Skip to content

Instantly share code, notes, and snippets.

@kljensen
Created February 6, 2013 14:12
Show Gist options
  • Save kljensen/4722736 to your computer and use it in GitHub Desktop.
Save kljensen/4722736 to your computer and use it in GitHub Desktop.
Set shared memory for postgres on a linux box to a constant fraction of ram
# If you want maximum shared memory of 1/5 of your RAM,
# leave FRACTION as 5
FRACTION=5
RAM=`cat /proc/meminfo|grep ^MemTotal|awk '{printf("%.f", $2*1024)}'`
SHMMAX=`echo "$RAM / $FRACTION" |bc`
PAGESIZE=`getconf PAGESIZE`
SHMALL=`echo "$SHMMAX / $PAGESIZE" |bc`
sudo sysctl -w kernel.shmmax=$SHMMAX
sudo sysctl -w kernel.shmall=$SHMALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment