Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to PostgreSQL server: could not connect to server: Permission denied

Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "10.0.1.201" and accepting TCP/IP connections on port 5432?

This is the error i am getting when trying to connect to remote database from linux based server

Though i am able to connect to it from localhost

Can anyone help me in this

like image 963
Manish Avatar asked Nov 15 '11 17:11

Manish


2 Answers

One possible scenario/solution that worked for me (for the very same problem) is here:

service httpd stop
service postgresql stop

setsebool -P httpd_can_network_connect 1

service httpd start
service postgresql start

Here we're basically allowing HTTPD to connect to PostgreSQL over network by setting SELinux bool equals to 1 (true).

like image 105
Amit Verma Avatar answered Oct 08 '22 01:10

Amit Verma


Check the listen_addresses setting in postgresql.conf. If it is set to localhost, then only loopback connections will be accepted, and remote connections will get a "connection refused" error. Set listen_addresses to "*" to enable listening on all interfaces.

like image 21
araqnid Avatar answered Oct 08 '22 02:10

araqnid