47

I am attempting to install and run a postgreSQL server, whenever I install it using

sudo apt-get install postgresql

I get the following error:

* Starting PostgreSQL 9.1 database server                                       
* The PostgreSQL server failed to start. Please check the log output:
2014-04-03 17:18:16 PDT FATAL:  could not create lock file     "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
                                                                    [fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-common (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of postgresql-9.1:
postgresql-9.1 depends on postgresql-common (>= 115~); however:
Package postgresql-common is not configured yet.

dpkg: error processing postgresql-9.1 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of postgresql:
 postgresql depends on postgresql-9.1; however:
  Package postgresql-9.1 is not configured yet.

dpkg: error processing postgresql (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a          previous failure.
Errors were encountered while
 processing:
 postgresql-common
 postgresql-9.1
 postgresql
E: Sub-process /usr/bin/dpkg returned an error code (1)

I am guessing it's a permissions issue; how do I go about solving it? I am running Ubuntu 13.10

Community
  • 1
  • 1
dawsondiaz
  • 674
  • 1
  • 7
  • 13
  • Here u have the solution. I think that it should help u. http://askubuntu.com/questions/371722/uninstall-postgresql-from-ubuntu – Jan Krajewski Apr 22 '14 at 21:55

4 Answers4

87

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.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Jessica Chiang
  • 1,026
  • 6
  • 6
  • I tried, however this is what was returned; [screenshot](http://i.imgur.com/mRU3Xq2.png) – dawsondiaz May 22 '14 at 03:14
  • 1
    Hi dawsondiaz, thanks for the screenshot. You have to change to root first. You missed the "sudo" before the chown command. If the dawson user does not have sudo priviledge, then 1) Change to root by "su -" and 2) "chown -R postgres:postgres /var/run/postgresql" – Jessica Chiang May 24 '14 at 16:10
  • 1
    This worked for me too, but I already had Postgres 9.3 installed. Synaptic Package Manager wanted to issue an update and after that update ran, Postgres failed to restart for the same reason detailed in your question. Manually fixing the permission issue allowed me to restart my local postgres server again. – danielricecodes Feb 18 '15 at 14:11
  • This is also the solution on Linux Mint. – Frederik Krautwald May 01 '15 at 10:19
  • 2
    on fedora changing owner to `postgres:postgres` didn't work for me, but changing it to my current user worked `sudo chown -R $USER:$USER /var/run/postgresql` – Asalle Aug 08 '20 at 08:00
23

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.

Matt
  • 4,815
  • 5
  • 39
  • 40
  • I run postgresql as a different user than postgres and it didn't allow me to create a lock file at `/var/run/postgresql`. IMHO allowing global read/writes is bad and I just added my user to the `postgres` group. – Mukesh Sai Kumar Sep 02 '19 at 09:11
2

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
new_sys_admin
  • 315
  • 2
  • 5
  • 15
0

I spent a lot of time looking for a solution.

I added my user to the postgres group, but that didn't help In the end I was forced to choose not the safest way.

  chmod -R 777 /var/run/postgresql/

Source

My error

FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied