Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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