0

我想知道是否有一种方法可以以更简单的方式从 WAL 日志中读取事务。我想要交易而不是二进制数据。我使用了 pg_xlogdump 但我不知道如何从看起来像这样的结果中获取事务

rmgr: Btree len (rec/tot): 2/ 64, tx: 659, lsn: 0/0172D3C8, prev 0/0172D380, desc: INSERT_LEAF off 284, blkref #0: rel 1663/12411/3455 blk 1
rmgr:堆 len(rec/tot):3/ 171,tx:659,lsn:0/0172D408,prev 0/0172D3C8,desc:INSERT off 35,blkref #0:rel 1663/12411/1249 blk 44
rmgr: Btree len (rec/tot): 2/ 64, tx: 659, lsn: 0/0172D4B8, prev 0/0172D408, desc: INSERT_LEAF off 91, blkref #0: rel 1663/12411/2658 blk 13
rmgr: Btree len (rec/tot): 2/ 64, tx: 659, lsn: 0/0172D4F8, prev 0/0172D4B8, desc: INSERT_LEAF off 309, blkref #0: rel 1663/12411/2659 blk 8
rmgr:堆 len(rec/tot):3/ 193,tx:659,lsn:0/0172D538,prev 0/0172D4F8,desc:INSERT off 25,blkref #0:rel 1663/12411/2610 blk 2
rmgr: Btree len (rec/tot): 2/ 64, tx: 659, lsn: 0/0172D600, prev 0/0172D538, desc: INSERT_LEAF off 121, blkref #0: rel 1663/12411/2678 blk 1
rmgr: Btree len (rec/tot): 2/ 64, tx: 659, lsn: 0/0172D640, prev 0/0172D600, desc: INSERT_LEAF off 122, blkref #0: rel 1663/12411/2679 blk 1
rmgr: 堆 len (rec/tot): 3/ 1786, tx: 659, lsn: 0/0172D680, prev 0/0172D640, desc: INSERT off 3, blkref #0: rel 1663/12411/2606 blk 0 FPW
rmgr: Btree len (rec/tot): 2/ 209, tx: 659, lsn: 0/0172DD80, prev 0/0172D680, desc: INSERT_LEAF off 2, blkref #0: rel 1663/12411/2664 blk 1 FPW
rmgr: Btree len (rec/tot): 2/ 153, tx: 659, lsn: 0/0172DE58, prev 0/0172DD80, desc: INSERT_LEAF off 3, blkref #0: rel 1663/12411/2665 blk 1 FPW
rmgr: Btree len (rec/tot): 2/ 153, tx: 659, lsn: 0/0172DEF8, prev 0/0172DE58, desc: INSERT_LEAF off 1, blkref #0: rel 1663/12411/2666 blk 1 FPW
rmgr: Btree len (rec/tot): 2/ 153, tx: 659, lsn: 0/0172DF98, prev 0/0172DEF8, desc: INSERT_LEAF off 3, blkref #0: rel 1663/12411/2667 blk 1 FPW
rmgr:堆 len(rec/tot):3/ 80,tx:659,lsn:0/0172E050,prev 0/0172DF98,desc:INSERT off 79,blkref #0:rel 1663/12411/2608 blk 53
rmgr: Btree len (rec/tot): 2/ 72, tx: 659, lsn: 0/0172E0A0, prev 0/0172E050, desc: INSERT_LEAF off 235, blkref #0: rel 1663/12411/2673 blk 38
rmgr: Btree len (rec/tot): 2/ 72, tx: 659, lsn: 0/0172E0E8, prev 0/0172E0A0, desc: INSERT_LEAF off 113, blkref #0: rel 1663/12411/2674 blk 44
rmgr:堆 len(rec/tot):3/ 80,tx:659,lsn:0/0172E130,prev 0/0172E0E8,desc:INSERT off 80,blkref #0:rel 1663/12411/2608 blk 53
rmgr: Btree len (rec/tot): 2/ 72, tx: 659, lsn: 0/0172E180, prev 0/0172E130, desc: INSERT_LEAF off 231, blkref #0: rel 1663/12411/2673 blk 38
rmgr: Btree len (rec/tot): 2/ 72, tx: 659, lsn: 0/0172E1C8, prev 0/0172E180, desc: INSERT_LEAF off 109, blkref #0: rel 1663/12411/2674 blk 23

实际上我想要 SQL 中的事务。如果我了解每笔交易是什么以及字段的值就足够了。

4

1 回答 1

4

WAL 文件中没有足够的信息来获取导致修改的 SQL 语句。

基本上,您的示例中的第一个 WAL 条目转换为:
在文件的块 1 中1663/12411/3455,在偏移量 284 处插入一个索引条目。
WAL 条目还包含要写入那里的原始数据,但pg_xlogdump不显示它们。

所以我从这个 WAL 中看到的只是一些东西将数据插入到一个有索引的表中,而这个表可能很小。此信息足以恢复对数据文件的更改,但无法从中重建 SQL 语句。

简而言之,WAL 包含对数据库的物理更改,而不是逻辑更改。

于 2017-02-01T13:09:56.403 回答