Skip to content

Commit 26c467d

Browse files
committed
[formats] improvements for postgres
testing with logs from pgbadger
1 parent aac22f2 commit 26c467d

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

src/formats/postgres_log.json

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
"description": "Format for PostgreSQL logs",
66
"regex": {
77
"std": {
8-
"pattern": "^(?<timestamp>^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})? \\S+) \\[(?<pid>[\\d\\-]+)\\](?<host>\\s+\\[[^\\]]+\\])?(?:\\s+(?<user>[^@]+)@(?<db_name>\\S+))? (?<level>DEBUG\\d?|DETAIL|CONTEXT|INFO|NOTICE|WARNING|ERROR|LOG|FATAL|PANIC|STATEMENT): *(?<body>.*)$"
8+
"pattern": "^(?<timestamp>^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})? \\S+) \\[(?<pid>[\\d\\-]+)\\](?:\\s+\\[queryid=(?<query_id>[^\\]]+)\\])?(?:\\s+\\[(?<host>[a-zA-Z0-9-\\.]+)\\])?(?:\\s+(?<user>[^@ ]+)@(?<db_name>\\S+))? (?<level>DEBUG\\d?|DETAIL|HINT|CONTEXT|INFO|NOTICE|WARNING|ERROR|LOG|FATAL|PANIC|STATEMENT): *(?:duration: (?<duration>\\d+\\.\\d+ [^ ]+))? *(?<body>.*)$"
9+
},
10+
"kvp1": {
11+
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?\\s[^ ]+) \\[(?<pid>\\d+)\\]:? db=(?<db_name>[^,]*),user=(?<user>[^,]*),app=(?<app>[^,]*),client=(?<client>[^ ]*) (?<level>DEBUG\\d?|DETAIL|HINT|CONTEXT|INFO|NOTICE|WARNING|ERROR|LOG|FATAL|PANIC|STATEMENT): *(?:duration: (?<duration>\\d+\\.\\d+ [^ ]+))? *(?<body>.*)$"
12+
},
13+
"kvp2": {
14+
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?\\s[^ ]+) \\[(?<pid>\\d+)\\]:?(?: \\[(?<session_line>\\d+)-1\\])? user=(?<user>[^,]*),db=(?<db_name>[^, ]*)(?:,app=(?<app>[^,]*),client=(?<client>[^ ]*))? (?<level>DEBUG\\d?|DETAIL|HINT|CONTEXT|INFO|NOTICE|WARNING|ERROR|LOG|FATAL|PANIC|STATEMENT): *(?:duration: (?<duration>\\d+\\.\\d+ [^ ]+))? *(?<body>.*)$"
15+
},
16+
"rds": {
17+
"pattern": "^(?<timestamp>^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})? [^:]+):(?<client>[^:]*):(?<user>[^@]*)@(?<db_name>[^:]*):\\[(?<pid>\\d+)\\]:(?<level>DEBUG\\d?|DETAIL|HINT|CONTEXT|INFO|NOTICE|WARNING|ERROR|LOG|FATAL|PANIC|STATEMENT): *(?:duration: (?<duration>\\d+\\.\\d+ [^ ]+))? *(?<body>.*)$"
918
}
1019
},
1120
"value": {
@@ -28,8 +37,27 @@
2837
"kind": "string",
2938
"identifier": true
3039
},
40+
"app": {
41+
"kind": "string",
42+
"identifier": true
43+
},
44+
"client": {
45+
"kind": "string",
46+
"identifier": true
47+
},
48+
"session_line": {
49+
"kind": "string"
50+
},
51+
"duration": {
52+
"kind": "string",
53+
"collate": "measure_with_units"
54+
},
3155
"timestamp": {
3256
"kind": "string"
57+
},
58+
"query_id": {
59+
"kind": "string",
60+
"identifier": true
3361
}
3462
},
3563
"sample": [
@@ -38,6 +66,27 @@
3866
},
3967
{
4068
"line": "2025-06-05 17:10:04 MSK [608647-3] [local] postgres@postgres WARNING: terminating connection because of crash of another server process"
69+
},
70+
{
71+
"line": "2021-02-14 01:34:02 CET [30291]: db=[unknown],user=[unknown],app=[unknown],client=[local] LOG: connection received: host=[local]"
72+
},
73+
{
74+
"line": "2017-09-06 08:40:10 UTC [20]: [1-1] user=,db=,app=,client= LOG: database system was shut down at 2017-09-06 08:40:08 UTC"
75+
},
76+
{
77+
"line": "2017-09-06 08:41:43 UTC [44]: [371-1] user=postgres,db=postgres,app=pgbench,client=172.23.0.1 LOG: duration: 59.911 ms statement: UPDATE pgbench_branches SET bbalance = bbalance + 4597 WHERE bid = 1;"
78+
},
79+
{
80+
"line": "2021-12-03 07:14:48.591 UTC [4913] user=user1,db=mydb LOG: duration: 0.211 ms statement: SELECT current_setting('nj.maint')"
81+
},
82+
{
83+
"line": "2022-02-17 06:45:10.440 -0800 [691] [queryid=1081270519976314062] postgres@stackoverflow LOG: duration: 0.140 ms statement: set log_min_duration_statement to 0;"
84+
},
85+
{
86+
"line": "2020-03-11 20:40:45 CET:[local]:postgres@template1:[12777]:LOG: duration: 0.038 ms statement: "
87+
},
88+
{
89+
"line": "2020-03-11 20:40:43 CET::@:[12760]:LOG: starting PostgreSQL 12.2 (Ubuntu 12.2-2.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit"
4190
}
4291
]
4392
}

0 commit comments

Comments
 (0)