Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 903
dawsondiaz Avatar asked Apr 04 '14 00:04

dawsondiaz


3 Answers

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.

like image 50
Jessica Chiang Avatar answered Oct 15 '22 01:10

Jessica Chiang


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.

like image 27
Matt Avatar answered Oct 15 '22 00:10

Matt


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
like image 2
new_sys_admin Avatar answered Oct 14 '22 23:10

new_sys_admin