这是在 OCI 上新安装的 Ubuntu 20.04。Postgres 数据库已安装并运行良好。问题是我无法使用主机的 IP 地址连接到数据库。请参阅下面的错误。
psql -h 135.145.78.113 -p 5432 -d postgres -U postgres -W
Password:
psql: error: connection to server at "135.145.78.113", port 5432 failed: Connection timed out
Is the server running on that host and accepting TCP/IP connections?
当使用 localhost 时,连接方式如下所示。
psql -h localhost -p 5432 -d postgres -U postgres -W
Password:
psql (13.7 (Ubuntu 13.7-1.pgdg22.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
非常感谢您的支持。
答案1
答案2
通过在 OCI 中使用主机的私有 IP 解决了这个问题。我使用的是公共 IP,这导致了错误。
使用公共 IP
lssnadmin@staging:~$ psql -h 111.111.111.1 -p 5432 -d postgres -U postgres -W
Password:
psql: error: connection to server at "111.111.111.1", port 5432 failed: No route to host
Is the server running on that host and accepting TCP/IP connections?
使用私有 IP
lssnadmin@staging:~$ psql -h 10.0.0.90 -p 5432 -d postgres -U postgres -W
Password:
psql (13.7 (Ubuntu 13.7-1.pgdg22.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=#