sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)无法连接到服务器:连接超时

时间:2020-08-06 22:43:30

标签: python postgresql amazon-web-services sqlalchemy psycopg2

大约一个小时前,我已将我的RDS亚马逊数据库实例(PostgreSQL数据库)从微型升级到小型。尽管它说它可以在Amazon控制台上使用,但是每次从应用程序访问数据库时,我总是收到错误(psycopg2.OperationalError) could not connect to server: Connection timed out.

我真的不是专家,所以我不知道怎么回事,因为在那之前一切都很好。

当尝试通过以下方式从我的ubuntu计算机访问服务器时:

psql -h Ip -d db -U myuser

我遇到相同的错误:

psql: could not connect to server: Connection timed out
    Is the server running on host "IP" and accepting
    TCP/IP connections on port 5432?

另一方面,PgAdmin4内部的一切看起来也很好。

我想知道是否只需要等待一点时间让事情初始化。顺便说一句,我正在开发一个django项目,在进行此类升级之后,是否需要进行一些设置?有人遇到过同样的问题吗?

这是postgres错误日志:

2020-08-07 10:00:16 UTC::@:[13371]:LOG: checkpoint starting: time
2020-08-07 10:00:16 UTC::@:[13371]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.132 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65537 kB
2020-08-07 10:05:16 UTC::@:[13371]:LOG: checkpoint starting: time
2020-08-07 10:05:16 UTC::@:[13371]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.136 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65537 kB
2020-08-07 10:10:16 UTC::@:[13371]:LOG: checkpoint starting: time
2020-08-07 10:10:16 UTC::@:[13371]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.135 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65534 kB, estimate=65537 kB
2020-08-07 10:12:03 UTC::@:[13368]:LOG: received fast shutdown request
2020-08-07 10:12:03 UTC::@:[13368]:LOG: aborting any active transactions
2020-08-07 10:12:03 UTC::@:[13368]:LOG: background worker "logical replication launcher" (PID 13377) exited with exit code 1
2020-08-07 10:12:03 UTC::@:[13371]:LOG: shutting down
2020-08-07 10:12:03 UTC::@:[13371]:LOG: checkpoint starting: shutdown immediate
2020-08-07 10:12:03 UTC::@:[13371]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.000 s, sync=0.007 s, total=0.037 s; sync files=1, longest=0.007 s, average=0.007 s; distance=65535 kB, estimate=65537 kB
2020-08-07 10:12:03 UTC::@:[13368]:LOG: database system is shut down
2020-08-07 10:12:06 UTC::@:[28963]:LOG: database system was shut down at 2020-08-07 10:12:03 UTC
2020-08-07 10:12:06 UTC::@:[28961]:LOG: database system is ready to accept connections
2020-08-07 10:17:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:17:07 UTC::@:[28964]:LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.881 s, sync=0.006 s, total=0.921 s; sync files=3, longest=0.006 s, average=0.002 s; distance=16 kB, estimate=16 kB
2020-08-07 10:22:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:22:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.678 s, sync=0.006 s, total=0.712 s; sync files=1, longest=0.006 s, average=0.006 s; distance=65521 kB, estimate=65521 kB
2020-08-07 10:27:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:27:07 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.693 s, sync=0.006 s, total=0.727 s; sync files=1, longest=0.006 s, average=0.006 s; distance=65536 kB, estimate=65536 kB
2020-08-07 10:32:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:32:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.101 s, sync=0.005 s, total=0.131 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65536 kB
2020-08-07 10:37:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:37:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.131 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65535 kB, estimate=65536 kB
2020-08-07 10:42:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:42:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.132 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65536 kB
2020-08-07 10:47:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:47:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.135 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65536 kB
2020-08-07 10:52:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:52:07 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.006 s, total=0.133 s; sync files=1, longest=0.006 s, average=0.006 s; distance=65535 kB, estimate=65536 kB
2020-08-07 10:57:06 UTC::@:[28964]:LOG: checkpoint starting: time
2020-08-07 10:57:06 UTC::@:[28964]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.137 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=65536 kB
----------------------- END OF LOG ----------------------

更新:我尝试测试服务器上的端口,重新启动RDS实例无效,还卸载并重新安装了psycopg2和sqlalchemy。

我可以从命令行连接到数据库。 我用nmap测试了端口,给出了以下结果:

PORT     STATE    SERVICE
5432/tcp filtered postgresql

我仍然非常困惑,并且该应用在过去10个小时内无法正常工作!

更新: 我刚刚注意到,在database/mydb/configurations/parameters group的aws控制台中,它显示为default.postgres11 (in-sync)。可能是升级后突然出现问题的原因吗?我不记得之前在同步中说过,我想知道它能持续多久

0 个答案:

没有答案