PostgreSQL server failed to start, could not create lock file: permission denied

Change the owner of /var/run/postgresql and set it to postgres:

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 user postgres and group postgres:

    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.


The lock file ends up in /var/run. To fix the permissions of this dir, I needed to run sudo chmod a+w /var/run/postgresql.


Could you check the file permissions of /var/run?

ls -l /var/run

If 'write' permission is missing, try

sudo chmod o+w /var/run