Why psql can't connect to server?

I typed psqland I get the following:

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

I used sudo netstat -nlp | grep 5432to see the status, but showed nothing. And I searched the Internet, someone told me to change pg_hba.conf, but I can not locatethis file. And I also tried this command sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432. He can't work.

+34
source share
18 answers

The error indicates that the psql utility cannot find the socket to connect to the database server. Either you do not have a database service running in the background, or the socket is somewhere else, or you might need to install it pg_hba.conf.

Step 1. Verify that the database is running

. * ix : postgres

ps -ef | grep postgres

, mac osx,

501   408     1   0  2Jul15 ??         0:21.63 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log

, , .

, postgres, .

man postgres

, -D -r datadir logfilename.

2: postgres

find , - /tmp

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

postgres , . :

/tmp/.s.PGSQL.5432

psql, , .

psql -h /tmp/ dbname

3: ,

, , , , pg_hba.conf .

datadir, pg_hba.conf.

:

# "local" is for Unix domain socket connections only
local       all       all       trust

, postgres.

+29

postgres , .

1: pg_lsclusters postgres,

:

Ver Cluster Port Status Owner    Data directory               Log file
9.6 main    5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

, Postgres

2: pg_ctlcluster

#format is pg_ctlcluster <version> <cluster> <action>
sudo pg_ctlcluster 9.6 main start

#restart postgres
sudo service postgres restart

3: 2

, . ( /var/log/postgresql/postgresql-9.6-main.log)

FATAL: could not access private key file "/etc/ssl/private/ssl-cert-snakeoil.key": Permission denied
Try adding 'postgres' user to the group 'ssl-cert'

4: postgres

, postgres /var/lib/postgresql/version_no/main : sudo chown postgres -R/var/lib/postgresql/9.6/main/

5: , postgres ssl-cert

, Postgres "ssl-cert". , .

#set user to group back with
sudo gpasswd -a postgres ssl-cert

# Fixed ownership and mode
sudo chown root:ssl-cert  /etc/ssl/private/ssl-cert-snakeoil.key
sudo chmod 740 /etc/ssl/private/ssl-cert-snakeoil.key

# now postgresql starts! (and install command doesn't fail anymore)
sudo service postgres restart
+11

. PostgreSQL, , .

. PostgreSQL Ubuntu. sudo/etc/init.d/postgresql restart

+9

! , , . , sudo apt-get --purge remove postgresql\* dpkg -l | grep postgres. , .

+4

sudo su - postgres
initdb --locale en_US.UTF-8 -D /var/lib/postgres/data
exit
sudo systemctl start postgresql
sudo systemctl status postgresql

.

+2

, Postgres . :

sudo systemctl start postgresql

, :

sudo systemctl enable postgresql
+1

Devuan ascii ( , Debian ?). /etc/postgresql/9.6/main/postgresql.conf unix_socket_directories /var/run/postgresql. /tmp, , .

+1

: , unix_socket_directories /data/postgresql.conf , /tmp, , . /var/run/postgresql . dir postgresql /var/run subsys/postgresql-9.6 /var/lock, ( postgresql 9.6).

0

debian:

  • /etc/postgresql/10/main/postgresql.conf listen_address *
  • /etc/postgresql/10/main/pg_hba.conf host all all 0/0 md5
  • postgres=# CREATE ROLE remoteuser LOGIN WITH PASSWORD 'foo'
  • sudo /etc/init.d/postgresql restart

  • clientide psql --host=ipofserver --port=5432 --username=remoteuser --password --dbname=mydb

  • , foo

postgres psql

0

pem, . : /var/log/postgresql/postgresql -9.5-main.log, .

0

, , Node.js( Postgres Sequelize),

  • brew install postgresql ( postgres, , msg, )

  • brew services start postgresql **** ( Homebrew postgres)

  • createdb <name of database in config.json file>

  • node_modules/.bin/sequelize db:migrate

  • npm start

0

postgresql. "postgres". , RDBMS, . :

  • :

    root @kalilinux: ~ # sudo -i -u postgres

  • ype psql

    postgres @kalilinux: ~ $psql

  • ,

    \

  • postgres @kalilinux: ~ $createuser --interactive

psql. . psql .

0

, , . , , , .

, postgres . .

0

, , ,

Unix "/var/run/postgresql/.s.PGSQL.5432"?

, , , 100% ,

df -h
cd /var/log/odoo/
cat /dev/null > odoo-server.log
reboot
0

. , , .

, .

0

, pg_hba.conf. , . .

0

. , psql -h, '/tmp' . psql . , , , .

0

,

vi /etc/postgresql/11/main/pg_hba.conf
Hide result

  1. hba, etc.

host    all   all    localhost trust   md5
Hide result

  1. pg_hba.conf

  2. sudo.
0

All Articles