PostgreSQL 12在日志记录上的改进是什么

37次阅读
没有评论

共计 3572 个字符,预计需要花费 9 分钟才能阅读完成。

本篇内容主要讲解“PostgreSQL 12 在日志记录上的改进是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“PostgreSQL 12 在日志记录上的改进是什么”吧!

对于每一个客户端连接,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 在日志记录上的改进是什么”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-26发表,共计3572字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)