我试图允许远程连接到ubuntu 19上的postgresql,我首先编辑了postgresql.conf,特别是参数listen_addresses,如下所示:
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
如本教程所述https://blog.bigbinary.com/2016/01/23/configure-postgresql-to-allow-remote-connection.html, 然后我使用以下命令重新启动psql服务器:
$ service postgresql restart
接下来,我也编辑了pg_hba.conf文件,并在最后添加了这两行:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
再次重新启动psql服务器。本教程说,这应该是全部,但是当我执行netstat -nlt命令以查看它是否已经起作用时,netstat显示以下信息:
$ netstat -nlt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN
tcp6 0 0 ::1:42545 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
tcp6 0 0 :::1883 :::* LISTEN
当它应该显示类似这样的内容时,特别是在端口5432上:
$ netstat -nlt
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2812 0.0.0.0:* LISTEN
tcp6 0 0 ::1:11211 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
我已经做过一些研究,可能与覆盖postgresql.conf文件的postgresql.auto.conf文件有关,但是由于postgresql.auto.conf仅显示以下内容,我无法进一步了解:
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM
感谢您对此问题的帮助。