postgresql 客户端连接上的意外 EOF 与打开的事务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40253832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:25:19  来源:igfitidea点击:

Unexpected EOF on client connection with an open transaction

postgresqlpython-2.7

提问by PengJ

I want to using threading to connect postgresql but postgresql log show:

我想用线程连接postgresql但是postgresql日志显示:

unexpected EOF on client connection with an open transaction

具有打开事务的客户端连接上的意外 EOF

here is my code:

这是我的代码:

conn = []
for i in range(10):
    conn.append(psycopg2.connect("dbname=test user=higis password=dbrgdbrg host=10.1.1.215 port=5432"))
print conn
def test_query(a,b,c,d,name,i):
    try:
        #conn = psycopg2.connect("dbname=test user=higis password=dbrgdbrg host=10.1.1.215 port=5432")
        cur = conn[i].cursor()
        sql_query = "SELECT count(*) FROM " + str(name) + " WHERE ST_MAKEENVELOPE" + str(
            (a, b, c, d, 4326)) + "&& wkb_geometry"
        start = time.time()
        cur.execute(sql_query)
        #conn.commit()
        end = time.time()
        results_time = end - start
        results = cur.fetchall()
        cur.close()
        conn[i].close()
        #print results
        #print  results[0][0]
        suit_f = open("/home/pj/Desktop/test/log/replicate_query_time.txt", 'a')
        print >> suit_f, (
            'range query table:,%s,(%s %s %s %s),%s,%s' % (name, a, b, c, d, results[0][0], results_time))
    except Exception, e:
        print e

a_all = [1,2,3,4,5,6,7,8,9,10]
b_all = [1,2,3,4,5,6,7,8,9,10]
c_all = [1,2,3,4,5,6,7,8,9,10]
d_all = [1,2,3,4,5,6,7,8,9,10]
threads = []
for i in range(10):
    a = a_all[i]
    b = b_all[i]
    c = c_all[i]
    d = d_all[i]
    t = threading.Thread(target=test_query,args=(a,b,c,d,"replicate_table1",i))
    threads.append(t)

if __name__ == '__main__':
    i = 0
    for t in threads:
        print "Thread:" + str(i) + " t and the time = %s" %(ctime())
        t.setDaemon(True)
        t.start()
        i = i+1
    t.join()
    #conn.commit()

回答by dland

At some point the server received a client connection which presented the appropriate credentials (and thus a session was established).

在某些时候,服务器收到一个客户端连接,该连接提供了适当的凭据(从而建立了会话)。

This log message is informing you that the client disconnected the session "it just walked away!" without shutting down cleanly. Maybe the code is throwing an exception before it gets to the cur.close()statement.

此日志消息通知您客户端断开了会话“它刚刚走开了!” 没有干净地关闭。也许代码在到达cur.close()语句之前抛出了异常。