Sunday, February 13, 2011

Set Unix Shared Memory Parameters' (shm) value for Postgresql in CentOS

I had to setup Postgresql 9.0.1 in a virtual machine running with CentOS5 with 2 GB RAM.

Two important Unix Shared Memory papramters are SHMMAX and SHMALL.

SHMMAX is the maximum size (in bytes) for a single shared memory segment
SHMALL is the total amount of shared memory (in pages) that all processes on the server can use.

I followed the following steps to calculate the above parameters for my Postgresql DB server:

page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
let shmall=$phys_pages/2
echo $shmall
let shmmax=$shmall*$page_size
echo $shmmax

_PHYS_PAGES : Total number of RAM pages used by processes in this container.

PAGE_SIZE: A page is a fixed length block of main memory, that is contiguous in both physical memory addressing and virtual memory addressing.

I got the following values for my DB server which was running with 2 GB RAM:


That is maximum size for a single shared memory segment is 1 GB which is shmmax and all processes on the server can use upto 1 GB (shmall*page_size) of shared memory.

Now, I modified the value for the above two parameters using sysctl interface -

$ sysctl -w kernel.shmmax=1073831936
$ sysctl -w kernel.shmall=262166

Check that the values are set;

$ cat /proc/sys/kernel/shmmax
$ cat /proc/sys/kernel/shmall

In addition, I also preserved these values between reboots in the file /etc/sysctl.conf.

Leave a Reply