Postgresql

如何從 pgadmin 允許 PostgreSQL

  • August 17, 2019

我不知道我是不是被詛咒了,但我無法將 postgre 伺服器添加到 pgadmin。我正在關注 Computingforgeeks 的指南,但它總是在 pgadmin 中創建新伺服器時顯示以下消息

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?

在服務狀態上,它顯示:

LOG:  listening on IPv4 address "0.0.0.0", port 5432
LOG:  listening on IPv6 address "::", port 5432
LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "log".

下面是配置:

--postgresql.conf:
listen_addresses = '*'
port = 5432

--pg_hba.conf:
# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             0.0.0.0/0               trust
# IPv6 local connections:
host    all             all             ::/0                    trust
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            ident
host    replication     all             ::1/128                 ident

網路統計:

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN    
tcp6       0      0 :::5432                 :::*                    LISTEN

我試過四處搜尋,但大多數解決方案都圍繞配置文件,我相信我已經按照指南和解決方案正確設置了它們。請幫忙…

答案在該教程網頁的評論中。不幸的是,本教程省略了一個至關重要的步驟。

SELinux 預設阻止 Web 伺服器(Apache、nginx 等)建立出站網路連接。您需要對其進行配置以允許 Web 伺服器與數據庫建立連接。

您可以使用適當的 SELinux 布爾值來做到這一點。

setsebool -P httpd_can_network_connect_db 1

引用自:https://serverfault.com/questions/979651