Thread: Relation between RAM / shmmax / shmall / shared_buffers
Hi,
I am having a transactional database heavy on parallel reads and updates. Apart from hardware optimization, I want to ensure that my system parameters are optimized as well. Following is what I am doing on my test system having 4GB RAM. Please let me know if the logic sounds ok (at least at high-level) and if there are other related parameters I should tweak as well:
RAM = 4GB
1. Keeping the kernel parameter kernel.shmmax at 75% of RAM (i.e. at 3GB )kernel.shmmax = 3221225472
2. Keeping the kernel parameter shmall at the same value. Because shmall is measured in number of pages and each page on my linux is 4096 bytes, having kernel.shmall = 786432 (786432 * 4096 = 3221225472, same as shmmax)
3. Keeping the shared_buffer parameter in the postgresql.conf file to be 25% of the kernel.shmmax. i.e. shared_buffers = 768MB (25% of 3072 MB)
Thanks,
-Bala
The New Busy is not the old busy. Search, chat and e-mail from your inbox. Get started.
Balkrishna Sharma <b_ki@hotmail.com> wrote: > [Are there] other related parameters I should tweak as well[?] There are several which should probably be adjusted. See: http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server -Kevin
Balkrishna Sharma wrote: > 1. Keeping the kernel parameter kernel.shmmax at 75% of RAM (i.e. at > 3GB )kernel.shmmax = 3221225472 > 2. Keeping the kernel parameter shmall at the same value. Because > shmall is measured in number of pages and each page on my linux is > 4096 bytes, having kernel.shmall = 786432 (786432 * 4096 = > 3221225472, same as shmmax) There's little reason to put shmmax at over 50% of RAM, because shared_buffers is going to be significantly lower than that even. I use the attached script for this job now; I got sick of doing the math manually all the time. If you're on a system that supports returning memory info using getconf, it outputs the lines you need to put into the kernel configuration. -- Greg Smith 2ndQuadrant US Baltimore, MD PostgreSQL Training, Services and Support greg@2ndQuadrant.com www.2ndQuadrant.us #!/bin/bash # 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