10

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
amiry jd
  • 27,021
  • 30
  • 116
  • 215
  • So what do the postgresql logs show server-side? You have turned on connection logging and checked them, haven't you? – Richard Huxton May 12 '19 at 19:14
  • @RichardHuxton Yes I did. Nothing logged during to attempt connecting via pgAdmin. – amiry jd May 12 '19 at 20:02
  • How exactly are you connecting with AzureDataStudio, terminal (I assume it's psql) and pgAdmin 4? What are your connection settings? Please don't post passwords though. – A. Scherbaum May 13 '19 at 03:40
  • If you are logging connection attempts and saw nothing logged then nothing reached the server. Check your IP addresses, routing, firewalls etc. You are running pgadmin on the same machine as the postgresql server aren't you? – Richard Huxton May 13 '19 at 06:42
  • @A.Scherbaum it has a form that I fill connection properties. Don't know what is going on the background. Also, I'm able to db via DataGrid (a JetBrains product) now. And connecting through console does work too. Seems only pgadmin cannot connect ): – amiry jd May 15 '19 at 08:06
  • @RichardHuxton Yes they are on the same machine. – amiry jd May 15 '19 at 08:07
  • Try to relax hba_conf first to accept all. If you can connect, it may be due to pgadmin is basically a web-application and running at a certain IP. Try to include your firewall assigned dynamic IP (192.168. ??? ) – Edward Aung Jun 07 '19 at 01:50
  • Have you tried to connect to the actual IP address of the server ? What OS is the pstogres running on ? – thecarpy Jun 07 '19 at 13:52
  • @EdwardAung How should I relax hba_conf? Is something wrong in mine? – amiry jd Jun 08 '19 at 05:50
  • @thecarpy I'm running both PostgreSQL and pgAdmin on my local machine which is running fedora 30. – amiry jd Jun 08 '19 at 05:51
  • How did you install pgAdmin? Is it running in the container? Is selinux enabled? – Jan Garaj Jun 08 '19 at 14:50
  • @JanGaraj I installed pgAdmin4 by this tutorial: https://computingforgeeks.com/how-to-install-pgadmin-on-centos-fedora/. No, it's not running in the container. I already did set the correct context for SELinux. – amiry jd Jun 09 '19 at 12:38

3 Answers3

3

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.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
0

on centos 7

# setsebool -P httpd_can_network_connect_db 1

there you go

-1

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

Wasiq Muhammad
  • 3,080
  • 3
  • 16
  • 29
  • 1
    Thanks a lot. But I already did all of these steps while I was installing pgadmin. I updated the question and add more info, would you take a look, please? – amiry jd Jun 08 '19 at 09:57
  • @javadamiry are u using web interface ? can you share me the screenshot of the interface might be the problem in your configuration setting. if it access through terminal it means it opens to connect from anywhere on your local machine – Wasiq Muhammad Jun 08 '19 at 10:12
  • Yes, I'm using web-interface. And it's in server mode. – amiry jd Jun 08 '19 at 11:33
  • @javadamiry have your webserver service is running ? – Wasiq Muhammad Jun 08 '19 at 16:50
  • Yes, I can load an login to pgAdmin. The problem is connecting to PostgreSQL. – amiry jd Jun 08 '19 at 21:37