简体   繁体   中英

PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory

Most of what I've seen revolve around sudo service postgresql restart

Tried that and no avail. Other answers I've seen are removing a file from /usr/local/var/psql

Issue with that is I do not have a /var/ folder in /local/

Full dump:

[17:51:55]  shell-ratings-backend (master)
// ♥  sudo service postgresql restart
 * Restarting PostgreSQL 14 database server                 [ OK ] 
[17:52:29]  shell-ratings-backend (master)
// ♥  rails db:migrate
rails aborted!
ActiveRecord::ConnectionNotEstablished: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/rails:5:in `<top (required)>'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:10:in `require'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:10:in `block in <top (required)>'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:7:in `tap'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:7:in `<top (required)>'

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/rails:5:in `<top (required)>'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:10:in `require'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:10:in `block in <top (required)>'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:7:in `tap'
/mnt/c/Users/Alex/dev/shell-ratings-backend/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

The error states that the psql utility can't find the socket to connect to your database server. Either you don't have the database service running in the background, or the socket is located elsewhere, or perhaps the pg_hba.conf needs to be fixed.

Step 1: Verify that the database is running The command may vary depending on your operating system. But on most *ix systems the following would work, it will search for postgres among all running processes

ps -ef | grep postgres

You can look at all the options available to start the postgres server using the following.

man postgres From there, you'd see that the options -D and -r are respectively the datadir & the logfilename.

Step 2: If the postgres service is running Use find to search for the location of the socket, which should be somewhere in the /tmp

sudo find /tmp/ -name .s.PGSQL.5432

If postgres is running and accepting socket connections, the above should tell you the location of the socket. On my machine, it turned out to be:

/tmp/.s.PGSQL.5432 Then, try connecting via psql using this file's location explicitly, eg.

psql -h /tmp/ dbname

Step 3: If the service is running but you don't see a socket If you can't find the socket, but see that the service is running, Verify that the pg_hba.conf file allows local sockets.

Browse to the datadir and you should find the pg_hba.conf file.

By default, near the bottom of the file you should see the following lines:

"local" is for Unix domain socket connections only

local       all       all       trust

If you don't see it, you can modify the file, and restart the postgres service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM