2011-10-05 66 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