2016-11-15 21 views
1

我在我的Django网络应用程序中使用pgbouncer。应用程序服务器和数据库服务器是两个独立的VM。 pgbouncer安装在应用程序服务器上。在pgbouncer.ini相关的设置是:解释django项目中的pgbouncer日志条目

[databases] 
dbname = host=80.211.128.113 port=5432 dbname=dbname 

pool_mode = transaction 
max_client_conn = 250 
default_pool_size = 100 

一旦pgbouncer接手,我查pgbouncer.log,发现许多条目如下:

2016-11-15 12:26:27.514 582 LOG S-0x1192740: dbname/[email protected]:5432 new connection to server 
2016-11-15 12:26:27.517 582 LOG C-0x11afcb8: dbname/[email protected]:42262 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.523 582 LOG S-0x1192a10: dbname/[email protected]:5432 new connection to server 
2016-11-15 12:26:27.528 582 LOG C-0x11af880: dbname/[email protected]:42250 closing because: client close request (age=0) 
2016-11-15 12:26:27.528 582 LOG S-0x1191a98: dbname/[email protected]:5432 closing because: unclean server (age=0) 
2016-11-15 12:26:27.548 582 LOG C-0x11afb50: dbname/[email protected]:42258 closing because: client close request (age=0) 
2016-11-15 12:26:27.556 582 LOG C-0x11aff88: dbname/[email protected]:42256 closing because: client close request (age=0) 
2016-11-15 12:26:27.556 582 LOG S-0x1191c00: dbname/[email protected]:5432 closing because: unclean server (age=0) 
2016-11-15 12:26:27.564 582 LOG C-0x11aff88: dbname/[email protected]:42264 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.569 582 LOG C-0x11afb50: dbname/[email protected]:42265 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.570 582 LOG S-0x1191c00: dbname/[email protected]:5432 new connection to server 
2016-11-15 12:26:27.593 582 LOG C-0x11af448: dbname/[email protected]:42255 closing because: client close request (age=0) 
2016-11-15 12:26:27.593 582 LOG C-0x11afcb8: dbname/[email protected]:42262 closing because: client close request (age=0) 
2016-11-15 12:26:27.593 582 LOG S-0x1191c00: dbname/[email protected]:5432 closing because: unclean server (age=0) 
2016-11-15 12:26:27.597 582 LOG C-0x11afb50: dbname/[email protected]:42265 closing because: client close request (age=0) 
2016-11-15 12:26:27.603 582 LOG C-0x11afb50: dbname/[email protected]:42267 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.604 582 LOG C-0x11afcb8: dbname/[email protected]:42268 login attempt: db=dbname user=myuser 

如果仔细分析的closing because: unclean serverclosing because: client close request许多实例中发现日志文件。任何人都可以解释这些是什么?也许我做错了什么。表面上看,我的应用程序似乎到目前为止运行正常。但我需要了解我在日志文件中看到的内容,因此我可以确定是什么。提前致谢。

回答

0
  • LOG C - 记录与此头都涉及到连接到 pgbouncer(不是PostgreSQL服务器)的客户端。
  • LOG S - 约 pgbouncer和服务器之间的通信(真正连接到 posgres服务器)。
  • age=0 - 告知使用时间,即LOG Cage=0, 表示客户端使用的连接时间少于1秒。

答案

关闭的原因是:客户端关闭请求

没什么可担心的,完全正常。它记录客户端已经相当客户端不再有与pgbouncer的实时连接。

通常日志就像

在第一次尝试连接到pgbouncer

1个线 - 连接尝试pgbouncer。

第2行 - pgbouncer将连接尝试连接到postgresql服务器。

第3行 - 客户端请求完成和客户pgbouncer连接被关闭

2016-11-15 12:26:27.517 582 LOG C-0x11afcb8: dbname/[email protected]:42262 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.523 582 LOG S-0x1192a10: dbname/[email protected]:5432 new connection to server 
2016-11-15 12:26:27.528 582 LOG C-0x11af880: dbname/[email protected]:42250 closing because: client close request (age=0) 

行1 - 连接尝试通过一个新的客户端pgbouncer。它会重新使用已经打开的连接到PostgreSQL服务器(打开最后一个客户端)

2号线 - 客户端请求已完成和客户pgbouncer连接被关闭

2016-11-15 12:26:27.569 582 LOG C-0x11afb50: dbname/[email protected]:42265 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.593 582 LOG C-0x11af448: dbname/[email protected]:42255 closing because: client close request (age=0) 

1号线& 2 - 2个并发客户端试图连接到pgbouncer

3号线 - pgbouncer进行第二尝试连接到PostgreSQL服务器,为第二个客户端(第一个将重新使用已经打开了一个)

4号线& 5 - 客户端请求已完成和客户pgbouncer连接关闭

2016-11-15 12:26:27.564 582 LOG C-0x11aff88: dbname/[email protected]:42264 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.569 582 LOG C-0x11afb50: dbname/[email protected]:42265 login attempt: db=dbname user=myuser 
2016-11-15 12:26:27.570 582 LOG S-0x1191c00: dbname/[email protected]:5432 new connection to server 
2016-11-15 12:26:27.593 582 LOG C-0x11af448: dbname/[email protected]:42255 closing because: client close request (age=0) 
2016-11-15 12:26:27.593 582 LOG C-0x11afcb8: dbname/[email protected]:42262 closing because: client close request (age=0) 

收盘因为:不洁服务器

可能是一个问题,因为它似乎像pgbouncer越来越和每一个连接到它的新客户端都会关闭postgres服务器的新连接(pgbouncer)。

可能的解决方案 /出路 - 可能与Django works by default有什么关系。

与正常池pgbouncer不能关闭它的连接Postgres的服务器(在关闭客户连接的时间) - 你可能会得到这个服务器连接关闭消息/日志时,连接可能达到server_lifetimeserver_idle_timeout空闲时,否则不。


+0

感谢您的深度响应。我的日志条目中超过95%的客户端关闭请求的“age = 0”。你认为这是正常的吗? –

+0

嗯,pgbouncer在任何地方记录日志都是完整的,如上所述,它会在每次登录尝试(一个连接到pgbouncer的客户端)之后出现。 –