Skip to content

Instantly share code, notes, and snippets.

@pi-aej
Created November 12, 2015 23:48
Show Gist options
  • Save pi-aej/f34dedac9bd45ce5673a to your computer and use it in GitHub Desktop.
Save pi-aej/f34dedac9bd45ce5673a to your computer and use it in GitHub Desktop.
Auto set postgresql shared_buffers to fraction of available memory
#!/bin/bash
## Adjust shared_buffer size for system (25% of available)
SYS_MEM=`cat /proc/meminfo | grep MemTotal | sed "s/[^0-9]//g"`
PG_MEM=`echo $(( $SYS_MEM / 4 ))`
RE="s/##PG_MEM##/$PG_MEM/g"
## Substitute shared_buffers in your config with ##PG_MEM##
## e.g: shared_buffers = ##PG_MEM##kB
sed -i $RE postgresql.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment