1

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?

2 Answers 2

2

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).

1
  • I guess it was a power outage, thanks for your answer.
    – F.C.
    May 2, 2012 at 14:59
0

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.

You must log in to answer this question.

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