Andrew Louis
Andrew Louis

Reputation: 390

Permission denied in postgres

I missed a bit with chmod and permissions. And now got a lot of problems with access to folders.

If I start server I see in browser:

could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

command

service --status-all

tells that postgres works

[ + ] postgresq works

Next I changed next files

sudo nano /etc/postgresql/9.5/main/postgresql.conf
#listen_addresses = 'localhost'

to

listen_addresses = 'localhost, server_ip, *'
sudo nano /etc/postgresql/9.5/main/pg_hba.conf

add

host    all         all         server_ip/24    trust

then command

psql -U postgres -h server_ip

and error

psql: could not connect to server: Connection refused
Is the server running on host "95.213.200.26" and accepting TCP/IP connections on port 5432?

The following chain of actions leads to a slightly different error

command

which psql

answer

/usr/bin/psql

sudo su - postgres

No directory, logging in with HOME=/

psql

psql: could not connect to server: Permission denied
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Which file permissions do I have to change here?

Upvotes: 1

Views: 6174

Answers (3)

Andrew Louis
Andrew Louis

Reputation: 390

This question is really hard. I made a great mistake with permissions 777 for / folder and whole system broke. So it is really easier delete server and start new project.

Upvotes: 0

anneb
anneb

Reputation: 5768

Check listen addres syntax. Use:

listen_addresses = '*'

For the server to listen on both localhost and the server ip.

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 246798

Check that unix_socket_directories on the server is set to the same directory (/var/run/postgresql) as the default socket directory that was configured when the client was compiled (this requires a server restart).

Alternatively, you can use the --host option of psql or set the PGHOST environment variable to tell the client to look for the socket file in /tmp, where the server creates it.

It looks like client and server are from different installations, otherwise the configured default should be the same for both. Or you have a bad PGHOST environment variable set by accident.

Upvotes: 0

Related Questions