当我尝试在 digitalocean 和 azure 函数上连接 postgres sql 服务器时连接超时

Connection timed out when I try to connect posgrest sql server on digitalocen and azure function

我在数字海洋服务器上有一个 postgres 数据库 运行。数据库受防火墙和 ssl 根证书保护,我将 Azure Function App 提供的出站地址添加到数据库防火墙,我通过连接字符串传递证书。

pg_conn = psycopg2.connect(host= os.environ.get("PG_HOST"),database= os.environ.get("PG_DB"), user=os.environ.get("PG_USER"), password=os.environ.get("PG_PASSWORD"), port=os.environ.get("PG_PORT"), sslmode='require', sslrootcert = r'my-proyect/certificate.crt' )

但是当我将我的函数上传到云端时,连接发送超时

Connection timed out Is the server running on that host and accepting TCP/IP connections?

据我所知,连接 time-out 错误通常是由于连接问题或网络问题造成的。

  • 防火墙如果不允许访问应用程序拥有的端口号。

解决这类问题的工具是portgry

portqry -n [hostname] -e [port number]

  • 您甚至可以将应用程序添加到 Postgry 中的可信资源 SQL

这里是 document,其中包含有关连接超时错误的完整信息。