Psql could not connect to server: No such file or

2020-01-29 03:12发布

I'm trying to run psql on my Vagrant machine, but I get this error:

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"?

Note: Vagrant 1.9.2 Box: ubuntu/trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64

EDIT Commands I've used in order to install and run postgres:

  • sudo apt-get update
  • sudo apt-get install postgresql
  • sudo su postgres
  • psql -d postgres -U postgres

16条回答
Lonely孤独者°
2楼-- · 2020-01-29 03:51

Does the /etc/postgresql/9.6/main/postgresql.conf show that port being assigned? On my default Xubuntu Linux install, mine showed port = 5433 for some reason as best as I can remember, but I did comment out the line in that same file that said listen_addresses = 'localhost' and uncommented the line listen_addresses = '*'. So maybe start and check there. Hope that helps.

查看更多
淡お忘
3楼-- · 2020-01-29 03:51

Within zsh:

rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

This is the only thing that worked for me after countless hours trouble shooting.

查看更多
smile是对你的礼貌
4楼-- · 2020-01-29 03:51

I was able to solve the issue by running:

sudo systemctl start postgresql@9.5-main
查看更多
家丑人穷心不美
5楼-- · 2020-01-29 03:56

I had similar problems just a while ago. After trying more than 5 suggestions I decided to go back to the basics and start from the beginning. Which meant removing my postgresql installation and following this guide upon re-installing postgresql. https://help.ubuntu.com/lts/serverguide/postgresql.html

查看更多
狗以群分
6楼-- · 2020-01-29 03:56

This error happened to me after my mac mini got un-plugged (so forced shutdown), and all I had to do to fix it was restart

查看更多
forever°为你锁心
7楼-- · 2020-01-29 04:00

I had the same issue but non of the answers here helped.

How I fixed it (mac)

  • Try to start postgresql with pg_ctl -D /usr/local/var/postgres start
  • Look for the Error Message that says something like FATAL: could not open directory "pg_tblspc": No such file or directory.
  • Create that missing directory mkdir /usr/local/var/postgres/pg_tblspc
  • Repeat from step one until you created all missing directories
  • When done and then trying to start postgresql again it might say FATAL: lock file "postmaster.pid" already exists
  • Delete postmaster.pid: rm /usr/local/var/postgres/postmaster.pid
  • Start postgres with: pg_ctl -D /usr/local/var/postgres start
  • Done ✨
查看更多
登录 后发表回答