PostgreSQL的WAL日志解析工具pg_waldump 浅谈

PostgreSQL 10.x 常用工具(一)

  • pg_waldump 介绍
把PG数据库集群的 wal 日志翻译成人为可阅读的信息,该工具要求访问数据库 data 目录权限,主要用于展示和debug的目的。

当服务器正在运行时可能会给出错误的结果。

只有指定的时间线 会被显示(如果没有指定,则显示默认时间线)。 其他时间线上的记录会被忽略。

pg_xlogdump不能读取具有后缀.partial 的 WAL 文件。如果需要读取那些文件,需要从文件名中移除 .partial后缀
  • 参数介绍
postgres@CLW-DB4:/pgdata/10/data/pg_wal> pg_waldump --help
pg_waldump decodes and displays PostgreSQL write-ahead logs for debugging.

Usage:
  pg_waldump [OPTION]... [STARTSEG [ENDSEG]]

STARTSEG    从指定的日志段文件开始读取。这也隐含地决定了要搜索文件的路径以及 要使用的时间线。
ENDSEG      在读取指定的日志段文件后停止。
Options:
  -b, --bkp-details      输出有关备份块的细节。
  -e, --end=RECPTR       在指定的日志位置停止读取,而不是一直读取到日志流的末尾。
  -f, --follow           在到达可用 WAL 的末尾之后,保持每秒轮询一次是否有新的 WAL 出现。
  -n, --limit=N          显示指定数量的记录,然后停止。
  -p, --path=PATH        要在哪个目录中寻找日志段文件。默认是在当前目录的pg_xlog 子目录中搜索。
  -r, --rmgr=RMGR        只显示由指定资源管理器生成的记录。如果把list作为资源管理器名称 传递给这个选项,则打印出可用资源管理器名称的列表然后退出。
  -s, --start=RECPTR     要从哪个日志位置开始读取。默认是从找到的最早的文件的第一个可用日志记录开始。
  -t, --timeline=TLI     要从哪个时间线读取日志记录。默认是使用startseg(如果指定) 中的值,否则默认为 1
  -V, --version          打印pg_xlogdump版本并且退出。
  -x, --xid=XID         只显示用给定事务 ID 标记的记录。
  -z, --stats[=record]   显示概括统计信息(记录的数量和尺寸以及全页镜像)而不是显示 每个记录。可以选择针对每个记录生成统计信息,而不是针对每个 资源管理器生成。
  -?, --help             show this help, then exit
  • 展示 wal 中所有的资源管理名称
postgres@CLW-DB4:/pgdata/10/data/pg_wal> pg_waldump --rmgr=list
XLOG
Transaction
Storage
CLOG
Database
Tablespace
MultiXact
RelMap
Standby
Heap2
Heap
Btree
Hash
Gin
Gist
Sequence
SPGist
BRIN
CommitTs
ReplicationOrigin
Generic
LogicalMessage
postgres@CLW-DB4:/pgdata/10/data/pg_wal>
  • 展示 STARTSEGENDSEG 的事务日志
[postgres@pg4 pg_wal]$ pg_waldump 000000010000000000000001 000000010000000000000002

...
rmgr: XLOG        len (rec/tot):    106/   106, tx:        553, lsn: 0/0162C8A8, prev 0/0162C870, desc: CHECKPOINT_ONLINE redo 0/162C870; tli 1; prev tli 1; fpw true; xid 0:554; oid 19719; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 553; online
rmgr: Transaction len (rec/tot):     66/    66, tx:        553, lsn: 0/0162C918, prev 0/0162C8A8, desc: COMMIT 2018-06-26 09:23:05.669905 CST; inval msgs: catcache 21; sync
rmgr: Heap        len (rec/tot):     54/   306, tx:        554, lsn: 0/0162C960, prev 0/0162C918, desc: INSERT off 3, blkref #0: rel 1664/0/2396 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/   153, tx:        554, lsn: 0/0162CA98, prev 0/0162C960, desc: INSERT_LEAF off 3, blkref #0: rel 1664/0/2397 blk 1 FPW
rmgr: Transaction len (rec/tot):     66/    66, tx:        554, lsn: 0/0162CB38, prev 0/0162CA98, desc: COMMIT 2018-06-26 09:23:05.670051 CST; inval msgs: snapshot 2396
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/0162CB80, prev 0/0162CB38, desc: CHECKPOINT_SHUTDOWN redo 0/162CB80; tli 1; prev tli 1; fpw true; xid 0:555; oid 13213; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 0; shutdown
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0162CBF0, prev 0/0162CB80, desc: RUNNING_XACTS nextXid 555 latestCompletedXid 554 oldestRunningXid 555
rmgr: Heap        len (rec/tot):     65/   933, tx:        555, lsn: 0/0162CC28, prev 0/0162CBF0, desc: HOT_UPDATE off 1 xmax 555 ; new off 7 xmax 0, blkref #0: rel 1664/0/1260 blk 0 FPW
rmgr: Transaction len (rec/tot):     82/    82, tx:        555, lsn: 0/0162CFD0, prev 0/0162CC28, desc: COMMIT 2018-06-26 09:39:33.629535 CST; inval msgs: catcache 11 catcache 10
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0162D028, prev 0/0162CFD0, desc: RUNNING_XACTS nextXid 556 latestCompletedXid 555 oldestRunningXid 556
rmgr: XLOG        len (rec/tot):     30/    30, tx:        556, lsn: 0/0162D060, prev 0/0162D028, desc: NEXTOID 24576
rmgr: Heap        len (rec/tot):    175/   175, tx:        556, lsn: 0/0162D080, prev 0/0162D060, desc: INSERT off 8, blkref #0: rel 1664/0/1260 blk 0
rmgr: Btree       len (rec/tot):     53/   313, tx:        556, lsn: 0/0162D130, prev 0/0162D080, desc: INSERT_LEAF off 7, blkref #0: rel 1664/0/2676 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/   233, tx:        556, lsn: 0/0162D270, prev 0/0162D130, desc: INSERT_LEAF off 7, blkref #0: rel 1664/0/2677 blk 1 FPW
rmgr: Transaction len (rec/tot):     82/    82, tx:        556, lsn: 0/0162D360, prev 0/0162D270, desc: COMMIT 2018-06-26 09:40:04.292064 CST; inval msgs: catcache 11 catcache 10
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0162D3B8, prev 0/0162D360, desc: RUNNING_XACTS nextXid 557 latestCompletedXid 556 oldestRunningXid 557
rmgr: Heap        len (rec/tot):     54/  1222, tx:        557, lsn: 0/0162D3F0, prev 0/0162D3B8, desc: INSERT off 4, blkref #0: rel 1664/0/1262 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/   197, tx:        557, lsn: 0/0162D8B8, prev 0/0162D3F0, desc: INSERT_LEAF off 4, blkref #0: rel 1664/0/2671 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/   173, tx:        557, lsn: 0/0162D980, prev 0/0162D8B8, desc: INSERT_LEAF off 4, blkref #0: rel 1664/0/2672 blk 1 FPW
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/0162DA30, prev 0/0162D980, desc: RUNNING_XACTS nextXid 558 latestCompletedXid 556 oldestRunningXid 557; 1 xacts: 557
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/0162DA68, prev 0/0162DA30, desc: CHECKPOINT_ONLINE redo 0/162DA30; tli 1; prev tli 1; fpw true; xid 0:558; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 557; online
rmgr: Database    len (rec/tot):     42/    42, tx:        557, lsn: 0/0162DAD8, prev 0/0162DA68, desc: CREATE copy dir 1/1663 to 16385/1663
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/0162DB08, prev 0/0162DAD8, desc: RUNNING_XACTS nextXid 558 latestCompletedXid 556 oldestRunningXid 557; 1 xacts: 557
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/0162DB40, prev 0/0162DB08, desc: CHECKPOINT_ONLINE redo 0/162DB08; tli 1; prev tli 1; fpw true; xid 0:558; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 557; online
rmgr: Transaction len (rec/tot):     66/    66, tx:        557, lsn: 0/0162DBB0, prev 0/0162DB40, desc: COMMIT 2018-06-26 09:40:16.669647 CST; inval msgs: catcache 21; sync
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0162DBF8, prev 0/0162DBB0, desc: RUNNING_XACTS nextXid 558 latestCompletedXid 557 oldestRunningXid 558
rmgr: Storage     len (rec/tot):     42/    42, tx:          0, lsn: 0/0162DC30, prev 0/0162DBF8, desc: CREATE base/16385/16386
rmgr: Heap        len (rec/tot):     54/  7550, tx:        558, lsn: 0/0162DC60, prev 0/0162DC30, desc: INSERT off 27, blkref #0: rel 1663/16385/1247 blk 6 FPW
rmgr: Btree       len (rec/tot):     53/  7613, tx:        558, lsn: 0/0162F9F8, prev 0/0162DC60, desc: INSERT_LEAF off 376, blkref #0: rel 1663/16385/2703 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/  2149, tx:        558, lsn: 0/016317D0, prev 0/0162F9F8, desc: INSERT_LEAF off 48, blkref #0: rel 1663/16385/2704 blk 2 FPW
rmgr: Heap        len (rec/tot):     54/  7622, tx:        558, lsn: 0/01632050, prev 0/016317D0, desc: INSERT off 92, blkref #0: rel 1663/16385/2608 blk 43 FPW
rmgr: Btree       len (rec/tot):     53/  5301, tx:        558, lsn: 0/01633E18, prev 0/01632050, desc: INSERT_LEAF off 72, blkref #0: rel 1663/16385/2673 blk 33 FPW
rmgr: Btree       len (rec/tot):     53/  6813, tx:        558, lsn: 0/016352E8, prev 0/01633E18, desc: INSERT_LEAF off 134, blkref #0: rel 1663/16385/2674 blk 45 FPW
rmgr: Heap        len (rec/tot):    203/   203, tx:        558, lsn: 0/01636DA0, prev 0/016352E8, desc: INSERT off 28, blkref #0: rel 1663/16385/1247 blk 6
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01636E70, prev 0/01636DA0, desc: INSERT_LEAF off 376, blkref #0: rel 1663/16385/2703 blk 1
rmgr: Btree       len (rec/tot):     53/  5413, tx:        558, lsn: 0/01636EB0, prev 0/01636E70, desc: INSERT_LEAF off 72, blkref #0: rel 1663/16385/2704 blk 1 FPW
rmgr: Heap        len (rec/tot):     80/    80, tx:        558, lsn: 0/016383F0, prev 0/01636EB0, desc: INSERT off 93, blkref #0: rel 1663/16385/2608 blk 43
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01638440, prev 0/016383F0, desc: INSERT_LEAF off 72, blkref #0: rel 1663/16385/2673 blk 33
rmgr: Btree       len (rec/tot):     53/  8241, tx:        558, lsn: 0/01638488, prev 0/01638440, desc: INSERT_LEAF off 154, blkref #0: rel 1663/16385/2674 blk 39 FPW
rmgr: Heap        len (rec/tot):     54/   866, tx:        558, lsn: 0/0163A4D8, prev 0/01638488, desc: INSERT off 2, blkref #0: rel 1663/16385/1259 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/  1733, tx:        558, lsn: 0/0163A840, prev 0/0163A4D8, desc: INSERT_LEAF off 82, blkref #0: rel 1663/16385/2662 blk 2 FPW
rmgr: Btree       len (rec/tot):     53/  2281, tx:        558, lsn: 0/0163AF08, prev 0/0163A840, desc: INSERT_LEAF off 50, blkref #0: rel 1663/16385/2663 blk 2 FPW
rmgr: Btree       len (rec/tot):     53/  3413, tx:        558, lsn: 0/0163B7F8, prev 0/0163AF08, desc: INSERT_LEAF off 162, blkref #0: rel 1663/16385/3455 blk 4 FPW
rmgr: Heap        len (rec/tot):     54/  7498, tx:        558, lsn: 0/0163C568, prev 0/0163B7F8, desc: INSERT off 22, blkref #0: rel 1663/16385/1249 blk 16 FPW
rmgr: Btree       len (rec/tot):     53/  7633, tx:        558, lsn: 0/0163E2D0, prev 0/0163C568, desc: INSERT_LEAF off 209, blkref #0: rel 1663/16385/2658 blk 12 FPW
rmgr: Btree       len (rec/tot):     53/  1273, tx:        558, lsn: 0/016400C0, prev 0/0163E2D0, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9 FPW
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/016405C0, prev 0/016400C0, desc: INSERT off 23, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01640670, prev 0/016405C0, desc: INSERT_LEAF off 209, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/016406B0, prev 0/01640670, desc: INSERT_LEAF off 60, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/016406F0, prev 0/016406B0, desc: INSERT off 24, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/016407A0, prev 0/016406F0, desc: INSERT_LEAF off 211, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/016407E8, prev 0/016407A0, desc: INSERT_LEAF off 61, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/01640828, prev 0/016407E8, desc: INSERT off 25, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/016408D8, prev 0/01640828, desc: INSERT_LEAF off 210, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01640920, prev 0/016408D8, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/01640960, prev 0/01640920, desc: INSERT off 27, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01640A10, prev 0/01640960, desc: INSERT_LEAF off 213, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01640A58, prev 0/01640A10, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/01640A98, prev 0/01640A58, desc: INSERT off 29, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01640B48, prev 0/01640A98, desc: INSERT_LEAF off 210, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01640B90, prev 0/01640B48, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):     54/  5378, tx:        558, lsn: 0/01640BD0, prev 0/01640B90, desc: INSERT off 34, blkref #0: rel 1663/16385/1249 blk 32 FPW
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/016420F0, prev 0/01640BD0, desc: INSERT_LEAF off 214, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01642138, prev 0/016420F0, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/01642178, prev 0/01642138, desc: INSERT off 35, blkref #0: rel 1663/16385/1249 blk 32
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01642228, prev 0/01642178, desc: INSERT_LEAF off 210, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01642270, prev 0/01642228, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/016422B0, prev 0/01642270, desc: INSERT off 36, blkref #0: rel 1663/16385/1249 blk 32
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01642360, prev 0/016422B0, desc: INSERT_LEAF off 215, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/016423A8, prev 0/01642360, desc: INSERT_LEAF off 59, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):     80/    80, tx:        558, lsn: 0/016423E8, prev 0/016423A8, desc: INSERT off 94, blkref #0: rel 1663/16385/2608 blk 43
rmgr: Btree       len (rec/tot):     53/  6897, tx:        558, lsn: 0/01642438, prev 0/016423E8, desc: INSERT_LEAF off 240, blkref #0: rel 1663/16385/2673 blk 38 FPW
rmgr: Btree       len (rec/tot):     53/  5441, tx:        558, lsn: 0/01643F30, prev 0/01642438, desc: INSERT_LEAF off 120, blkref #0: rel 1663/16385/2674 blk 26 FPW
rmgr: Standby     len (rec/tot):     42/    42, tx:        558, lsn: 0/01645490, prev 0/01643F30, desc: LOCK xid 558 db 16385 rel 16386
rmgr: Heap        len (rec/tot):    375/   375, tx:        558, lsn: 0/016454C0, prev 0/01645490, desc: INSERT+INIT off 1, blkref #0: rel 1663/16385/2604 blk 0
rmgr: Btree       len (rec/tot):     78/    78, tx:        558, lsn: 0/01645638, prev 0/016454C0, desc: NEWROOT lev 0, blkref #0: rel 1663/16385/2656 blk 1, blkref #2: rel 1663/16385/2656 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645688, prev 0/01645638, desc: INSERT_LEAF off 1, blkref #0: rel 1663/16385/2656 blk 1
rmgr: Btree       len (rec/tot):     78/    78, tx:        558, lsn: 0/016456C8, prev 0/01645688, desc: NEWROOT lev 0, blkref #0: rel 1663/16385/2657 blk 1, blkref #2: rel 1663/16385/2657 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645718, prev 0/016456C8, desc: INSERT_LEAF off 1, blkref #0: rel 1663/16385/2657 blk 1
rmgr: Heap        len (rec/tot):     54/    54, tx:        558, lsn: 0/01645758, prev 0/01645718, desc: LOCK off 24: xid 558: flags 0 LOCK_ONLY EXCL_LOCK , blkref #0: rel 1663/16385/1249 blk 16
rmgr: Heap        len (rec/tot):    190/   190, tx:        558, lsn: 0/01645790, prev 0/01645758, desc: UPDATE off 24 xmax 558 ; new off 37 xmax 0, blkref #0: rel 1663/16385/1249 blk 32, blkref #1: rel 1663/16385/1249 blk 16
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01645850, prev 0/01645790, desc: INSERT_LEAF off 214, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645898, prev 0/01645850, desc: INSERT_LEAF off 67, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):     80/    80, tx:        558, lsn: 0/016458D8, prev 0/01645898, desc: INSERT off 95, blkref #0: rel 1663/16385/2608 blk 43
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01645928, prev 0/016458D8, desc: INSERT_LEAF off 241, blkref #0: rel 1663/16385/2673 blk 38
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01645970, prev 0/01645928, desc: INSERT_LEAF off 135, blkref #0: rel 1663/16385/2674 blk 45
rmgr: Storage     len (rec/tot):     42/    42, tx:        558, lsn: 0/016459B8, prev 0/01645970, desc: CREATE base/16385/16390
rmgr: Standby     len (rec/tot):     42/    42, tx:        558, lsn: 0/016459E8, prev 0/016459B8, desc: LOCK xid 558 db 16385 rel 16390
rmgr: Heap        len (rec/tot):    199/   199, tx:        558, lsn: 0/01645A18, prev 0/016459E8, desc: INSERT off 3, blkref #0: rel 1663/16385/1259 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645AE0, prev 0/01645A18, desc: INSERT_LEAF off 83, blkref #0: rel 1663/16385/2662 blk 2
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01645B20, prev 0/01645AE0, desc: INSERT_LEAF off 51, blkref #0: rel 1663/16385/2663 blk 2
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645B68, prev 0/01645B20, desc: INSERT_LEAF off 163, blkref #0: rel 1663/16385/3455 blk 4
rmgr: Heap        len (rec/tot):    171/   171, tx:        558, lsn: 0/01645BA8, prev 0/01645B68, desc: INSERT off 38, blkref #0: rel 1663/16385/1249 blk 32
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645C58, prev 0/01645BA8, desc: INSERT_LEAF off 219, blkref #0: rel 1663/16385/2658 blk 12
rmgr: Btree       len (rec/tot):     64/    64, tx:        558, lsn: 0/01645C98, prev 0/01645C58, desc: INSERT_LEAF off 69, blkref #0: rel 1663/16385/2659 blk 9
rmgr: Heap        len (rec/tot):     54/  8062, tx:        558, lsn: 0/01645CD8, prev 0/01645C98, desc: INSERT off 38, blkref #0: rel 1663/16385/2610 blk 2 FPW
rmgr: Btree       len (rec/tot):     53/  2793, tx:        558, lsn: 0/01647C70, prev 0/01645CD8, desc: INSERT_LEAF off 135, blkref #0: rel 1663/16385/2678 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/  2793, tx:        558, lsn: 0/01648778, prev 0/01647C70, desc: INSERT_LEAF off 135, blkref #0: rel 1663/16385/2679 blk 1 FPW
rmgr: Heap        len (rec/tot):     54/  1778, tx:        558, lsn: 0/01649268, prev 0/01648778, desc: INSERT off 3, blkref #0: rel 1663/16385/2606 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/   209, tx:        558, lsn: 0/01649960, prev 0/01649268, desc: INSERT_LEAF off 2, blkref #0: rel 1663/16385/2664 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/   153, tx:        558, lsn: 0/01649A38, prev 0/01649960, desc: INSERT_LEAF off 3, blkref #0: rel 1663/16385/2665 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/   153, tx:        558, lsn: 0/01649AD8, prev 0/01649A38, desc: INSERT_LEAF off 1, blkref #0: rel 1663/16385/2666 blk 1 FPW
rmgr: Btree       len (rec/tot):     53/   153, tx:        558, lsn: 0/01649B78, prev 0/01649AD8, desc: INSERT_LEAF off 3, blkref #0: rel 1663/16385/2667 blk 1 FPW
rmgr: Heap        len (rec/tot):     80/    80, tx:        558, lsn: 0/01649C18, prev 0/01649B78, desc: INSERT off 96, blkref #0: rel 1663/16385/2608 blk 43
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01649C68, prev 0/01649C18, desc: INSERT_LEAF off 244, blkref #0: rel 1663/16385/2673 blk 38
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01649CB0, prev 0/01649C68, desc: INSERT_LEAF off 135, blkref #0: rel 1663/16385/2674 blk 45
rmgr: Heap        len (rec/tot):     80/    80, tx:        558, lsn: 0/01649CF8, prev 0/01649CB0, desc: INSERT off 97, blkref #0: rel 1663/16385/2608 blk 43
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01649D48, prev 0/01649CF8, desc: INSERT_LEAF off 241, blkref #0: rel 1663/16385/2673 blk 38
rmgr: Btree       len (rec/tot):     72/    72, tx:        558, lsn: 0/01649D90, prev 0/01649D48, desc: INSERT_LEAF off 115, blkref #0: rel 1663/16385/2674 blk 26
rmgr: XLOG        len (rec/tot):     49/   113, tx:        558, lsn: 0/01649DD8, prev 0/01649D90, desc: FPI , blkref #0: rel 1663/16385/16390 blk 0 FPW
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/01649E50, prev 0/01649DD8, desc: LOCK xid 558 db 16385 rel 16386 xid 558 db 16385 rel 16390
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/01649E88, prev 0/01649E50, desc: RUNNING_XACTS nextXid 559 latestCompletedXid 557 oldestRunningXid 558; 1 xacts: 558
rmgr: Heap        len (rec/tot):    184/   184, tx:        558, lsn: 0/01649EC0, prev 0/01649E88, desc: INPLACE off 2, blkref #0: rel 1663/16385/1259 blk 0
rmgr: Heap        len (rec/tot):    184/   184, tx:        558, lsn: 0/01649F78, prev 0/01649EC0, desc: INPLACE off 3, blkref #0: rel 1663/16385/1259 blk 0
rmgr: Transaction len (rec/tot):    757/   757, tx:        558, lsn: 0/0164A048, prev 0/01649F78, desc: COMMIT 2018-06-26 09:41:29.781733 CST; inval msgs: catcache 50 catcache 49 catcache 50 catcache 49 catcache 50 catcache 49 catcache 7 catcache 6 catcache 32 catcache 19 catcache 7 catcache 6 catcache 74 catcache 73 catcache 74 catcache 73 catcache 50 catcache 49 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 catcache 7 catcache 6 relcache 16386 relcache 16390 relcache 16390 snapshot 2608 relcache 16386 snapshot 2608 snapshot 2608 relcache 16386
rmgr: Heap2       len (rec/tot):     56/    56, tx:          0, lsn: 0/0164A340, prev 0/0164A048, desc: CLEAN remxid 0, blkref #0: rel 1663/16385/1249 blk 16
rmgr: Heap        len (rec/tot):     79/    79, tx:        559, lsn: 0/0164A378, prev 0/0164A340, desc: INSERT+INIT off 1, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     78/    78, tx:        559, lsn: 0/0164A3C8, prev 0/0164A378, desc: NEWROOT lev 0, blkref #0: rel 1663/16385/16390 blk 1, blkref #2: rel 1663/16385/16390 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        559, lsn: 0/0164A418, prev 0/0164A3C8, desc: INSERT_LEAF off 1, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        559, lsn: 0/0164A458, prev 0/0164A418, desc: COMMIT 2018-06-26 09:41:42.961867 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0164A480, prev 0/0164A458, desc: RUNNING_XACTS nextXid 560 latestCompletedXid 559 oldestRunningXid 560
rmgr: Heap        len (rec/tot):     79/    79, tx:        560, lsn: 0/0164A4B8, prev 0/0164A480, desc: INSERT off 2, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        560, lsn: 0/0164A508, prev 0/0164A4B8, desc: INSERT_LEAF off 2, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        560, lsn: 0/0164A548, prev 0/0164A508, desc: COMMIT 2018-06-26 09:44:25.649393 CST
rmgr: Heap        len (rec/tot):     79/    79, tx:        561, lsn: 0/0164A570, prev 0/0164A548, desc: INSERT off 3, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        561, lsn: 0/0164A5C0, prev 0/0164A570, desc: INSERT_LEAF off 3, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        561, lsn: 0/0164A600, prev 0/0164A5C0, desc: COMMIT 2018-06-26 09:44:25.652326 CST
rmgr: Heap        len (rec/tot):     79/    79, tx:        562, lsn: 0/0164A628, prev 0/0164A600, desc: INSERT off 4, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        562, lsn: 0/0164A678, prev 0/0164A628, desc: INSERT_LEAF off 4, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        562, lsn: 0/0164A6B8, prev 0/0164A678, desc: COMMIT 2018-06-26 09:44:25.653694 CST
rmgr: Heap        len (rec/tot):     79/    79, tx:        563, lsn: 0/0164A6E0, prev 0/0164A6B8, desc: INSERT off 5, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        563, lsn: 0/0164A730, prev 0/0164A6E0, desc: INSERT_LEAF off 5, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        563, lsn: 0/0164A770, prev 0/0164A730, desc: COMMIT 2018-06-26 09:44:25.654917 CST
rmgr: Heap        len (rec/tot):     79/    79, tx:        564, lsn: 0/0164A798, prev 0/0164A770, desc: INSERT off 6, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        564, lsn: 0/0164A7E8, prev 0/0164A798, desc: INSERT_LEAF off 6, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        564, lsn: 0/0164A828, prev 0/0164A7E8, desc: COMMIT 2018-06-26 09:44:25.655734 CST
rmgr: Heap        len (rec/tot):     79/    79, tx:        565, lsn: 0/0164A850, prev 0/0164A828, desc: INSERT off 7, blkref #0: rel 1663/16385/16386 blk 0
rmgr: Btree       len (rec/tot):     64/    64, tx:        565, lsn: 0/0164A8A0, prev 0/0164A850, desc: INSERT_LEAF off 7, blkref #0: rel 1663/16385/16390 blk 1
rmgr: Transaction len (rec/tot):     34/    34, tx:        565, lsn: 0/0164A8E0, prev 0/0164A8A0, desc: COMMIT 2018-06-26 09:44:25.656608 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0164A908, prev 0/0164A8E0, desc: RUNNING_XACTS nextXid 566 latestCompletedXid 565 oldestRunningXid 566
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0164A940, prev 0/0164A908, desc: RUNNING_XACTS nextXid 566 latestCompletedXid 565 oldestRunningXid 566
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/0164A978, prev 0/0164A940, desc: CHECKPOINT_ONLINE redo 0/164A940; tli 1; prev tli 1; fpw true; xid 0:566; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 566; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0164A9E8, prev 0/0164A978, desc: RUNNING_XACTS nextXid 566 latestCompletedXid 565 oldestRunningXid 566
rmgr: Heap        len (rec/tot):     54/   494, tx:        566, lsn: 0/0164AA20, prev 0/0164A9E8, desc: INSERT off 8, blkref #0: rel 1663/16385/16386 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/   253, tx:        566, lsn: 0/0164AC10, prev 0/0164AA20, desc: INSERT_LEAF off 8, blkref #0: rel 1663/16385/16390 blk 1 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        566, lsn: 0/0164AD10, prev 0/0164AC10, desc: COMMIT 2018-06-26 15:18:04.789695 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/0164AD38, prev 0/0164AD10, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: XLOG        len (rec/tot):     24/    24, tx:          0, lsn: 0/0164AD70, prev 0/0164AD38, desc: SWITCH
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000028, prev 0/0164AD70, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000060, prev 0/02000028, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000098, prev 0/02000060, desc: CHECKPOINT_ONLINE redo 0/2000060; tli 1; prev tli 1; fpw true; xid 0:567; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 567; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000108, prev 0/02000098, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
pg_waldump: FATAL:  error in WAL record at 0/2000108: invalid record length at 0/2000140: wanted 24, got 0
  • 日志参数介绍
rmgr : 资源名称
lsn: 0/0162D3F0 日志编号
prev 0/0162D3B8
desc : 对日志详细信息的描述
xid 事务id
  • 连接数据库,表中插入数据
test=# insert into tt(id ,age) values (11,31);
INSERT 0 1
test=# select * from tt;
 id | age |        insert_time
----+-----+----------------------------
  1 |  11 | 2018-06-26 09:41:42.961409
  2 |  22 | 2018-06-26 09:44:25.648493
  3 |  23 | 2018-06-26 09:44:25.652257
  5 |  25 | 2018-06-26 09:44:25.653644
  7 |  27 | 2018-06-26 09:44:25.654806
  8 |  28 | 2018-06-26 09:44:25.655683
  9 |  29 | 2018-06-26 09:44:25.656561
 10 |  30 | 2018-06-26 15:18:04.788798
 11 |  31 | 2018-06-26 15:47:47.339161
(9 rows)
test=#
  • 查看此时 wal 日志,如果没有日志则通过手动切换select pg_switch_wal()
[postgres@pg4 pg_wal]$ pg_waldump 000000010000000000000002
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000028, prev 0/0164AD70, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000060, prev 0/02000028, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000098, prev 0/02000060, desc: CHECKPOINT_ONLINE redo 0/2000060; tli 1; prev tli 1; fpw true; xid 0:567; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 567; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000108, prev 0/02000098, desc: RUNNING_XACTS nextXid 567 latestCompletedXid 566 oldestRunningXid 567
rmgr: Heap        len (rec/tot):     54/   546, tx:        567, lsn: 0/02000140, prev 0/02000108, desc: INSERT off 9, blkref #0: rel 1663/16385/16386 blk 0 FPW
rmgr: Btree       len (rec/tot):     53/   273, tx:        567, lsn: 0/02000368, prev 0/02000140, desc: INSERT_LEAF off 9, blkref #0: rel 1663/16385/16390 blk 1 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        567, lsn: 0/02000480, prev 0/02000368, desc: COMMIT 2018-06-26 15:47:47.340016 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/020004A8, prev 0/02000480, desc: RUNNING_XACTS nextXid 568 latestCompletedXid 567 oldestRunningXid 568

INSERT off 9 可以看到我们刚刚执行的sql 有日志记录,并且事务的提交,COMMIT 2018-06-26 15:47:47.340016 CST 提交事务

  • 执行 update 语句
test=# update tt set age = 66 where id = 11;
UPDATE 1
test=#
  • 查看此时的日志
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/020009D8, prev 0/020009A0, desc: CHECKPOINT_ONLINE redo 0/20009A0; tli 1; prev tli 1; fpw  true; xid 0:569; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 569;  online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000A48, prev 0/020009D8, desc: RUNNING_XACTS nextXid 569 latestCompletedXid 568 oldestR unningXid 569
rmgr: Heap        len (rec/tot):     65/   661, tx:        569, lsn: 0/02000A80, prev 0/02000A48, desc: HOT_UPDATE off 9 xmax 569 ; new off 11 xmax 0, blkref #0 : rel 1663/16385/16386 blk 0 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        569, lsn: 0/02000D18, prev 0/02000A80, desc: COMMIT 2018-06-26 16:22:19.062823 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D40, prev 0/02000D18, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D78, prev 0/02000D40, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000DB0, prev 0/02000D78, desc: CHECKPOINT_ONLINE redo 0/2000D78; tli 1; prev tli 1; fpw  true; xid 0:570; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 570;  online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000E20, prev 0/02000DB0, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
pg_waldump: FATAL:  error in WAL record at 0/2000E20: invalid record length at 0/2000E58: wanted 24, got 0

发现此时 desc: HOT_UPDATE off 9 xmax 569 ; 事务日志已经写入,desc: COMMIT 2018-06-26 16:22:19.062823 CST 完成提交

  • 执行删除sql
test=# delete from tt where id = 12;
DELETE 1
test=#
  • 查看此时日志
...
rmgr: Heap        len (rec/tot):     65/   661, tx:        569, lsn: 0/02000A80, prev 0/02000A48, desc: HOT_UPDATE off 9 xmax 569 ; new off 11 xmax 0, blkref #0 : rel 1663/16385/16386 blk 0 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        569, lsn: 0/02000D18, prev 0/02000A80, desc: COMMIT 2018-06-26 16:22:19.062823 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D40, prev 0/02000D18, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D78, prev 0/02000D40, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000DB0, prev 0/02000D78, desc: CHECKPOINT_ONLINE redo 0/2000D78; tli 1; prev tli 1; fpw  true; xid 0:570; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 570;  online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000E20, prev 0/02000DB0, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestR unningXid 570
rmgr: Heap        len (rec/tot):     59/   655, tx:        570, lsn: 0/02000E58, prev 0/02000E20, desc: DELETE off 10 KEYS_UPDATED , blkref #0: rel 1663/16385/1 6386 blk 0 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        570, lsn: 0/020010E8, prev 0/02000E58, desc: COMMIT 2018-06-26 16:26:42.487533 CST
pg_waldump: FATAL:  error in WAL record at 0/20010E8: invalid record length at 0/2001110: wanted 24, got 0

发现此时desc: DELETE off 10 KEYS_UPDATED 写入日志,desc: COMMIT 2018-06-26 16:26:42.487533 CST事务提交

  • 执行查询sql
test=# select * from tt;
 id | age |        insert_time
----+-----+----------------------------
  1 |  11 | 2018-06-26 09:41:42.961409
  2 |  22 | 2018-06-26 09:44:25.648493
  3 |  23 | 2018-06-26 09:44:25.652257
  5 |  25 | 2018-06-26 09:44:25.653644
  7 |  27 | 2018-06-26 09:44:25.654806
  8 |  28 | 2018-06-26 09:44:25.655683
  9 |  29 | 2018-06-26 09:44:25.656561
 10 |  30 | 2018-06-26 15:18:04.788798
 11 |  66 | 2018-06-26 15:47:47.339161
(9 rows)

test=#
  • 查看此时日志
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000A48, prev 0/020009D8, desc: RUNNING_XACTS nextXid 569 latestCompletedXid 568 oldestRunningXid 569
rmgr: Heap        len (rec/tot):     65/   661, tx:        569, lsn: 0/02000A80, prev 0/02000A48, desc: HOT_UPDATE off 9 xmax 569 ; new off 11 xmax 0, blkref #0: rel 1663/16385/16386 blk 0 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        569, lsn: 0/02000D18, prev 0/02000A80, desc: COMMIT 2018-06-26 16:22:19.062823 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D40, prev 0/02000D18, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestRunningXid 570
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000D78, prev 0/02000D40, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestRunningXid 570
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02000DB0, prev 0/02000D78, desc: CHECKPOINT_ONLINE redo 0/2000D78; tli 1; prev tli 1; fpw true; xid 0:570; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 570; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02000E20, prev 0/02000DB0, desc: RUNNING_XACTS nextXid 570 latestCompletedXid 569 oldestRunningXid 570
rmgr: Heap        len (rec/tot):     59/   655, tx:        570, lsn: 0/02000E58, prev 0/02000E20, desc: DELETE off 10 KEYS_UPDATED , blkref #0: rel 1663/16385/16386 blk 0 FPW
rmgr: Transaction len (rec/tot):     34/    34, tx:        570, lsn: 0/020010E8, prev 0/02000E58, desc: COMMIT 2018-06-26 16:26:42.487533 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02001110, prev 0/020010E8, desc: RUNNING_XACTS nextXid 571 latestCompletedXid 570 oldestRunningXid 571
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02001148, prev 0/02001110, desc: RUNNING_XACTS nextXid 571 latestCompletedXid 570 oldestRunningXid 571
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02001180, prev 0/02001148, desc: CHECKPOINT_ONLINE redo 0/2001148; tli 1; prev tli 1; fpw true; xid 0:571; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 571; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/020011F0, prev 0/02001180, desc: RUNNING_XACTS nextXid 571 latestCompletedXid 570 oldestRunningXid 571
pg_waldump: FATAL:  error in WAL record at 0/20011F0: invalid record length at 0/2001228: wanted 24, got 0

发现并没有新增日志

  • 查看事务日志
[postgres@pg4 pg_wal]$ pg_waldump  -b -f  -r Transaction 000000010000000000000002 000000010000000000000003
rmgr: Transaction len (rec/tot):     34/    34, tx:        567, lsn: 0/02000480, prev 0/02000368, desc: COMMIT 2018-06-26 15:47:47.340016 CST
rmgr: Transaction len (rec/tot):     34/    34, tx:        568, lsn: 0/02000940, prev 0/02000818, desc: COMMIT 2018-06-26 16:19:56.200336 CST
rmgr: Transaction len (rec/tot):     34/    34, tx:        569, lsn: 0/02000D18, prev 0/02000A80, desc: COMMIT 2018-06-26 16:22:19.062823 CST
rmgr: Transaction len (rec/tot):     34/    34, tx:        570, lsn: 0/020010E8, prev 0/02000E58, desc: COMMIT 2018-06-26 16:26:42.487533 CST
rmgr: Transaction len (rec/tot):     34/    34, tx:        571, lsn: 0/02001628, prev 0/020014E8, desc: COMMIT 2018-06-26 16:46:16.665520 CST
  • 创建数据库
test=# create database pgt;
CREATE DATABASE
test=#
  • 查看日志
[postgres@pg4 pg_wal]$ pg_waldump  -b -f -r Database  000000010000000000000002 000000010000000000000003
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/020016C0, prev 0/02001688, desc: CHECKPOINT_ONLINE redo 0/2001688; tli 1; prev tli 1; fpw true; xid 0:572; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 572; online
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/02001730, prev 0/020016C0, desc: RUNNING_XACTS nextXid 572 latestCompletedXid 571 oldestRunningXid 572
rmgr: Heap        len (rec/tot):     54/  1482, tx:        572, lsn: 0/02001768, prev 0/02001730, desc: INSERT off 7
        blkref #0: rel 1664/0/1262 fork main blk 0 (FPW); hole: offset: 52, length: 6764

rmgr: Btree       len (rec/tot):     53/   217, tx:        572, lsn: 0/02001D38, prev 0/02001768, desc: INSERT_LEAF off 1
        blkref #0: rel 1664/0/2671 fork main blk 1 (FPW); hole: offset: 44, length: 8028

rmgr: Btree       len (rec/tot):     53/   193, tx:        572, lsn: 0/02001E18, prev 0/02001D38, desc: INSERT_LEAF off 5
        blkref #0: rel 1664/0/2672 fork main blk 1 (FPW); hole: offset: 44, length: 8052

rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/02001EE0, prev 0/02001E18, desc: RUNNING_XACTS nextXid 573 latestCompletedXid 571 oldestRunningXid 572; 1 xacts: 572
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02001F18, prev 0/02001EE0, desc: CHECKPOINT_ONLINE redo 0/2001EE0; tli 1; prev tli 1; fpw true; xid 0:573; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 572; online
rmgr: Database    len (rec/tot):     42/    42, tx:        572, lsn: 0/02001F88, prev 0/02001F18, desc: CREATE copy dir 1/1663 to 16392/1663
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/02001FB8, prev 0/02001F88, desc: RUNNING_XACTS nextXid 573 latestCompletedXid 571 oldestRunningXid 572; 1 xacts: 572
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/02001FF0, prev 0/02001FB8, desc: CHECKPOINT_ONLINE redo 0/2001FB8; tli 1; prev tli 1; fpw true; xid 0:573; oid 24576; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 572; online
rmgr: Transaction len (rec/tot):     66/    66, tx:        572, lsn: 0/02002078, prev 0/02001FF0, desc: COMMIT 2018-06-26 17:18:14.699518 CST; inval msgs: catcache 21; sync
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/020020C0, prev 0/02002078, desc: RUNNING_XACTS nextXid 573 latestCompletedXid 572 oldestRunningXid 573
pg_waldump: FATAL:  error in WAL record at 0/20020C0: invalid record length at 0/20020F8: wanted 24, got 0
[postgres@pg4 pg_wal]$

desc: COMMIT 2018-06-26 17:18:14.699518 CST; 发现创建数据库日志已经写入wal日志

  • 使用 显示事务 进行插入数据
test=# begin;
BEGIN
test=# insert into tt (id ,age) values (14,14);
INSERT 0 1

test=#
  • 查看此时 wal日志
[postgres@pg4 pg_wal]$ pg_waldump -bf   000000010000000000000004 000000010000000000000005

...
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/040007F0, prev 0/04000780, desc: RUNNING_XACTS nextXid 575 latestCompletedXid 574 oldestRunningXid 575
rmgr: Heap        len (rec/tot):     54/   858, tx:        575, lsn: 0/04000828, prev 0/040007F0, desc: INSERT off 15
        blkref #0: rel 1663/16385/16386 fork main blk 0 (FPW); hole: offset: 84, length: 7388

rmgr: Btree       len (rec/tot):     53/   373, tx:        575, lsn: 0/04000B88, prev 0/04000828, desc: INSERT_LEAF off 13
        blkref #0: rel 1663/16385/16390 fork main blk 1 (FPW); hole: offset: 80, length: 7872

rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/04000D00, prev 0/04000B88, desc: RUNNING_XACTS nextXid 576 latestCompletedXid 574 oldestRunningXid 575; 1 xacts: 575

发现插入数据后,wal 日志会先进入资源等待 rmgr: Standby ,分配一个事务id 575 ,进入rmgr: Heap,把插入事务写入到指定日志偏移位置 desc: INSERT off 15 ,进入索引资源 rmgr: Btree ,插入索引 desc: INSERT_LEAF off 13,分配下一事务id
RUNNING_XACTS nextXid 576 latestCompletedXid 574 oldestRunningXid 575; 1 xacts: 575

  • 显示事务回滚
test=# begin;
BEGIN
test=# insert into tt (id ,age) values (14,14);
INSERT 0 1
test=# rollback;
ROLLBACK
test=# end;
WARNING:  there is no transaction in progress
COMMIT
test=#
  • 查看此时 wal 日志
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/04000D38, prev 0/04000D00, desc: RUNNING_XACTS nextXid 576 latestCompletedXid 574 oldestRunningXid 575; 1 xacts: 575
rmgr: XLOG        len (rec/tot):    106/   106, tx:          0, lsn: 0/04000D70, prev 0/04000D38, desc: CHECKPOINT_ONLINE redo 0/4000D38; tli 1; prev tli 1; fpw true; xid 0:576; oid 16393; multi 1; offset 0; oldest xid 548 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 0/0; oldest running xid 575; online
rmgr: Standby     len (rec/tot):     54/    54, tx:          0, lsn: 0/04000DE0, prev 0/04000D70, desc: RUNNING_XACTS nextXid 576 latestCompletedXid 574 oldestRunningXid 575; 1 xacts: 575
rmgr: Transaction len (rec/tot):     34/    34, tx:        575, lsn: 0/04000E18, prev 0/04000DE0, desc: ABORT 2018-06-27 10:58:25.616921 CST
rmgr: Standby     len (rec/tot):     50/    50, tx:          0, lsn: 0/04000E40, prev 0/04000E18, desc: RUNNING_XACTS nextXid 576 latestCompletedXid 575 oldestRunningXid 576

发现此时 desc: ABORT 2018-06-27 10:58:25.616921 CST 事务已经取消

你可能感兴趣的:(PostgreSQL)