psycopg2 +保镖。带有 gevent 错误的异步模式
我有一个应用程序 psycopg2 + pgbouncer + gevent。异步应用程序,即一个进程服务多个请求。异步访问数据库出现在最新版本的psycopg2(如果不是2.2)中。但就在这个版本中引入了错误,导致 pgbouncer 出现很多断线。 在 pgbouncer 日志中有一些条目:
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]: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,以避免有关不干净服务器的消息? 有关错误的信息,例如有一个补丁治愈某些东西。来自 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
I've got an application psycopg2 + pgbouncer + gevent. Asynchronous application, ie one process serves multiple requests. Asynchronous access to database appeared in the latest version of psycopg2, if rather then 2.2. But just in this release introduces bug for which there is a lot of disconnections from pgbouncer.
In the pgbouncer logs there are entries:
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]: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)
Maybe there is some way to configure pgbouncer, to avoid messages about unclean server?
Information about a bug, like there is a patch that cures something. All packages from ubuntu repositories, apply patches on the production machine - not a good option.
My config 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能没有调用connection.close()。在 Psycopg 2.2 之前,在连接删除时会发出隐式 ROLLBACK,但这种情况无法再得到保证(甚至在它被认为不安全之前)。
请参阅http://initd.org/psycopg/docs/connection.html#connection。关闭
You are probably not calling connection.close(). Before Psycopg 2.2 an implicit ROLLBACK was issued on connection delete, but this condition couldn't be guaranteed anymore (and even before it was considered not safe).
See http://initd.org/psycopg/docs/connection.html#connection.close