如何打开用于远程Postgresql连接的端口?

时间:2020-06-01 02:44:10

标签: sql database postgresql port

我试图在我的计算机上设置一个数据库,其他人可以远程访问该数据库。我已将postgresql.conf修改为listening_addresses = '*',并将host all all 0.0.0.0/0 md5添加到了pg_hba.conf文件中。当我们尝试远程连接到数据库时,出现错误psql: could not connect to server: Connection refused Is the server running on host "MYIPADDRESS" and accepting CP/IP connections on port 5432?,当我进入https://www.yougetsignal.com/tools/open-ports/时,端口5543也被关闭了。我们该如何解决这个问题?让我知道是否需要提供更多代码。预先感谢!

更新:这是我的日志。

2020-06-01 12:00:09.385 EDT [13570] LOG:  listening on IPv6 address "::1", port 5432
2020-06-01 12:00:09.385 EDT [13570] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-06-01 12:00:09.386 EDT [13570] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432" 

1 个答案:

答案 0 :(得分:0)

确定要运行数据库吗?

您看到Postgres是进程列表吗? ps ax|grep postgres

您在Postgres日志中看到一些有趣的东西吗?

Postgres日志应包含:

serverlog          [----]  0 L:[  1+ 0   1/589] *(0   /50295b) 0050 0x032                                                                                              [*][X]
2020-05-29 07:45:11.931 CEST [12960] LOG:  starting PostgreSQL 13beta1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.1.1 20200507 (Red Hat 10.1.1-1), 64-bit
2020-05-29 07:45:11.933 CEST [12960] LOG:  listening on IPv6 address "::1", port 5432
2020-05-29 07:45:11.933 CEST [12960] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-05-29 07:45:11.959 CEST [12960] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

如果Postgres正在运行,则问题可能出在防火墙上。您应该打开端口5432进行远程访问。