3

Someone, please, please, please explain to me what the hell is going on here, and how I can fix this?

I'll let my console do the talking:

root@worker2:/var/run# service postgresql start
 * Starting PostgreSQL 9.3 database server                                                           * The PostgreSQL server failed to start. Please check the log output:
2016-01-15 10:47:08 PST FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
                                                                                             [fail]
root@worker2:/var/run# chmod 777 postgresql
root@worker2:/var/run# ls -l |grep post
drwxrwsrwx 2 postgres    postgres       40 Jan 15 10:24 postgresql
root@worker2:/var/run# chmod g-s postgresql
root@worker2:/var/run# ls -l |grep post
drwxrwxrwx 2 postgres    postgres       40 Jan 15 10:24 postgresql
root@worker2:/var/run# service postgresql start
 * Starting PostgreSQL 9.3 database server                                                           * The PostgreSQL server failed to start. Please check the log output:
2016-01-15 10:47:48 PST FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
                                                                                             [fail]
root@worker2:/var/run# ls -l |grep post
drwxrwsr-x 2 postgres    postgres       40 Jan 15 10:24 postgresql

3 Answers3

2

I had the exact same problem. I still don't know what caused it, but as a workaround I changed the postgresql pid file directory and unix socket directory (although perhaps the former wasn't necessary). I will call this new directory /pg_workaround in this answer.

mkdir /pg_workaround
chown postgres:postgres /pg_workaround
chmod 777 /pg_workaround

Then edit /etc/postgresql/<version>/main/postgresql.conf and modify the following lines:

external_pid_file = '/pg_workaround/<version>-main.pid'
unix_socket_directory = '/pg_workaround'

(Replace /pg_workaround with the desired location and <version> with your actual postgres version.)

Cinnam
  • 211
1

Check the owner of /var/run/postgresql and set it to postgres if not already so To do so, type


sudo chown -R postgres:postgres /var/run/postgresql**


If the user you are running as does not have sudo privilege, then

1) Change to root

su -

2) Change ownership of /var/run/postgresql to postgres user and postgres group

chown -R postgres:postgres /var/run/postgresql

I had the same problem when installing postgres on Ubuntu 14.04 and changing the ownership fixed the problem for me.

0

This is result of a bug usually on VPS when OS and shared Kernel differ. Workaround; create a cronjob that fix it on every reboot like following:

@reboot chown -R postgres:postgres /var/run/postgresql

For more detail relevant to this issue: SSH Server stops working after reboot, caused by missing /var/run/sshd

Simptive
  • 130