Skip to content

Instantly share code, notes, and snippets.

@jodell
Created October 13, 2011 18:54
Show Gist options
  • Save jodell/1285137 to your computer and use it in GitHub Desktop.
Save jodell/1285137 to your computer and use it in GitHub Desktop.
kernel shared memory calculator
#!/bin/bash
# http://archives.postgresql.org/pgsql-admin/2010-05/msg00285.php
# Output lines suitable for sysctl configuration based
# on total amount of RAM on the system. The output
# will allow up to 50% of physical memory to be allocated
# into shared memory.
# On Linux, you can use it as follows (as root):
#
# ./shmsetup >> /etc/sysctl.conf
# sysctl -p
# Early FreeBSD versions do not support the sysconf interface
# used here. The exact version where this works hasn't
# been confirmed yet.
page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
if [ -z "$page_size" ]; then
echo Error: cannot determine page size
exit 1
fi
if [ -z "$phys_pages" ]; then
echo Error: cannot determine number of memory pages
exit 2
fi
shmall=`expr $phys_pages / 2`
shmmax=`expr $shmall \* $page_size`
echo \# Maximum shared segment size in bytes
echo kernel.shmmax = $shmmax
echo \# Maximum number of shared memory segments in pages
echo kernel.shmall = $shmall
@gingerlime
Copy link

Thanks for sharing this! really useful to automate deployment of postgresql and automatically detect and adjust shared memory kernel settings.

@NanXiao
Copy link

NanXiao commented Jan 15, 2016

A useful script!

@Marckchile
Copy link

Thanks!

@kopax
Copy link

kopax commented Jun 13, 2016

Thanks for sharing, can this be used inside a docker container running PostgreSQL?

@evaristorivi
Copy link

Muchas gracias!

@mbwmbw1337
Copy link

Great script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment