0

After migration to a new VPS and trying website on new server(Centos 7), Selinux somehow prevents http from accessing Postgresql:

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

and yes my postgresql in on port 6432 because of pgbouncer that we use to reduce server load. I googled around and find out it's because of Selinux so I used selinux commands to allow httpd connection to db setsebool -P httpd_can_network_connect_db on and it works as in when I look in Selinux config with sestatus -b it's turned ON but the problem still exists...

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

Funny thing is I know it's because of Selinux cause when I use setenforce 0 It works and connect to postgresql without any problem. what should I do?

4
  • I believe You could do: semanage port -a -t postgressql_port_t -p tcp 6432 Jun 25, 2016 at 17:58
  • ValueError: Type postgressql_port_t is invalid, must be a port type
    – Ehphan
    Jun 25, 2016 at 18:00
  • try unreserved_port_t, sorry last time I touched selinux was loong time ago. Jun 25, 2016 at 18:03
  • no, I think problem is with postgressql_port_t typo it should be postgresql_port_t and I tested it. It works. Thanks
    – Ehphan
    Jun 25, 2016 at 18:06

1 Answer 1

1

I found the solution with help of a Bogdan Kuštan. It because Selinux accepts 5432 as Postgresql port and does not work with other ports. You can check acceptable ports to Selinux labeld port with semanage port -l command. You can add ports to labeled ports with "semanage port -a" command with some other parameters and in my case:

semanage port -a -t postgresql_port_t -p tcp 6432

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.