PostgreSQL 格式化日志输出
PostgreSQL stderr日志记录,修改postgresql.cfg中的log_line_prefix:
log_line_prefix = '%m [pid=%p] %q[txid=%x] %u@%d '
-- 输出结果如下
2024-06-20 17:17:52.988 CEST [pid=19718] [txid=0] dbausers@test LOG: statement: INSERT INTO child VALUES (100, 1, 'new child');
2024-06-20 17:17:58.215 CEST [pid=19674] [txid=0] dbausers@test LOG: statement: BEGIN;
2024-06-20 17:18:03.626 CEST [pid=19674] [txid=0] dbausers@test LOG: statement: INSERT INTO child VALUES (101, 1, 'another child');
2024-06-20 17:18:18.979 CEST [pid=19674] [txid=1108] dbausers@test LOG: statement: SELECT pdata FROM parent WHERE pid = 1 FOR UPDATE;
2024-06-20 17:18:31.550 CEST [pid=19718] [txid=1109] dbausers@test LOG: statement: SELECT pdata FROM parent WHERE pid = 1 FOR UPDATE;
2024-06-20 17:18:32.551 CEST [pid=19718] [txid=1109] dbausers@test ERROR: deadlock detected
2024-06-20 17:18:32.551 CEST [pid=19718] [txid=1109] dbausers@test DETAIL: Process 19718 waits for ShareLock on transaction 1108; blocked by process 19674.
Process 19674 waits for ShareLock on transaction 1109; blocked by process 19718.
Process 19718: SELECT pdata FROM parent WHERE pid = 1 FOR UPDATE;
Process 19674: SELECT pdata FROM parent WHERE pid = 1 FOR UPDATE;