I want to make sure Postgresql can take advantage of all available memory for caching on a dedicated DB server. How do I make sure that the kernel's shared memory settings are correct? Does anyone know the calculation to make sure shmax etc. won't limit Postgresql?

1 Answer 1


Here's a little snippet that allows the server to use up to half of physical RAM for shared memory:

page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
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

Put the output of that into /etc/sysctl.conf and run:

sysctl -p

Then you're set.

PostgreSQL uses the operating system to supplement all of its read and writes, so you really don't want to dedicate half of RAM--this has plenty of margin in it for a dedicated database server. Tests varying the amount of dedicated RAM for the server normally find maximum throughput somewhere between 15% and 40% of total RAM; any more and you end up with too many double buffered pages. And the useful upper limit is around 8GB on large systems, period, due to as yet unresolved caching contention issues in the server code. More on server tuning at the PostgreSQL wiki.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.