ITPub博客

首页 > 数据库 > PostgreSQL > PostgreSQL DBA(140) - PG 12(Don't log incomplete startup packet if it's empty)

PostgreSQL DBA(140) - PG 12(Don't log incomplete startup packet if it's empty)

翻译 PostgreSQL 作者:husthxd 时间:2019-12-09 16:19:05 0 删除 编辑

本节简单介绍了PostgreSQL 12 在日志记录上的改进:Don’t log incomplete startup packet if it’s empty。

This will stop logging cases where, for example, a monitor opens a connection and immediately closes it. If the packet contains any data an incomplete packet will still be logged.
Author: Tom Lane

对于每一个客户端连接,PG都会请求Postmaster,然后fork一个后台进程来处理请求,Postmaster期望每一个客户端请求发送startup message给PG Server,startup packet中的信息用于配置fork的后台进程。对于端口扫描、HA解决方案中的心跳检测等等都会发请求给PG Server port,PG会启动进程来处理这些连接,但安全检测、HA脚本等不同于常规的客户端,对于这些请求,PG会产生一条日志条目,因此会造成日志文件的膨胀而导致不必要的IO开销。

PG 11
使用工具nc来访问数据库端口,日志中会产生无用的日志条目。

[xdb@localhost ~]$ psql -c 'select version();'
Timing is on.
Expanded display is used automatically.
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 11.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)
Time: 56.253 ms
[xdb@localhost ~]$ 
[xdb@localhost ~]$ for i in {1..100}; do      nc -zv localhost 5110 ; done
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5110.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5110.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5110.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5110.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
...

数据库日志输出

2019-12-09 14:35:55.468 CST,,,16065,"::1:57554",5dedeb4b.3ec1,1,"",2019-12-09 14:35:55 CST,,0,LOG,08P01,"incomplete startup packet",,,,,,,,,""
2019-12-09 14:35:55.479 CST,,,16067,"::1:57556",5dedeb4b.3ec3,1,"",2019-12-09 14:35:55 CST,,0,LOG,08P01,"incomplete startup packet",,,,,,,,,""
2019-12-09 14:35:55.490 CST,,,16069,"::1:57558",5dedeb4b.3ec5,1,"",2019-12-09 14:35:55 CST,,0,LOG,08P01,"incomplete startup packet",,,,,,,,,""
2019-12-09 14:35:55.503 CST,,,16071,"::1:57560",5dedeb4b.3ec7,1,"",2019-12-09 14:35:55 CST,,0,LOG,08P01,"incomplete startup packet",,,,,,,,,""
2019-12-09 14:35:55.513 CST,,,16073,"::1:57562",5dedeb4b.3ec9,1,"",2019-12-09 14:35:55 CST,,0,LOG,08P01,"incomplete startup packet",,,,,,,,,""
...

这些日志其实是无用的日志信息,可以不作记录。

PG 12

[xdb@localhost ~]$ psql -h localhost -p 5120 -U pg12 -c 'select version();'
Timing is on.
Expanded display is used automatically.
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 12.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
(1 row)
Time: 60.207 ms
[xdb@localhost ~]$ 
[xdb@localhost ~]$ for i in {1..100}; do      nc -zv localhost 5120 ; done
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5120.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5120.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5120.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5120.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to ::1:5120.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
[xdb@localhost ~]$ 
...

数据库日志信息,相对于PG 11,没有出现无用的日志信息

[pg12@localhost ~]$ tail -f $PGDATA/pg_log/postgresql-2019-12-09.log 
2019-12-09 14:18:59.317 CST [1813] LOG:  ending log output to stderr
2019-12-09 14:18:59.317 CST [1813] HINT:  Future log output will go to log destination "csvlog".

参考资料
PostgreSQL 12 Improvement: Benign Log Entries “Incomplete Startup Packet”
PATCH

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6906/viewspace-2667566/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
ITPUB数据库版块资深版主,对Oracle、PostgreSQL有深入研究。

注册时间:2007-12-28

  • 博文量
    1465
  • 访问量
    3897237