如何从 pgadmin 允许 PostgreSQL

如何从 pgadmin 允许 PostgreSQL

我不知道我是不是被诅咒了,但我无法将 postgre 服务器添加到 pgadmin。我正在按照以下指南操作计算极客,但在 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

我尝试搜索,但大多数解决方案都与配置文件有关,我相信我已经按照指南和解决方案正确设置了它们。请帮忙...

答案1

答案就在该教程网页的评论中。不幸的是,该教程省略了一个至关重要的步骤。

SELinux 默认阻止 Web 服务器(Apache、nginx 等)进行出站网络连接。您需要对其进行配置,以允许 Web 服务器与数据库进行连接。

您可以使用适当的 SELinux 布尔值来做到这一点。

setsebool -P httpd_can_network_connect_db 1

相关内容