amiry jd
amiry jd

Reputation: 27585

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

Upvotes: 10

Views: 4518

Answers (3)

Fakieh Maulana
Fakieh Maulana

Reputation: 1

on centos 7

# setsebool -P httpd_can_network_connect_db 1

there you go

Upvotes: 0

Jan Garaj
Jan Garaj

Reputation: 28696

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.

Upvotes: 3

Wasiq Muhammad
Wasiq Muhammad

Reputation: 3118

Assuming as per should mention that you can connect to the database through the terminal: Try to run pgAdmin4 by using root administrator account.

For further verification of your installation and configuration

Copy the pgAdmin 4 sample configuration.

cp /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.conf

mkdir /var/log/pgadmin4/
mkdir /var/lib/pgadmin4/

Create/Edit config_local.py file.

vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_local.py

Add the following settings.

LOG_FILE = '/var/log/pgadmin4/pgadmin4.log'
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage'

Change permissions of directories so that Apache can write data into it.

chown -R apache:apache /var/lib/pgadmin4/*
chown -R apache:apache /var/log/pgadmin4/*

Run the following command to create a user account for the pgAdmin 4 web interface.

python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.py

pgAdmin4 comes with server and desktop deployment, In here we are assuming desktop If still you are facing problem share you logs

Upvotes: -1

Related Questions