Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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:

#!/bin/bash
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

 
discard

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.