会话一:
txdb_default=# insert into zz values(3);
INSERT 0 1
wal文件查看如下所示
rmgr: Heap len (rec/tot): 54/ 222, tx: 504, lsn: 0/12012360, prev 0/12012328, desc: INSERT off 4 flags 0x00, blkref #0: rel 1663/13603/16392 blk 0 FPW
rmgr: Transaction len (rec/tot): 34/ 34, tx: 504, lsn: 0/12012440, prev 0/12012360, desc: COMMIT 2022-02-17 17:14:01.336289 CST
一个txid可以对应多个lsn,insert操作会记录一次lsn号,commit操作会记录一次lsn号,即每次操作记录都会生成lsn。
会话一
通过显式提交操作
txdb_default=# begin;
BEGIN
txdb_default=*# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
0/12012070
(1 row)
txdb_default=*# insert into zz values(3);
INSERT 0 1
txdb_default=*#
txdb_default=*# SELECT txid_current();
txid_current
--------------
503
(1 row)
txdb_default=*# select pg_current_wal_lsn();
pg_current_wal_lsn
--------------------
0/12012218
(1 row)
txdb_default=*# commit;
COMMIT
wal文件查看如下所示
rmgr: Heap len (rec/tot): 54/ 186, tx: 503, lsn: 0/12012120, prev 0/120120A8, desc: INSERT off 3 flags 0x00, blkref #0: rel 1663/13603/16392 blk 0 FPW
rmgr: Standby len (rec/tot): 54/ 54, tx: 0, lsn: 0/120121E0, prev 0/12012120, desc: RUNNING_XACTS nextXid 504 latestCompletedXid 502 oldestRunningXid 503; 1 xacts: 503
rmgr: Transaction len (rec/tot): 34/ 34, tx: 503, lsn: 0/12012218, prev 0/120121E0, desc: COMMIT 2022-02-17 17:04:16.597925 CST
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 0/12012240, prev 0/12012218, desc: RUNNING_XACTS nextXid 504 latestCompletedXid 503 oldestRunningXid 504