Name pg_xlogdump -- Display a human-readable rendering of the write-ahead log of a PostgreSQL database cluster Synopsis pg_xlogdump [option...] [startseg [endseg] ] Description pg_xlogdump displays thewrite-ahead log (WAL) and is mainly useful for debugging or educational purposes. This utility can only be run bythe user who installed the server, because it requires read-only access tothe data directory.
pg_xlogdump 测试
2.1 展现 startseg 到 startseg 的 WAL 的事务日志
1 2 3 4 5 6 7 8 9 10
[pg93@redhatB pg_xlog]$ ll total 65M -rw-------. 1 pg93 pg93 16M May 1512:04000000010000000000000001 -rw-------. 1 pg93 pg93 16M May 1815:25000000010000000000000002 -rw-------. 1 pg93 pg93 16M May 2413:46000000010000000000000003 -rw-------. 1 pg93 pg93 16M May 2713:18000000010000000000000004 drwx------. 2 pg93 pg93 4.0K May 2413:47 archive_status [pg93@redhatB pg_xlog]$pg_xlogdump -b -n1 000000010000000000000001000000010000000000000004 rmgr: XLOG len (rec/tot): 68/96, tx:0, lsn:0/01000024, prev 0/00000000, bkp:0000, desc:checkpoint: redo 0/1000024; tli 1; prev tli 1; fpw true; xid 0/3; oid 10000; multi 1; offset 0; oldest xid 3in DB 1; oldest multi 1in DB 1; oldest
francs=> select oid,spcname from pg_tablespace where oid=16385; oid | spcname -------+------------ 16385 | tbs_francs (1 row)
database
1 2 3 4 5
francs=> select oid,datname from pg_database where oid=16386; oid | datname -------+--------- 16386 | francs (1 row)
relation
1 2 3 4
francs=> select oid,relkind,relname from pg_class where oid=16438; oid | relkind | relname -------+---------+------------------- 16438 | S | test_json1_id_seq
备注:可见,最终是个序列。
2.4 仅展现 WAL 中资源名称 Database 的日志
1 2 3 4 5 6
[pg93@redhatB pg_xlog]$ pg_xlogdump -r Database -b 000000010000000000000001000000010000000000000004 rmgr: Database len (rec/tot): 16/44, tx:1797, lsn:0/0176C9D4, prev 0/0176C974, bkp:0000, desc: create db: copy dir 1/1663 to 12890/1663 rmgr: Database len (rec/tot): 16/44, tx:1804, lsn:0/0178332C, prev 0/017832CC, bkp:0000, desc: create db: copy dir 1/1663 to 12895/1663 rmgr: Database len (rec/tot): 16/44, tx:1808, lsn:0/0178441C, prev 0/017843BC, bkp:0000, desc: create db: copy dir 12890/1663 to 16386/16385 rmgr: Database len (rec/tot): 16/44, tx:1814, lsn:0/0178619C, prev 0/0178613C, bkp:0000, desc: create db: copy dir 12890/1663 to 16390/16389 pg_xlogdump:FATAL: error in WAL record at 0/40019F8: record with zero length at 0/4001A58
备注:上面指定的 resource manager 为 Database,也可以指定LSN,如下。
2.5 指定 LSN
1 2 3 4 5
[pg93@redhatB pg_xlog]$ pg_xlogdump -r Databasestart 0/0178332C000000010000000000000001 000000010000000000000004 rmgr: Database len (rec/tot): 16/44, tx:1804, lsn:0/0178332C, prev 0/017832CC, bkp:0000, desc: create db: copy dir 1/1663 to 12895/1663 rmgr: Database len (rec/tot): 16/44, tx:1808, lsn:0/0178441C, prev 0/017843BC, bkp:0000, desc: create db: copy dir 12890/1663 to 16386/16385 rmgr: Database len (rec/tot): 16/44, tx:1814, lsn:0/0178619C, prev 0/0178613C, bkp:0000, desc: create db: copy dir 12890/1663 to 16390/16389 pg_xlogdump:FATAL: error in WAL record at 0/40019F8: record with zero length at 0/4001A58