Tuning Postgresql on a 16GB Linode VPS

Dave Rapin asked:

I’m running a dedicated PostgreSQL on a 16GB Linode (Ubuntu 12.04 32bit). I’ve tried using pgtune, but I’ll run into shared memory errors. I.e.

The PostgreSQL server failed to start. Please check the log output:
2014-02-10 08:32:39 EST FATAL:  could not create shared memory segment: Invalid argument
2014-02-10 08:32:39 EST DETAIL:  Failed system call was shmget(key=5432001, size=4107419648, 03600).
2014-02-10 08:32:39 EST HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMMAX.  To reduce the request size (currently 4107419648 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
    If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter, in which case raising the request size or reconfiguring SHMMIN is called for.
    The PostgreSQL documentation contains more information about shared memory configuration

So I went ahead and started tweaking the SHMAX, but I’m really not sure what I should be setting this to. I was hoping pgtune would let me know or that I could find some documentation @ linode about this. I assume this value is in bytes? I’ve read it should be anything from 1/4 to 1/2 of the total memory (so 4 or 8 GB), but also that it shouldn’t exceed 4GB when you’re on 32bit.

Any advice? What would you recommending setting SHMAX to and why? Should I give up on pgtune, or pass a max memory param to it?


VPS Memory Details:

             total       used       free     shared    buffers     cached
Mem:      16617352     334320   16283032          0      18132     208400
-/+ buffers/cache:     107788   16509564
Swap:       524284          0     524284

— Update —

Migrating to 64bit did basically make everything work. The SHMAX was being accepted (it’s in bytes by the way). Figuring out what to set it to I just went with half of my available RAM on the box (“free -b” on Ubuntu to see memory in bytes).

I basically went with pgtune recommendations for the rest with a couple minor tweaks.

apt-get install pgtune

My answer:

You installed a 32-bit operating system on a machine with 16GB of RAM. This isn’t going to work. Even if a 32-bit OS can technically use more than 4GB of RAM, no single process on the operating system can exceed that boundary. Start over and install a 64-bit operating system, and this problem will go away (along with all the other problems you’re going to have).

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.