Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem starting Postgresql on Gentoo.

$ /etc/init.d/postgresql-9.1 start
 * Socket conflict.
 * A server is already listening on:
 *     /var/run/postgresql/.s.PGSQL.5432
 * HINT: Change PGPORT to listen on a different socket.

I removed the file /var/run/postgresql/.s.PGSQL.5432 the service starts and runs fine. I guess the sever shut down and left the file there. I checked with netstat to see if there was a process listening on that port but it wasn't any.

My question is, how can I avoid this problem in the future?

share|improve this question
up vote 2 down vote accepted

The socket should be removed when postgres is shut down (cleanly). Most probably cause is, that your computer was uncleanly restarted (power outage, reset button,...), or postgres crashed, and didn't have time/chance to remove the socket file.

If you do a clean shutdown/restart, this shouldn't happen at all. If postgres crashes, you have a bigger problem then a stale socket. If hard-reboots happen often, you have a great chance of data loss/corruption.

You can delete sockets from one of the init scripts (depends on the distribution) at boot time, or edit the postgres init script to delete the socket before starting (dangerous if you unintentionally run it when one postgresd is already running and you delete it's socket).

share|improve this answer
I guess it was a power outage, thanks for your answer. – F.C. May 2 '12 at 14:59

If it is not a software bug, you just need to make sure you stop postgresql server gracefully when needed. This is also critical to avoid data loss.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.