我想知道是否有一种方法可以更简单地从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:Heap 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:Heap len(rec/tot):3/193,tx:659,lsn:0/0172D538,prev:0/0172D4F8,desc:INSERT off 25,blkref: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:Heap 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:Heap 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:Heap 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中的事务。如果我知道每个事务是什么以及字段的值就足够了。

最佳答案

WAL文件中没有足够的信息来获取导致修改的SQL语句。
基本上,示例中的第一个WAL条目转换为:
在文件1663/12411/3455的块1中,在偏移量284处插入索引项。
WAL条目还包含要在其中写入的原始数据,但pg_xlogdump不显示它们。
所以我能从这个WAL中看到的就是有东西把数据插入了一个有索引的表中,这个表可能很小。
这些信息足以恢复对数据文件的更改,但无法从中重新构造SQL语句。
简而言之,WAL包含对数据库的物理更改,而不是逻辑更改。

10-06 10:56