简体   繁体   English

如何为远程 Postgresql 连接打开端口?

[英]How do I open a port for a remote Postgresql connection?

I am trying to set up a database on my computer that can be accessed remotely by others.我正在尝试在我的计算机上设置一个可以被其他人远程访问的数据库。 I have modified my postgresql.conf by to listening_addresses = '*' and added host all all 0.0.0.0/0 md5 to my pg_hba.conf file.我已将 postgresql.conf 修改为 listener_addresses listening_addresses = '*'并将host all all 0.0.0.0/0 md5添加到我的 pg_hba.conf 文件中。 When we try to connect to the database remotely, we get the error psql: could not connect to server: Connection refused Is the server running on host "MYIPADDRESS" and accepting CP/IP connections on port 5432?当我们尝试远程连接到数据库时,我们收到错误psql: could not connect to server: Connection refused Is the server running on host "MYIPADDRESS" and accepting CP/IP connections on port 5432? The port is 5432 is also closed when I got to https://www.yougetsignal.com/tools/open-ports/ .当我到达https://www.yougetsignal.com/tools/open-ports/时,端口 5432 也已关闭。 How do we go about solving this problem?我们如何解决这个问题? Let me know if I need to provide more code.如果我需要提供更多代码,请告诉我。 Thanks in advance!提前致谢!

Update: Here is my log.更新:这是我的日志。

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" 

Are you sure so your database is running?你确定你的数据库正在运行吗?

Do you see Postgres is process list?你看到 Postgres 是进程列表吗? ps ax|grep postgres . ps ax|grep postgres

Do you see some interesting in Postgres log?你在 Postgres 日志中看到一些有趣的东西吗?

Postgres log should to contains: 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"

If Postgres is running, then problem can be firewall.如果 Postgres 正在运行,那么问题可能是防火墙。 You should to open port 5432 for remote access.您应该打开端口 5432 进行远程访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM