Why won't PostgreSQL 9.3 start on Ubuntu?

My locale settings were not properly configured when PostgreSQL was installed. Purging and reinstalling didn't help. I followed the instructions here and that did the trick for me.

Essential parts of the linked information reproduced below:

The problem showed itself in the following manner:

warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
...
are supported and installed on your system.

The first one was very easy to solve by executing:

#dpkg-reconfigure locales

...and choosing the preferred locales.

But after that PostgreSQL still refused to start. This is due to the fact that the installation process tried to create a cluster at installation time but because of the bad locales this wasn't done. So we have to redo this step by executing:

#pg_createcluster 9.3 main --start

(For the 9.3 version of PostgreSQL)

After that step PostgreSQL starts flawlessly via

#/etc/init.d/postgresql start

Hopefully you've already solved this issue, but I'm running into a similar problem that seems to have a different source, and maybe my experience will help if you're still having a problem.

My problem with 9.3 on Ubuntu relates to the socket dir being a transient dir in /run. Basically, the init.d script is supposed to take care of creating the socket dir in /run/postgresql if it doesn't exist during the start action. This is always going to be the state of things after a reboot.

The problem is, however, that the init.d script will exit before executing the start action if the socket dir doesn't exist. This is because the call to pg_lsclusters will fail w/o the socket dir, which in turn prevents the start action from ever creating the socket dir.

I haven't figured out what the best solution is, but if I relocate the logic for creating the socket dir from the start action to before the call to pg_lsclusters, I am able to start the server after reboot without a problem.

Here is the portion of the start action that handles creating the socket dir:

# create socket directory
if [ -d /var/run/postgresql ]; then
  chmod 2775 /var/run/postgresql
else
  install -d -m 2775 -o postgres -g postgres /var/run/postgresql
  [ -x /sbin/restorecon ] && restorecon -R /var/run/postgresql || true
fi

I'll post an update if the root cause of this becomes clear to me, because this clearly can't be the expected behavior.

ADDENDUM:

I think the reason I was running into this problem is because I didn't have a good value configured for unix_socket_directories. On 9.2 this configuration option used to be unix_socket_directory, which I removed rather than switching to unix_socket_directories. Since I set a value for unix_socket_directories, I haven't had any issues with the server starting.


I've had several problems with the sockets file, in your case /var/run/postgresql/.s.PGSQL.5432

make sure /var/run/postgresql directory exists and is writable before starting postgresql for more info see this discussion.

also, when connecting use -h flag:

psql -h localhost 

and see if that resolves it.