gpt4 book ai didi

python - 当针对 CentOS 与 python 2.6 上的 information_schema 执行 "SELECT"语句时,psycopg2 挂起

转载 作者:太空狗 更新时间:2023-10-29 12:16:04 26 4
gpt4 key购买 nike

我有一个 python 脚本,它对 postgresql 数据库(RedShift)执行查询。它在我的本地机器上运行得很好:

Ubuntu 12.10,
python 2.7
psycog.__version__ = '2.5.3 (dt dec pq3 ext)'

但是当我在 AWS

上从我的生产机器执行 SOME 查询时它挂起
CentOS 6.5
Python 2.6
psycog.__version__ = '2.5.3 (dt dec pq3 ext)'

代码如下:

import psycopg2
con = psycopg2.connect(**{<my_connection_params>}})
curs = con.cursor()

# This works perfectly fine on both machines !!!
curs.execute("""SELECT table_name FROM information_schema.tables
WHERE table_schema='public' AND table_type='BASE TABLE'""")

# This one hangs on AWS, but works fine from my laptop
curs.execute('select column_name from information_schema.columns')

当我连接到 db 并运行查询以查看正在运行的进程时,我可以看到:

select pid, trim(user_name), starttime, substring(query,1,20)
from stv_recents
where status='Running';

我可以看到这个查询。

这是一个strace -p:

ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x3aaa00f710}, {0x3ab1027010, [], SA_RESTORER|SA_RESTART, 0x3aaa00f710}, 8) = 0
gettimeofday({1403280035, 826010}, NULL) = 0
rt_sigprocmask(SIG_BLOCK, [PIPE], [], 8) = 0
write(3, "\27\3\1\0 5\351Br$\331\30\00563\v\211f\325\367\210\331\331\253\300\310\240"..., 122) = 122
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
poll([{fd=3, events=POLLIN|POLLERR}], 1, -1) =

最佳答案

事实证明:

Amazon EC2-Classic instances can handle up to 1500 bytes of data per frame, while Amazon EC2-VPC instances can handle up to 9000 bytes of data per frame. In a mixed environment, we recommend disabling TCP/IP jumbo frames by setting the MTU to 1500 in the Amazon EC2-VPC instance; this way, both instances use 1500 bytes maximum. This is not necessary if both the client and cluster instances use Amazon EC2-VPC.

http://docs.aws.amazon.com/redshift/latest/mgmt/connecting-drop-issues.html

所以这一行将解决它:

ip link set dev eth0 mtu 1500

关于python - 当针对 CentOS 与 python 2.6 上的 information_schema 执行 "SELECT"语句时,psycopg2 挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com