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
Ernie Dunbar
  • 31
  • 1
  • 1
  • 2
  • Notice that the permissions on the folder /var/run/postgresql change from 777 to 775 with a sticky bit on group when I try to start the daemon. The daemon actually changes these permissions to break operation. If I could change it to 777 permanently, at the very least I could find out what user postgresql was actually running as, and fix that, but no, the daemon changes its permissions to break operation instead. – Ernie Dunbar Jan 19 '16 at 16:57

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
  • 201
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.

  • Read my output carefully please. That's exactly what I did. What appears to be happening, is that Postgresql actually changes this file's permissions to not work with whatever user the Postgresql server is actually running with. (ie, not postgres, or the permissions above would actually work - yes, I've tested writing files as the postgres user in /var/run/postgresql) – Ernie Dunbar Jan 15 '16 at 21:00
  • I can see that you used chmod not chown! – Saleh Salem Jan 16 '16 at 21:21
  • root@worker2:/var/run# chown -R postgres:postgres /var/run/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-19 08:50:36 PST FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

    – Ernie Dunbar Jan 19 '16 at 16:51
  • It was already chowned to postgresql:postgresql, and doing it again hasn't changed anything. There's nothing in this directory. the file /var/run/postgresql/.s.PGSQL.5432.lock cannot exist, and even if it did and the ownership was correct, it still appears that PostgreSQL actually runs as another user, because it can't write to this directory. – Ernie Dunbar Jan 19 '16 at 16:53
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
  • 121