Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.