9

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

Manish
  • 131
  • 1
  • 1
  • 5
  • permission denied means that the account you're trying to log into isn't allowed in via TCP. – Marc B Nov 15 '11 at 17:58
  • Basically i have an web application installed on server which requires database connection to postgre which is installed on remote server,But i am getting this error, though i am able to connect on windows, can you please tell me what's the reason – Manish Nov 15 '11 at 18:01
  • 1
    Even though the username may be the same, username@localhost is a completely different account than username@linuxbox. – Marc B Nov 15 '11 at 18:03
  • can you please tell me what can i do in such a situation? – Manish Nov 15 '11 at 18:11
  • Can i solve this problem by creating a new account on postgre to listen my request on database server? – Manish Nov 15 '11 at 18:13
  • In postgresql, user accounts are normalised, so "username" is "username", regardless of if you're connecting from localhost or elsewhere. Although access for "username" may be restricted to certain source addresses or authentication methods, there is only one account. – araqnid Nov 15 '11 at 20:06

3 Answers3

38

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).

Amit Verma
  • 8,660
  • 8
  • 35
  • 40
2

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.

araqnid
  • 127,052
  • 24
  • 157
  • 134
1

In PostgreSQL you have to configure client authentication in pg_hba.conf on the remote server.

Read more about pg_hba.conf @ http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html , otherwise you'll never connect to that server :).

Hope it will help, Stefan

igniter
  • 151
  • 3