Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL 11 configurations doesn't allow pgAdmin4 to connect

I'm pretty new to PostgreSQL so the question may be simple. So. I have installed PostgreSQL 11 and pgAdmin 4 on Fedora 29. I can connect to the database via terminal or AzureDataStudio, but when I try to connect with pgAdmin, I get this error:

Unable to connect to 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 5432?

I'm trying anything that can be found for 3 last days, but nothing helped me. Here are my configurations:

# I set listen_address in postgresql.conf:
listen_addresses = '*'

# and these are my pg_hba.conf hosts:
local   all             all                     md5

host    all             all     127.0.0.1/32    md5
host    all             all     0.0.0.0/0       md5

host    all             all     ::1/128         md5
host    all             all     ::/0            md5

local   replication     all                     peer
host    replication     all     127.0.0.1/32    ident
host    replication     all     ::1/128         ident

Is there any problem with these configurations? Or is there any tip should I know to connect through pgAdmin? Thanks in advance.

UPDATE:

I should mention that I can connect to the database through the terminal:

psql -h 127.0.0.1 -U postgres

Connecting through AzureDataStudio doesn't need any specified data. There is a form just like this:

enter image description here

And filling the form and submitting the Connect button will connect to the database. Also, I can connect to the database via JetBrains' DataGrip with same form and data.

UPDATE 2:

I'm running both PostgreSQL and pgAdmin on my local machine which is running Fedora 30.

UPDATE 3:

Here are my full software's info:

// OS
Fedora 30 64-bit

// PostgreSQL
PostgreSQL 11.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10), 64-bit

// pgAdmin
Version    4.8
Copyright    Copyright (C) 2013 - 2019, The pgAdmin Development Team
Python Version    3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
Flask Version    1.0.2
Application Mode    Server

UPDATE 3:

Running sudo netstat -nlp | grep 5432 command gives this result;

tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      16954/postmaster    
tcp6       0      0 :::5432                 :::*                    LISTEN      16954/postmaster    
unix  2      [ ACC ]     STREAM     LISTENING     952579   16954/postmaster     /var/run/postgresql/.s.PGSQL.5432

UPDATE 4: The Solution!

Finally, with the help of Jan Garaj's answer, I found the solution. First of all, I installed the SELinux Troubleshooter app:

sudo dnf install setroubleshoot

Then I started the Troubleshooter. Next, I tried to connect to the database through pgAdmin4. The Troubleshooter gave me 2 errors with suggested solutions which were running these commands:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1
like image 338
amiry jd Avatar asked May 12 '19 19:05

amiry jd


People also ask

Why pgAdmin Cannot connect to server?

If pgAdmin displays this message, there are two possible reasons for this: the database server isn't running - simply start it. the server isn't configured to accept TCP/IP requests on the address shown.

How do I give permission to pgAdmin?

To launch the Grant Wizard tool, select a database object in the pgAdmin tree control, then navigate through Tools on the menu bar to click on the Grant Wizard option. Use the fields in the Object Selection window to select the object or objects on which you are modifying privileges.

Where is pgAdmin4 config file?

The config_local.py file should be created in the same directory as config.py which for pgAdmin 5.3 on Windows is C:\Program Files\pgAdmin 4\v5\web .


1 Answers

Check SELinux audit logs - https://fedoraproject.org/wiki/SELinux_FAQ#How_do_I_find_out_whether_SELinux_is_denying_access_for_any_software.3F

I see denials on my test CentOS 7 system:

type=AVC msg=audit(1560101981.565:1942): avc:  denied  { name_connect } for  pid=63140 comm="httpd" dest=5432 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:postgresql_port_t:s0 tclass=tcp_socket permissive=0
type=SYSCALL msg=audit(1560101981.565:1942): arch=c000003e syscall=42 success=no exit=-13 a0=15 a1=7f741c06dfe0 a2=10 a3=7f742f9147b8 items=0 ppid=63139 pid=63140 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

I guess, you will have similar problem in your Fedora - you will need to tweak used SELinux policy.

like image 190
Jan Garaj Avatar answered Oct 07 '22 17:10

Jan Garaj