【发布时间】:2020-11-13 11:19:34
【问题描述】:
我无法从 python 连接到 Azure postgres 数据库。我在这里遵循指南 - https://docs.microsoft.com/cs-cz/azure/postgresql/connect-python 我有基本相同的代码来建立连接。 但是 psycopg2 和 SQLalchemy 给我带来了同样的错误:
OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
我可以通过 dbeaver 等其他客户端工具连接到实例,但从 python 中它不起作用。
当我在 Postgres 日志中进行调查时,我可以看到服务器实际上授权了连接,但下一行显示
could not receive data from client: An existing connection was forcibly closed by the remote host.
Python 是 3.7 psycopg 的版本是 2.8.5 Azure Postgres 区域位于西欧
有人对我应该如何尝试使其工作有任何建议吗?
谢谢!
编辑: 问题自己解决了。几天后我尝试了相同的设置,它开始工作了。 Azure West Europe 可能有问题。
【问题讨论】:
-
间歇性地面临同样的问题。我们有一个每天运行 8 小时的负载。每周至少一次失败,我们必须重新触发。痛苦。我们的 Postgres 服务器上有大量未使用的资源,所以这不是问题。看起来它与维护模式有关。
标签: python-3.x postgresql azure psycopg2