在CentOS上执行对information_schema的“SELECT”语句时psycopg2挂起与python 2.6相关

2 投票
1 回答
886 浏览
提问于 2025-04-18 10:31

我有一个Python脚本,它用来对PostgreSQL数据库(RedShift)执行查询。在我本地机器上运行得非常顺利:

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

但是当我在生产机器上执行某些查询时,它就卡住了,那个机器是在AWS上。

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) =

1 个回答

2

结果是:

Amazon EC2-Classic 实例每个数据帧最多可以处理 1500 字节的数据,而 Amazon EC2-VPC 实例每个数据帧最多可以处理 9000 字节的数据。在混合环境中,我们建议通过将 Amazon EC2-VPC 实例的 MTU 设置为 1500 来禁用 TCP/IP 的 jumbo frames;这样的话,两个实例都最多使用 1500 字节。如果客户端和集群实例都使用 Amazon EC2-VPC,这个设置就不是必须的。

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

所以这行代码可以解决这个问题:

ip link set dev eth0 mtu 1500

撰写回答