Dealing with “could not create shared memory segment” from postgres on Ubuntu

After installing postgresql-8.4 from the Ubuntu repos on an Ubuntu 9.10 machine, I received the following when the daemon tried to start up:

1
2
3
4
5
6
7
 * The PostgreSQL server failed to start. Please check the log output:
FATAL:  could not create shared memory segment: Invalid argument
DETAIL:  Failed system call was shmget(key=5433001, size=35233792, 03600).
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 35233792 bytes), reduce PostgreSQL's shared_buffers parameter (currently 4096) and/or its max_connections parameter (currently 13).
    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.
[fail]

Fail indeed. Here’s the fix:

1
2
3
4
sudo cp /etc/sysctl.conf /etc/sysctl.conf-orig &&
sudo sh -c 'echo "#\n# For postgres\nkernel.shmmax = 104857600" >> /etc/sysctl.conf' &&
sudo sysctl -p &&
sudo /etc/init.d/postgresql-8.4 start

This increases a particular kernel parameter to allow postgres enough memory to start. Yay for poor defaults…

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI and tagged , , , . Bookmark the permalink.

10 Responses to Dealing with “could not create shared memory segment” from postgres on Ubuntu

  1. Jesper says:

    Excellent, just what happened to me. Thanks for this!

  2. Pål de Vibe says:

    Thanks! Great fix and instructions.

  3. Dr H says:

    Thanks, mate, You really made my day!

  4. Gaston says:

    Thanks man! You saved me a lot of time and pain!

  5. Chaos says:

    Hey Samuel,

    I am on ubuntu lucid x64. Am facing the same issue and this soln don’t seem to work.

    Any other ideas?

    Thanks.

  6. Chaos says:

    Hi Samuel,
    Got it up & running again. Pls ignore my previous comment.
    Many Thanks..

  7. Tim Mattison says:

    This worked for me too. Thanks a lot!

  8. Mehul says:

    Thanks..Really its working for me

    Since last 1 monthi was trying to solve this error but it was not going from my PC but not its working..

    thanks once again thanks a lot..

  9. Sandeep Gholve says:

    Thank you Samuel.
    This worked for me.

  10. Gary Yao says:

    Thanks,
    Happened to me after upgrade to 12.04 LTS Polished Penguin.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>