pgbouncer连接池正常日志内容一例
因为PostgreSQL采用进程模式,大量连接对数据库性能会产生较大影响。所以在大量连接情况下,一般会在数据库和应用程序之间配置pgbouncer。pgbouncer可以配置在数据库主机上,也可以配置在单独的一台服务器。当然如果不知道pgbouncer怎么安装,可以参考这篇《pgbouncer安装》的文章,https://zhangnq.com/1309.html 。
下面是一个正常pgbouncer运行过程中的日志。从这个日志中可以看到几个参数,他们分别是req/s,in xx b/s,out xx b/s,query xx us 。那么这几个参数是什么意思?
2014-11-19 00:32:25.615 15304 LOG Stats: 1498 req/s, in 213991 b/s, out 6578930 b/s,query 4504 us
2014-11-19 00:33:25.616 15304 LOG Stats: 1617 req/s, in 238981 b/s, out 6685419 b/s,query 4421 us
2014-11-19 00:34:25.616 15304 LOG Stats: 1617 req/s, in 234316 b/s, out 2966821 b/s,query 5843 us
2014-11-19 00:35:25.616 15304 LOG Stats: 1759 req/s, in 265723 b/s, out 2524038 b/s,query 4763 us
2014-11-19 00:36:25.617 15304 LOG Stats: 1682 req/s, in 252605 b/s, out 5539475 b/s,query 5089 us
2014-11-19 00:37:25.617 15304 LOG Stats: 1633 req/s, in 228204 b/s, out 5312089 b/s,query 4452 us
2014-11-19 00:38:25.617 15304 LOG Stats: 1613 req/s, in 229847 b/s, out 3155005 b/s,query 4719 us
2014-11-19 00:39:25.618 15304 LOG Stats: 1658 req/s, in 235340 b/s, out 5546190 b/s,query 4472 us
2014-11-19 00:40:25.618 15304 LOG Stats: 1702 req/s, in 250598 b/s, out 3714750 b/s,query 5888 us
2014-11-19 00:41:25.620 15304 LOG Stats: 1727 req/s, in 256322 b/s, out 5693627 b/s,query 4855 us
req/s:每秒的请求数,request per second。
in b/s:这个比较好读懂,每秒读入字节数。
out b/s:和in b/s一样,表示每秒读出的字节数。
query us:我的理解是平均每个查询话费的时间,单位毫秒。us应该是used的缩写。
结合这个日志,在登陆pgbouncer查看运行状态。
postgres@ubuntu:/var/log/pgbouncer$ psql -U pgbouncer -p 6432 -d pgbouncer
Password for user pgbouncer:
psql.bin (9.2.9, server 1.5.4/bouncer)
WARNING: psql.bin version 9.2, server version 1.5.
Some psql features might not work.
Type "help" for help.
pgbouncer=# show stats ;
database | total_requests | total_received | total_sent | total_query_time | avg_req | avg_recv | avg_sent | avg_query
------+------+----------+---------+-----------+--------+----------+-------+----
xxxx | 2554218382 | 388493014688 | 8095950760712 | 22137810844111 | 1631 | 278549 | 3503231 | 8986
pgbouncer | 4 | 0 | 0 | 0 | 0 | 0 | 0 | 0
(2 rows)
这个状态更加详细,其中avg_req对应req/s,avg_query对应query us 。其他参数通过字段名可以很容易理解。