2011-10-05 71 views
2

我有一个应用程序psycopg2 + pgbouncer + gevent。异步应用程序,即一个进程提供多个请求。异步访问数据库出现在最新版本的psycopg2中,如果宁愿的话2.2。但是在这个版本中引入了一个bug,这个bug与pgbouncer有很多断开关系。 在pgbouncer日志有条目:psycopg2 + pgbouncer。异步模式与gevent错误

2011-10-04 12:16:38.972 4590 LOG C-0x1b3f490: database/[email protected]:43849 login successful: db=database user=user 
2011-10-04 12:16:38.972 4590 LOG C-0x1b3f0a0: database/[email protected]:43850 login successful: db=database user=user 
2011-10-04 12:16:38.973 4590 LOG C-0x1b40840: database/[email protected]:43802 closing because: client close request (age=0) 
2011-10-04 12:16:38.973 4590 LOG S-0x1b5cd80: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:38.976 4590 LOG C-0x1b3ef50: database/[email protected]:43825 closing because: client close request (age=0) 
2011-10-04 12:16:38.976 4590 LOG S-0x1b5e520: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:38.977 4590 LOG S-0x1b5e520: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.979 4590 LOG C-0x1b3f340: database/[email protected]:43791 closing because: client close request (age=0) 
2011-10-04 12:16:38.979 4590 LOG S-0x1b5d410: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:38.980 4590 LOG S-0x1b5d410: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.983 4590 LOG S-0x1b5cd80: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.987 4590 LOG S-0x1b5dbf0: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.990 4590 LOG S-0x1b5c1b0: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.992 4590 LOG C-0x1b3ff10: database/[email protected]:43854 login successful: db=database user=user 
2011-10-04 12:16:38.995 4590 LOG S-0x1b5c450: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.996 4590 LOG C-0x1b3f340: database/[email protected]:43855 login successful: db=database user=user 
2011-10-04 12:16:38.996 4590 LOG C-0x1b3ee00: database/[email protected]:43828 closing because: client close request (age=0) 
2011-10-04 12:16:38.998 4590 LOG S-0x1b5c300: database/[email protected]:5432 new connection to server 
2011-10-04 12:16:38.999 4590 LOG C-0x1b3f1f0: database/[email protected]:43805 closing because: client close request (age=0) 
2011-10-04 12:16:38.999 4590 LOG S-0x1b5daa0: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:39.010 4590 LOG C-0x1b41410: database/[email protected]3:43655 closing because: client close request (age=1) 
2011-10-04 12:16:39.010 4590 LOG S-0x1b5d2c0: database/[email protected]:5432 closing because: unclean server (age=1) 
2011-10-04 12:16:39.011 4590 LOG S-0x1b5d2c0: datab+ase/[email protected]:5432 new connection to server 
2011-10-04 12:16:39.014 4590 LOG C-0x1b3fc70: database/[email protected]:43818 closing because: client close request (age=0) 
2011-10-04 12:16:39.014 4590 LOG S-0x1b5d170: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:39.042 4590 LOG C-0x1b40990: database/[email protected]:43822 closing because: client close request (age=0) 
2011-10-04 12:16:39.042 4590 LOG S-0x1b5de90: database/[email protected]:5432 closing because: unclean server (age=0) 
2011-10-04 12:16:39.043 4590 LOG C-0x1b40060: database/[email protected]:43820 closing because: client close request (age=0) 
2011-10-04 12:16:39.043 4590 LOG S-0x1b5e280: database/[email protected]:5432 closing because: unclean server (age=0) 

也许有某种方式来配置pgbouncer,避免不洁有关服务器的消息? Information about a bug,就像有一个补丁可以治愈某些东西。所有来自ubuntu存储库的软件包,在生产机器上应用补丁 - 不是一个好选择。 我的配置pgboucner:

[pgbouncer] 
logfile = /var/log/postgresql/pgbouncer.log 
pidfile = /var/run/postgresql/pgbouncer.pid 
listen_addr = * 
listen_port = 6432 
unix_socket_dir = /var/run/postgresql 

pool_mode = session 

server_reset_query = DISCARD ALL; 
server_check_query = select 1 
server_check_delay = 10 

max_client_conn = 1000 
default_pool_size = 200 

log_connections = 1 
log_disconnections = 1 

回答

4

您可能不会调用connection.close()。在Psycopg 2.2之前,在连接删除时发布了一个隐式ROLLBACK,但是这种情况再也无法得到保证(甚至在它被认为不安全之前)。

请参阅http://initd.org/psycopg/docs/connection.html#connection.close

+1

嗯。如果我关闭连接,那么我应该在每个请求上重新分配给db?我想我可以使用持久连接。 – exabiche

+0

不,实际上我认为这足以提交或回滚。从我们所报告的情况来看,当连接以“事务中”的状态返回到pgpool时,会报告“不洁服务器”。尝试监视离开系统的连接的''.status''属性。 – piro

+0

当我使用'close'方法时 - 有一个像'不能使用闭合连接'的错误。然后我使用“提交”方法 - 有关不洁服务器消失的错误消息,但在pgbouncer日志中,我收到了很多关于连接和断开数据库的消息。我可以使用持久连接吗? http://pastebin.com/GNpNJrPk – exabiche