我有一个python脚本执行查询postgresql数据库(RedShift。它在我的本地机器上运行得很好:
Ubuntu 12.10, python 2.7 psycog.__version__ = '2.5.3 (dt dec pq3 ext)'
但是,当我在AWS
上执行我的prod机器上的一些查询时,它会挂起
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实例每帧最多可处理1500个字节的数据,而Amazon EC2-VPC实例每帧最多可处理9000个字节的数据。 在混合环境中,我们建议通过在Amazon EC2-VPC实例中将MTU设置为1500来禁用TCP / IP巨型帧; 这样,两个实例最多使用1500个字节。 如果客户端和集群实例都使用Amazon EC2-VPC,则这不是必需的。
http://docs.aws.amazon.com/redshift/latest/mgmt/connecting-drop-issues.html
所以这条线将解决它:
ip link set dev eth0 mtu 1500