作者
digoal
日期
2022-01-12
标签
PostgreSQL , log , csvlog , jsonlog
https://www.postgresql.org/docs/devel/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE
Including jsonlog in the log_destination list provides a convenient way to import log files into many different programs. This option emits log lines in (JSON) format. String fields with null values are excluded from output. Additional fields may be added in the future. User applications that process jsonlog output should ignore unknown fields. Each log line is serialized as a JSON object as of the following set of keys with their values.
复制
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=dc686681e0799b12c40f44f85fc5bfd7fed4e57f
Introduce log_destination=jsonlog author Michael Paquier <michael@paquier.xyz> Mon, 17 Jan 2022 01:16:53 +0000 (10:16 +0900) committer Michael Paquier <michael@paquier.xyz> Mon, 17 Jan 2022 01:16:53 +0000 (10:16 +0900) commit dc686681e0799b12c40f44f85fc5bfd7fed4e57f tree 66654ff9d34f4153810245c2152a6d2ddfbeb761 tree parent 6478896675660402171c97d6307e6e1519250025 commit | diff Introduce log_destination=jsonlog "jsonlog" is a new value that can be added to log_destination to provide logs in the JSON format, with its output written to a file, making it the third type of destination of this kind, after "stderr" and "csvlog". The format is convenient to feed logs to other applications. There is also a plugin external to core that provided this feature using the hook in elog.c, but this had to overwrite the output of "stderr" to work, so being able to do both at the same time was not possible. The files generated by this log format are suffixed with ".json", and use the same rotation policies as the other two formats depending on the backend configuration. This takes advantage of the refactoring work done previously in ac7c807, bed6ed3, 8b76f89 and 2d77d83 for the backend parts, and 72b76f7 for the TAP tests, making the addition of any new file-based format rather straight-forward. The documentation is updated to list all the keys and the values that can exist in this new format. pg_current_logfile() also required a refresh for the new option. Author: Sehrope Sarkuni, Michael Paquier Reviewed-by: Nathan Bossart, Justin Pryzby Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
复制
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=ac7c80758a7ad6369aefce7406f08c689144ec4b
Refactor set of routines specific to elog.c author Michael Paquier <michael@paquier.xyz> Wed, 12 Jan 2022 05:16:59 +0000 (14:16 +0900) committer Michael Paquier <michael@paquier.xyz> Wed, 12 Jan 2022 05:16:59 +0000 (14:16 +0900) commit ac7c80758a7ad6369aefce7406f08c689144ec4b tree 2a42b18e86912ceb5137eaf6033bf443b3a37bc9 tree parent 9a3d8e1886670ca3532687c5336d97965a79a084 commit | diff Refactor set of routines specific to elog.c This refactors the following routines and facilities coming from elog.c, to ease their use across multiple log destinations: - Start timestamp, including its reset, to store when a process has been started. - The log timestamp, associated to an entry (the same timestamp is used when logging across multiple destinations). - Routine deciding if a query can be logged or not. - The backend type names, depending on the process that logs any information (postmaster, bgworker name or just GetBackendTypeDesc() with a regular backend). - Write of logs using the logging piped protocol, with the log collector enabled. - Error severity converted to a string. These refactored routines will be used for some follow-up changes to move all the csvlog logic into its own file and to potentially add JSON as log destination, reducing the overall size of elog.c as the end result. Author: Michael Paquier, Sehrope Sarkuni Reviewed-by: Nathan Bossart Discussion: https://postgr.es/m/CAH7T-aqswBM6JWe4pDehi1uOiufqe06DJWaU5=X7dDLyqUExHg@mail.gmail.com
复制
Hi, This patch adds a new log_destination, "jsonlog", that writes log entries as lines of JSON. It was originally started by David Fetter using the jsonlog module by Michael Paquier ( https://github.com/michaelpq/pg_plugins/blob/master/jsonlog/jsonlog.c) as a basis for how to serialize the log messages. Thanks to both of them because this wouldn't be possible without that starting point. The first commit splits out the destination in log pipe messages into its own field. Previously it would piggyback on the "is_last" field. This adds an int to the message size but makes the rest of the code easier to follow. The second commit adds a TAP test for log_destination "csvlog". This was done to both confirm that the previous change didn't break anything and as a skeleton for the test in the next commit. The third commit adds the new log_destination "jsonlog". The output format is one line per entry with the top level output being a JSON object keyed with the log fields. Newlines in the output fields are escaped as \n so the output file has exactly one line per log entry. It also includes a new test for verifying the JSON output with some basic regex checks (similar to the csvlog test). Here's a sample of what the log entries look like: {"timestamp":"2021-08-31 10:15:25.129 EDT","user":"sehrope","dbname":"postgres","pid":12012,"remote_host":"[local]","session_id":"612e397d.2eec","line_num":1,"ps":"idle","session_start":"2021-08-31 10:15:25 EDT","vxid":"3/2","txid":"0","error_severity":"LOG","application_name":" 006_jsonlog.pl","message":"statement: SELECT 1/0"} It builds and passes "make check-world" on Linux. It also includes code to handle Windows as well but I have not actually tried building it there. Regards, -- Sehrope Sarkuni Founder & CEO | JackDB, Inc. | https://www.jackdb.com/
复制
期望 PostgreSQL 增加什么功能?
PolarDB for PostgreSQL云原生分布式开源数据库
PostgreSQL 解决方案集合
德哥 / digoal's github - 公益是一辈子的事.
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
外国CTO也感兴趣的开源数据库项目——openHalo
小满未满、
502次阅读
2025-04-21 16:58:09
9.9 分高危漏洞,尽快升级到 pgAdmin 4 v9.2 进行修复
严少安
357次阅读
2025-04-11 10:43:23
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
337次阅读
2025-04-15 14:48:05
openHalo问世,全球首款基于PostgreSQL兼容MySQL协议的国产开源数据库
严少安
311次阅读
2025-04-07 12:14:29
转发有奖 | PostgreSQL 16 PGCM高级认证课程直播班招生中!
墨天轮小教习
152次阅读
2025-04-14 15:58:34
墨天轮PostgreSQL认证证书快递已发(2025年3月批)
墨天轮小教习
131次阅读
2025-04-03 11:43:25
SQL 优化之 OR 子句改写
xiongcc
95次阅读
2025-04-21 00:08:06
融合Redis缓存的PostgreSQL高可用架构
梧桐
90次阅读
2025-04-08 06:35:40
PostgreSQL拓展PGQ实现解析
chirpyli
87次阅读
2025-04-07 11:23:17
Mysql/Oracle/Postgresql快速批量生成百万级测试数据sql
hongg
75次阅读
2025-04-07 15:32:54
热门文章
阿里巴巴的使命、愿景、核心价值观
2021-01-04 67688浏览
MacOS 关闭和开启虚拟内存(swap)
2022-01-20 17768浏览
[珍藏级] PostgreSQL ssl 证书配置 - 防止中间攻击者 - 以及如何使用证书无密码登录配置cert
2020-06-19 16526浏览
PostgreSQL md5hash插件 - 128bit 存储,压缩空间、提升效率
2019-11-08 14356浏览
产品与运营-OKR的设计、总结、复盘、规划、组织保障和考核例子
2022-01-20 13249浏览
最新文章
PostgreSQL 15 preview - PostgreSQL 15 pg_stat_statements 增加对temp file blocks io timing的统计, 增加JIT的统计.
2022-01-20 270浏览
德说-第92期, 怎么解决躺平|不想奋斗?
2022-01-20 301浏览
PostgreSQL 增量物化视图插件 - pg_ivm incremental materialized view maintenance
2022-01-20 1397浏览
PostgreSQL 15 preview - ARM多核适配 性能提升 - Use ISB as a spin-delay instruction on ARM64
2022-01-20 784浏览
PostgreSQL 15 preview - recovery(包括崩溃恢复、逻辑流复制、物理流复制、归档恢复) 加速, 支持异步prefetch 预读接下来要恢复的wal record相关的data block到shared buffer
2022-01-20 1210浏览