I upgraded from Maverick to Natty recently and everything went fine except during the dist-upgrade something went wrong with PostgreSQL. I've since tried reinstalling, removing, and even purging it via 'sudo apt-get purge postgresql' but it still comes up with the same error no matter what I do. See below. It was working fine before the upgrade. Any help would be greatly appreciated. Thanks!

Setting up postgresql-common (114) ...
 * Starting PostgreSQL 8.4 database server         * The PostgreSQL server failed to start. Please check the log output:
2011-05-19 11:49:41 EDT LOG:  could not bind IPv4 socket: Address already in use
2011-05-19 11:49:41 EDT HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2011-05-19 11:49:41 EDT WARNING:  could not create listen socket for ""
2011-05-19 11:49:41 EDT FATAL:  could not create shared memory segment: Invalid argument
2011-05-19 11:49:41 EDT DETAIL:  Failed system call was shmget(key=5432001, size=37879808, 03600).
2011-05-19 11:49:41 EDT 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 37879808 bytes), reduce PostgreSQL's shared_buffers parameter (currently 4096) and/or its max_connections parameter (currently 103).
    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.

invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1
  • could you post the output of "netstat -na | grep 5432" May 22, 2011 at 3:15
  • Running that command outputs nothing. Any other ideas?
    – wired
    May 22, 2011 at 6:08
  • open /etc/init.d/postgresql and add a set -x to the line after #!/bin/bash and do a sudo /etc/init.d/postgresql restart and post the output May 22, 2011 at 6:21
  • I replaced set -e with set -x and here is what I got: pastebin link
    – wired
    May 22, 2011 at 6:41

2 Answers 2


You need to increase the maximum size of a chunk of shared memory Linux kernel allows to allocate at once (known as SHMMAX parameter)

You need to edit /etc/sysctl.conf and add the following line:

kernel.shmmax = 41943040

(where 41943040 is the size of memory in bytes, i.e. 40 megabytes. On production system you probably want to set this value way higher - Postgres documentation recommends to start with 1/4 of available memory)

Then run

sudo sysctl -p

and restart postgres again.

Alternatively, you can edit /etc/postgresql/<version>/main/postgresql.conf and reduce the value of shared_buffers parameter.

This is a bug, more info here


(there's also /etc/sysctl.d/30-postgresql-shm.conf file which is supposed to be used for this purpose but it doesn't seem to be included from the main config so editing it has no effect)

  • I did exactly as you stated above and even restarted the computer, but I still get the exact same error as I posted in the original question. At this point, I'm willing to just uninstall the whole thing and start from scratch, but for some reason apt-get trys to run the server when I uninstall and so I can't even do that. Thanks for all your help! I really appreciate it.
    – wired
    May 22, 2011 at 7:28
  • try bumping the shmmax further .. it is a shared memory issue. Look at the link I posted, it has more info and more work arounds May 22, 2011 at 7:31
  • 10
    The solution was to edit /etc/sysctl.conf and add the line kernel.shmmax = 41943040 then run sudo sysctl -p and restart postgreSQL: sudo /etc/init.d/postgresql start. Now it starts without error. Thank you so much!!
    – wired
    May 22, 2011 at 16:03
  • 1
    @freethinker, This does not work in 12.04.
    – Cerin
    May 14, 2012 at 3:18
  • 1
    @wired, Thanks, your fix works for me. It appears that /etc/sysctl.d/30-postgresql-shm.conf is completely ignored...
    – Cerin
    May 14, 2012 at 3:23

The old Postgres is still running most likely.

Good idea, like freethinker pointed out, to veryfy what's running on that port.

Once you know it's Postrgres then you would probably want to kill it:

# Find PID
ps axf | grep post

kill PID

Then you can start the new version:

/etc/init.d/postgresql start

I'm puzzled why the package manager was not able to stop the older version.

  • It's not showing up with 'ps axf | grep post' . I'm pretty sure it's not running.
    – wired
    May 22, 2011 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .