Psycopg2 Python 太慢,无法在 Ubuntu 中从 Dbeaver 检索数据。不知道为什么

发布于 2025-01-19 20:41:18 字数 740 浏览 2 评论 0原文

我希望有人能帮助我 我尝试使用 python 检索驻留在堡垒主机后面的 AWS RDS EC2 实例中的数据,遇到了一个奇怪的问题,该主机是我在 ubuntu LTS 20.04 上的 Dbeaver 中本地连接的,

我使用的是非常标准的代码,昨天运行时没有任何问题 今天的性能

import psycopg2 
con = psycopg2.connect(user=myuser,
                       password=mypassword,
                        host='localhost',
                        port=5433,
                        database=mydwh)

sql = """select * from table limit 100"""

data = pd.read_sql(sql, con)

我可以超快速地检索 100 行,所以我知道连接工作正常, 但如果我想检索整个表,即大约 1M 行,它似乎完全卡住并且无法工作,即使在 1 小时后也是如此。 dbeaver 中的相同查询(无限制)大约需要 15 秒来计算。

我已经尝试将端口从 5434 更改为 5433,并将 localhost 更改为 127.0.0.1,因为我在某处读到可能存在问题,但没有任何改变。端口 5432 已被使用。

你知道为什么它突然这么慢吗?昨天同样的操作最多持续 30 秒。任何帮助将非常感激,因为我真的不知道发生了什么

I hope that someone can help me,
I have a weird issue by trying to retrieve data with python that resides into AWS RDS EC2 instance behind a bastion host that I connected locally in Dbeaver on my ubuntu LTS 20.04

I'm using a very standard code that yesterday was working without any issue in performance

import psycopg2 
con = psycopg2.connect(user=myuser,
                       password=mypassword,
                        host='localhost',
                        port=5433,
                        database=mydwh)

sql = """select * from table limit 100"""

data = pd.read_sql(sql, con)

today I can retrieve super fast 100 rows, so I know that the connection works fine,
but if I want to retrieve the whole table i.e. around 1M rows it seems to be completely stuck and not to work, even after 1 hour. The same query (without limit) in dbeaver takes around 15seconds to compute.

I already tried to change the port from 5434 to 5433 and changing localhost to 127.0.0.1, because I read somewhere that could be an issue, but nothing changed. The port 5432 is already in use.

Do you have any idea why it is suddenly so slow? Yesterday the same operation was lasting max 30sec. Any help would be really appreciated, because I really have no clue about what happened

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文