问题
I have a local installation of postgresql. It does not start, as I get:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Starting it manually does not work:
sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.4 database server
* The PostgreSQL server failed to start. Please check the log output:
2015-03-09 17:41:39 CET [3769-1] FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied
Ok, something wrong with the permissions. Lets look at them:
ls -all /var/run/
drwxr-xr-x 27 root root 900 Mar 9 17:36 .
drwxr-xr-x 25 root root 4096 Feb 28 06:19 ..
drwxrwsr-x 3 postgres-xc postgres-xc 60 Mar 9 17:35 postgresql
I found the following: doing sudo chmod 777 /var/run/postgresql solves the problem and a can start postgresql afterwards. Unfortunatly this has to be done after every reboot of Ubuntu. SO two questions:
1.Whats wrong? Why is the chmod not permanently?
2. How to fix it?
Thanks!
回答1:
Ok, I found a solution. A remove, purge and reinstall of postgresql did not solve the problem. I think some artefacts of earlier versions still remained (as I, for instance, still found 9.1,9.3 and 9.4 as subdirectories in /etc/postgresql/). Here is the full set of commands that I did to set up a clean installation:
sudo apt-get remove postgresql
sudo apt-get purge postgresql
apt-get --purge remove postgresql\*
sudo apt-get --purge remove postgresql\*
sudo rm -r /etc/postgresql/
sudo rm -r /etc/postgresql-common/
sudo rm -r /var/lib/postgresql/
sudo rm -r /var/run/postgres
userdel -r postgres
sudo userdel -r postgres
sudo apt-get install postgresql
after this, the problem was no longer present.
来源:https://stackoverflow.com/questions/28947498/ubuntu-psql-could-not-connect-to-server