#创建表
postgres=# create table t(id numeric(5));
CREATE TABLE
postgres=# select 't'::regclass::oid;
oid
-------
50032
(1 row)
#查看wal日志
[pg13@sdw2 pg_wal]$ pg_waldump 0000000100000006000000A2
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2000028, prev 6/A1000060, desc: RUNNING_XACTS nextXid 20362 latestCompletedXid 20361 oldestRunningXid 20362
rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 6/A2000060, prev 6/A2000028, desc: CHECKPOINT_ONLINE redo 6/A2000028; tli 1; prev tli 1; fpw true; xid 0:20362; oid 58194; multi 1; offset 0; oldest xid 478 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 496/20361; oldest running xid 20362; online
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A20000D8, prev 6/A2000060, desc: RUNNING_XACTS nextXid 20362 latestCompletedXid 20361 oldestRunningXid 20362
#create table创建表t,relfileno=50032
rmgr: Storage len (rec/tot): 42/ 42, tx: 0, lsn: 6/A2000110, prev 6/A20000D8, desc: CREATE base/13580/50032
rmgr: Standby len (rec/tot): 54/ 54, tx: 0, lsn: 6/A2000140, prev 6/A2000110, desc: RUNNING_XACTS nextXid 20363 latestCompletedXid 20361 oldestRunningXid 20362; 1 xacts: 20362
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2000178, prev 6/A2000140, desc: NEW_CID rel 1663/13580/1247; tid 11/19; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 684, tx: 20362, lsn: 6/A20001B8, prev 6/A2000178, desc: INSERT off 19 flags 0x00, blkref #0: rel 1663/13580/1247 blk 11 FPW
rmgr: Btree len (rec/tot): 55/ 2444, tx: 20362, lsn: 6/A2000468, prev 6/A20001B8, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2703 blk 2 FPW
rmgr: Btree len (rec/tot): 55/ 1776, tx: 20362, lsn: 6/A2000DF8, prev 6/A2000468, desc: INSERT_LEAF off 29, blkref #0: rel 1663/13580/2704 blk 2 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A20014E8, prev 6/A2000DF8, desc: NEW_CID rel 1663/13580/2608; tid 65/101; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 1965, tx: 20362, lsn: 6/A2001528, prev 6/A20014E8, desc: INSERT off 101 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65 FPW
rmgr: Btree len (rec/tot): 55/ 2420, tx: 20362, lsn: 6/A2001CD8, prev 6/A2001528, desc: INSERT_LEAF off 216, blkref #0: rel 1663/13580/2673 blk 36 FPW
rmgr: Btree len (rec/tot): 55/ 2599, tx: 20362, lsn: 6/A2002668, prev 6/A2001CD8, desc: INSERT_LEAF off 224, blkref #0: rel 1663/13580/2674 blk 50 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2003090, prev 6/A2002668, desc: NEW_CID rel 1663/13580/1247; tid 11/20; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 207/ 207, tx: 20362, lsn: 6/A20030D0, prev 6/A2003090, desc: INSERT off 20 flags 0x00, blkref #0: rel 1663/13580/1247 blk 11
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A20031A0, prev 6/A20030D0, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2703 blk 2
rmgr: Btree len (rec/tot): 55/ 2305, tx: 20362, lsn: 6/A20031E0, prev 6/A20031A0, desc: INSERT_LEAF off 104, blkref #0: rel 1663/13580/2704 blk 1 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2003AE8, prev 6/A20031E0, desc: NEW_CID rel 1663/13580/2608; tid 65/102; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 80/ 80, tx: 20362, lsn: 6/A2003B28, prev 6/A2003AE8, desc: INSERT off 102 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A2003B78, prev 6/A2003B28, desc: INSERT_LEAF off 216, blkref #0: rel 1663/13580/2673 blk 36
rmgr: Btree len (rec/tot): 55/ 2260, tx: 20362, lsn: 6/A2003BC0, prev 6/A2003B78, desc: INSERT_LEAF off 212, blkref #0: rel 1663/13580/2674 blk 41 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A20044B0, prev 6/A2003BC0, desc: NEW_CID rel 1663/13580/1259; tid 14/34; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 1298, tx: 20362, lsn: 6/A20044F0, prev 6/A20044B0, desc: INSERT off 34 flags 0x00, blkref #0: rel 1663/13580/1259 blk 14 FPW
rmgr: Btree len (rec/tot): 55/ 3615, tx: 20362, lsn: 6/A2004A08, prev 6/A20044F0, desc: INSERT_LEAF off 347, blkref #0: rel 1663/13580/2662 blk 2 FPW
rmgr: Btree len (rec/tot): 55/ 2640, tx: 20362, lsn: 6/A2005828, prev 6/A2004A08, desc: INSERT_LEAF off 118, blkref #0: rel 1663/13580/2663 blk 7 FPW
rmgr: Btree len (rec/tot): 55/ 2830, tx: 20362, lsn: 6/A2006290, prev 6/A2005828, desc: INSERT_LEAF off 268, blkref #0: rel 1663/13580/3455 blk 4 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2006DA0, prev 6/A2006290, desc: NEW_CID rel 1663/13580/1249; tid 59/38; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 898, tx: 20362, lsn: 6/A2006DE0, prev 6/A2006DA0, desc: INSERT off 38 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59 FPW
rmgr: Btree len (rec/tot): 55/ 591, tx: 20362, lsn: 6/A2007168, prev 6/A2006DE0, desc: INSERT_LEAF off 43, blkref #0: rel 1663/13580/2658 blk 23 FPW
rmgr: Btree len (rec/tot): 55/ 2575, tx: 20362, lsn: 6/A20073B8, prev 6/A2007168, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2007DC8, prev 6/A20073B8, desc: NEW_CID rel 1663/13580/1249; tid 59/39; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2007E08, prev 6/A2007DC8, desc: INSERT off 39 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A2007EB8, prev 6/A2007E08, desc: INSERT_LEAF off 43, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A2007F00, prev 6/A2007EB8, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2007F40, prev 6/A2007F00, desc: NEW_CID rel 1663/13580/1249; tid 59/40; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2007F80, prev 6/A2007F40, desc: INSERT off 40 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A2008048, prev 6/A2007F80, desc: INSERT_LEAF off 45, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A2008090, prev 6/A2008048, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A20080D0, prev 6/A2008090, desc: NEW_CID rel 1663/13580/1249; tid 59/41; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2008110, prev 6/A20080D0, desc: INSERT off 41 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A20081C0, prev 6/A2008110, desc: INSERT_LEAF off 43, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A2008208, prev 6/A20081C0, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2008248, prev 6/A2008208, desc: NEW_CID rel 1663/13580/1249; tid 59/42; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2008288, prev 6/A2008248, desc: INSERT off 42 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A2008338, prev 6/A2008288, desc: INSERT_LEAF off 46, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A2008380, prev 6/A2008338, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A20083C0, prev 6/A2008380, desc: NEW_CID rel 1663/13580/1249; tid 59/43; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2008400, prev 6/A20083C0, desc: INSERT off 43 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A20084B0, prev 6/A2008400, desc: INSERT_LEAF off 43, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A20084F8, prev 6/A20084B0, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A2008538, prev 6/A20084F8, desc: NEW_CID rel 1663/13580/1249; tid 59/44; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20362, lsn: 6/A2008578, prev 6/A2008538, desc: INSERT off 44 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20362, lsn: 6/A2008628, prev 6/A2008578, desc: INSERT_LEAF off 47, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20362, lsn: 6/A2008670, prev 6/A2008628, desc: INSERT_LEAF off 222, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20362, lsn: 6/A20086B0, prev 6/A2008670, desc: NEW_CID rel 1663/13580/2608; tid 65/103; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 80/ 80, tx: 20362, lsn: 6/A20086F0, prev 6/A20086B0, desc: INSERT off 103 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65
rmgr: Btree len (rec/tot): 55/ 1332, tx: 20362, lsn: 6/A2008740, prev 6/A20086F0, desc: INSERT_LEAF off 123, blkref #0: rel 1663/13580/2673 blk 37 FPW
rmgr: Btree len (rec/tot): 55/ 2336, tx: 20362, lsn: 6/A2008C78, prev 6/A2008740, desc: INSERT_LEAF off 247, blkref #0: rel 1663/13580/2674 blk 37 FPW
rmgr: Standby len (rec/tot): 42/ 42, tx: 20362, lsn: 6/A2009598, prev 6/A2008C78, desc: LOCK xid 20362 db 13580 rel 50032
rmgr: Transaction len (rec/tot): 405/ 405, tx: 20362, lsn: 6/A20095C8, prev 6/A2009598, desc: COMMIT 2022-03-10 14:19:44.865853 CST; inval msgs: catcache 75 catcache 74 catcache 75 catcache 74 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 snapshot 2608 relcache 50032
pg_waldump: fatal: error in WAL record at 6/A20095C8: invalid record length at 6/A2009760: wanted 24, got 0
注意:上述日志都是更新和修改元数据,pg_class pg_depend pg_attriue
postgres=# insert into t values(88888);
INSERT 0 1
#查看wal日志
[pg13@sdw2 pg_wal]$ pg_waldump 0000000100000006000000A2
................................
#1 推动xid=20362
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009760, prev 6/A20095C8, desc: RUNNING_XACTS nextXid 20363 latestCompletedXid 20362 oldestRunningXid 20363
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009798, prev 6/A2009760, desc: RUNNING_XACTS nextXid 20363 latestCompletedXid 20362 oldestRunningXid 20363
rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 6/A20097D0, prev 6/A2009798, desc: CHECKPOINT_ONLINE redo 6/A2009798; tli 1; prev tli 1; fpw true; xid 0:20363; oid 58194; multi 1; offset 0; oldest xid 478 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 496/20362; oldest running xid 20363; online
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009848, prev 6/A20097D0, desc: RUNNING_XACTS nextXid 20363 latestCompletedXid 20362 oldestRunningXid 20363
#2 写入数据
rmgr: Heap len (rec/tot): 62/ 62, tx: 20363, lsn: 6/A2009880, prev 6/A2009848, desc: INSERT+INIT off 1 flags 0x08, blkref #0: rel 1663/13580/50032 blk 0
#3 事务提交
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20363, lsn: 6/A20098C0, prev 6/A2009880, desc: COMMIT 2022-03-10 14:27:15.277014 CST
#4 推动xid=20364
rmgr: Standby len (rec/tot): 54/ 54, tx: 0, lsn: 6/A20098F0, prev 6/A20098C0, desc: RUNNING_XACTS nextXid 20364 latestCompletedXid 20362 oldestRunningXid 20363; 1 xacts: 20363
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009928, prev 6/A20098F0, desc: RUNNING_XACTS nextXid 20364 latestCompletedXid 20363 oldestRunningXid 20364
rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 6/A2009960, prev 6/A2009928, desc: CHECKPOINT_ONLINE redo 6/A2009928; tli 1; prev tli 1; fpw true; xid 0:20364; oid 58194; multi 1; offset 0; oldest xid 478 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 496/20363; oldest running xid 20364; online
postgres=# alter table t alter COLUMN id type numeric(6);
ALTER TABLE
pg13@sdw2 pg_wal]$ pg_waldump 0000000100000006000000A2
................接上面的日志.................................
rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 6/A2009960, prev 6/A2009928, desc: CHECKPOINT_ONLINE redo 6/A2009928; tli 1; prev tli 1; fpw true; xid 0:20364; oid 58194; multi 1; offset 0; oldest xid 478 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 496/20363; oldest running xid 20364; online
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A20099D8, prev 6/A2009960, desc: RUNNING_XACTS nextXid 20364 latestCompletedXid 20363 oldestRunningXid 20364
#lock表,并且xid=20364
rmgr: Standby len (rec/tot): 42/ 42, tx: 20364, lsn: 6/A2009A10, prev 6/A20099D8, desc: LOCK xid 20364 db 13580 rel 50032
# 修改元数据pg_attribute表(oid=1249)
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20364, lsn: 6/A2009A40, prev 6/A2009A10, desc: NEW_CID rel 1663/13580/1249; tid 59/38; cmin: 4294967295, cmax: 0, combo: 4294967295
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20364, lsn: 6/A2009A80, prev 6/A2009A40, desc: NEW_CID rel 1663/13580/1249; tid 59/45; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 67/ 1009, tx: 20364, lsn: 6/A2009AC0, prev 6/A2009A80, desc: HOT_UPDATE off 38 xmax 20364 flags 0x00 ; new off 45 xmax 0, blkref #0: rel 1663/13580/1249 blk 59 FPW
rmgr: Transaction len (rec/tot): 98/ 98, tx: 20364, lsn: 6/A2009EB8, prev 6/A2009AC0, desc: COMMIT 2022-03-10 14:33:45.290471 CST; inval msgs: catcache 7 catcache 6 relcache 50032
# 事务xid推进到20365
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009F20, prev 6/A2009EB8, desc: RUNNING_XACTS nextXid 20365 latestCompletedXid 20364 oldestRunningXid 20365
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A2009F58, prev 6/A2009F20, desc: RUNNING_XACTS nextXid 20365 latestCompletedXid 20364 oldestRunningXid 20365
rmgr: XLOG len (rec/tot): 114/ 114, tx: 0, lsn: 6/A2009F90, prev 6/A2009F58, desc: CHECKPOINT_ONLINE redo 6/A2009F58; tli 1; prev tli 1; fpw true; xid 0:20365; oid 58194; multi 1; offset 0; oldest xid 478 in DB 1; oldest multi 1 in DB 1; oldest/newest commit timestamp xid: 496/20364; oldest running xid 20365; online
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/A200A020, prev 6/A2009F90, desc: RUNNING_XACTS nextXid 20365 latestCompletedXid 20364 oldestRunningXid 20365
pg_waldump: fatal: error in WAL record at 6/A200A020: invalid record length at 6/A200A058: wanted 24, got 0
总结:当字段从numeric(5)增加到numeric(6),只是元数据发生改变(pg_attribute表)。
postgres=# alter table t alter COLUMN id type numeric(8,2);
ALTER TABLE
[pg13@sdw2 pg_wal]$ pg_waldump 0000000100000006000000A2
.........................接上述日志...............
# lock表,且xid=20365
rmgr: Standby len (rec/tot): 42/ 42, tx: 20365, lsn: 6/A200A058, prev 6/A200A020, desc: LOCK xid 20365 db 13580 rel 50032
# 修改元数据pg_attribute表(oid=1249)
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200A088, prev 6/A200A058, desc: NEW_CID rel 1663/13580/1249; tid 59/45; cmin: 4294967295, cmax: 0, combo: 4294967295
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200A0C8, prev 6/A200A088, desc: NEW_CID rel 1663/13580/1249; tid 59/46; cmin: 0, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 67/ 1034, tx: 20365, lsn: 6/A200A108, prev 6/A200A0C8, desc: HOT_UPDATE off 45 xmax 20365 flags 0x00 ; new off 46 xmax 0, blkref #0: rel 1663/13580/1249 blk 59 FPW
# 为表t创新的相关filenode,refilenode=50035
rmgr: Storage len (rec/tot): 42/ 42, tx: 20365, lsn: 6/A200A518, prev 6/A200A108, desc: CREATE base/13580/50035
#修改元数据pg_type(oid=1247)
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200A548, prev 6/A200A518, desc: NEW_CID rel 1663/13580/1247; tid 11/21; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 751, tx: 20365, lsn: 6/A200A588, prev 6/A200A548, desc: INSERT off 21 flags 0x00, blkref #0: rel 1663/13580/1247 blk 11 FPW
rmgr: Btree len (rec/tot): 55/ 2465, tx: 20365, lsn: 6/A200A878, prev 6/A200A588, desc: INSERT_LEAF off 231, blkref #0: rel 1663/13580/2703 blk 2 FPW
rmgr: Btree len (rec/tot): 55/ 3348, tx: 20365, lsn: 6/A200B220, prev 6/A200A878, desc: INSERT_LEAF off 115, blkref #0: rel 1663/13580/2704 blk 4 FPW
#修改元数据pg_depend( 2608)
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200BF38, prev 6/A200B220, desc: NEW_CID rel 1663/13580/2608; tid 65/104; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 2021, tx: 20365, lsn: 6/A200BF78, prev 6/A200BF38, desc: INSERT off 104 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65 FPW
rmgr: Btree len (rec/tot): 55/ 2443, tx: 20365, lsn: 6/A200C778, prev 6/A200BF78, desc: INSERT_LEAF off 218, blkref #0: rel 1663/13580/2673 blk 36 FPW
rmgr: Btree len (rec/tot): 55/ 2612, tx: 20365, lsn: 6/A200D108, prev 6/A200C778, desc: INSERT_LEAF off 225, blkref #0: rel 1663/13580/2674 blk 50 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200DB40, prev 6/A200D108, desc: NEW_CID rel 1663/13580/1247; tid 11/22; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 207/ 207, tx: 20365, lsn: 6/A200DB80, prev 6/A200DB40, desc: INSERT off 22 flags 0x00, blkref #0: rel 1663/13580/1247 blk 11
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A200DC50, prev 6/A200DB80, desc: INSERT_LEAF off 231, blkref #0: rel 1663/13580/2703 blk 2
rmgr: Btree len (rec/tot): 55/ 2320, tx: 20365, lsn: 6/A200DC90, prev 6/A200DC50, desc: INSERT_LEAF off 63, blkref #0: rel 1663/13580/2704 blk 1 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200E5B8, prev 6/A200DC90, desc: NEW_CID rel 1663/13580/2608; tid 65/105; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 80/ 80, tx: 20365, lsn: 6/A200E5F8, prev 6/A200E5B8, desc: INSERT off 105 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A200E648, prev 6/A200E5F8, desc: INSERT_LEAF off 218, blkref #0: rel 1663/13580/2673 blk 36
rmgr: Btree len (rec/tot): 55/ 2268, tx: 20365, lsn: 6/A200E690, prev 6/A200E648, desc: INSERT_LEAF off 213, blkref #0: rel 1663/13580/2674 blk 41 FPW
#修改元数据pg_class(1259)
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A200EF70, prev 6/A200E690, desc: NEW_CID rel 1663/13580/1259; tid 14/35; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 1346, tx: 20365, lsn: 6/A200EFB0, prev 6/A200EF70, desc: INSERT off 35 flags 0x00, blkref #0: rel 1663/13580/1259 blk 14 FPW
rmgr: Btree len (rec/tot): 55/ 3626, tx: 20365, lsn: 6/A200F4F8, prev 6/A200EFB0, desc: INSERT_LEAF off 348, blkref #0: rel 1663/13580/2662 blk 2 FPW
rmgr: Btree len (rec/tot): 55/ 1506, tx: 20365, lsn: 6/A2010340, prev 6/A200F4F8, desc: INSERT_LEAF off 53, blkref #0: rel 1663/13580/2663 blk 5 FPW
rmgr: Btree len (rec/tot): 55/ 2839, tx: 20365, lsn: 6/A2010928, prev 6/A2010340, desc: INSERT_LEAF off 269, blkref #0: rel 1663/13580/3455 blk 4 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2011440, prev 6/A2010928, desc: NEW_CID rel 1663/13580/1249; tid 59/47; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A2011480, prev 6/A2011440, desc: INSERT off 47 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 55/ 664, tx: 20365, lsn: 6/A2011530, prev 6/A2011480, desc: INSERT_LEAF off 50, blkref #0: rel 1663/13580/2658 blk 23 FPW
rmgr: Btree len (rec/tot): 55/ 2645, tx: 20365, lsn: 6/A20117C8, prev 6/A2011530, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15 FPW
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2012238, prev 6/A20117C8, desc: NEW_CID rel 1663/13580/1249; tid 59/48; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A2012278, prev 6/A2012238, desc: INSERT off 48 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A2012328, prev 6/A2012278, desc: INSERT_LEAF off 50, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2012370, prev 6/A2012328, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A20123B0, prev 6/A2012370, desc: NEW_CID rel 1663/13580/1249; tid 59/49; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A20123F0, prev 6/A20123B0, desc: INSERT off 49 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A20124A0, prev 6/A20123F0, desc: INSERT_LEAF off 52, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A20124E8, prev 6/A20124A0, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2012528, prev 6/A20124E8, desc: NEW_CID rel 1663/13580/1249; tid 59/50; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A2012568, prev 6/A2012528, desc: INSERT off 50 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A2012618, prev 6/A2012568, desc: INSERT_LEAF off 50, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2012660, prev 6/A2012618, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A20126A0, prev 6/A2012660, desc: NEW_CID rel 1663/13580/1249; tid 59/51; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A20126E0, prev 6/A20126A0, desc: INSERT off 51 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A2012790, prev 6/A20126E0, desc: INSERT_LEAF off 53, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A20127D8, prev 6/A2012790, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2012818, prev 6/A20127D8, desc: NEW_CID rel 1663/13580/1249; tid 59/52; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 175/ 175, tx: 20365, lsn: 6/A2012858, prev 6/A2012818, desc: INSERT off 52 flags 0x00, blkref #0: rel 1663/13580/1249 blk 59
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A2012908, prev 6/A2012858, desc: INSERT_LEAF off 50, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2012950, prev 6/A2012908, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2012990, prev 6/A2012950, desc: NEW_CID rel 1663/13580/1249; tid 64/19; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 56/ 1144, tx: 20365, lsn: 6/A20129D0, prev 6/A2012990, desc: INSERT off 19 flags 0x00, blkref #0: rel 1663/13580/1249 blk 64 FPW
rmgr: Btree len (rec/tot): 72/ 72, tx: 20365, lsn: 6/A2012E48, prev 6/A20129D0, desc: INSERT_LEAF off 54, blkref #0: rel 1663/13580/2658 blk 23
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2012E90, prev 6/A2012E48, desc: INSERT_LEAF off 229, blkref #0: rel 1663/13580/2659 blk 15
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2012ED0, prev 6/A2012E90, desc: NEW_CID rel 1663/13580/2608; tid 65/106; cmin: 1, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 80/ 80, tx: 20365, lsn: 6/A2012F10, prev 6/A2012ED0, desc: INSERT off 106 flags 0x00, blkref #0: rel 1663/13580/2608 blk 65
rmgr: Btree len (rec/tot): 55/ 1344, tx: 20365, lsn: 6/A2012F60, prev 6/A2012F10, desc: INSERT_LEAF off 124, blkref #0: rel 1663/13580/2673 blk 37 FPW
rmgr: Btree len (rec/tot): 55/ 2344, tx: 20365, lsn: 6/A20134A0, prev 6/A2012F60, desc: INSERT_LEAF off 248, blkref #0: rel 1663/13580/2674 blk 37 FPW
rmgr: Heap2 len (rec/tot): 132/ 132, tx: 20365, lsn: 6/A2013DC8, prev 6/A20134A0, desc: CLEAN remxid 20364, blkref #0: rel 1663/13580/1249 blk 59
# lock表t,xid=20365,relfilenode=50035
rmgr: Standby len (rec/tot): 42/ 42, tx: 20365, lsn: 6/A2013E50, prev 6/A2013DC8, desc: LOCK xid 20365 db 13580 rel 50035
# **重新写入表t数据**
rmgr: Heap len (rec/tot): 62/ 62, tx: 20365, lsn: 6/A2013E80, prev 6/A2013E50, desc: INSERT+INIT off 1 flags 0x08, blkref #0: rel 1663/13580/50035 blk 0
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2013EC0, prev 6/
#写入pg_class pg_depend等表的索引数据
A2013E80, desc: NEW_CID rel 1663/13580/1259; tid 14/34; cmin: 4294967295, cmax: 2, combo: 4294967295
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2013F00, prev 6/A2013EC0, desc: NEW_CID rel 1663/13580/1259; tid 14/36; cmin: 2, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 123/ 123, tx: 20365, lsn: 6/A2013F40, prev 6/A2013F00, desc: UPDATE off 34 xmax 20365 flags 0x60 ; new off 36 xmax 0, blkref #0: rel 1663/13580/1259 blk 14
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2013FC0, prev 6/A2013F40, desc: INSERT_LEAF off 348, blkref #0: rel 1663/13580/2662 blk 2
rmgr: Btree len (rec/tot): 55/ 2647, tx: 20365, lsn: 6/A2014018, prev 6/A2013FC0, desc: INSERT_LEAF off 119, blkref #0: rel 1663/13580/2663 blk 7 FPW
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2014A70, prev 6/A2014018, desc: INSERT_LEAF off 270, blkref #0: rel 1663/13580/3455 blk 4
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014AB0, prev 6/A2014A70, desc: NEW_CID rel 1663/13580/1259; tid 14/35; cmin: 1, cmax: 2, combo: 0
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014AF0, prev 6/A2014AB0, desc: NEW_CID rel 1663/13580/1259; tid 14/37; cmin: 2, cmax: 4294967295, combo: 4294967295
rmgr: Heap len (rec/tot): 79/ 79, tx: 20365, lsn: 6/A2014B30, prev 6/A2014AF0, desc: UPDATE off 35 xmax 20365 flags 0x60 ; new off 37 xmax 0, blkref #0: rel 1663/13580/1259 blk 14
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2014B80, prev 6/A2014B30, desc: INSERT_LEAF off 350, blkref #0: rel 1663/13580/2662 blk 2
rmgr: Btree len (rec/tot): 80/ 80, tx: 20365, lsn: 6/A2014BC0, prev 6/A2014B80, desc: INSERT_LEAF off 54, blkref #0: rel 1663/13580/2663 blk 5
rmgr: Btree len (rec/tot): 64/ 64, tx: 20365, lsn: 6/A2014C10, prev 6/A2014BC0, desc: INSERT_LEAF off 269, blkref #0: rel 1663/13580/3455 blk 4
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014C50, prev 6/A2014C10, desc: NEW_CID rel 1663/13580/1247; tid 11/22; cmin: 1, cmax: 3, combo: 1
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014C90, prev 6/A2014C50, desc: DELETE off 22 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1247 blk 11
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014CC8, prev 6/A2014C90, desc: NEW_CID rel 1663/13580/2608; tid 65/105; cmin: 1, cmax: 3, combo: 1
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014D08, prev 6/A2014CC8, desc: DELETE off 105 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/2608 blk 65
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014D40, prev 6/A2014D08, desc: NEW_CID rel 1663/13580/1247; tid 11/21; cmin: 1, cmax: 4, combo: 2
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014D80, prev 6/A2014D40, desc: DELETE off 21 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1247 blk 11
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014DB8, prev 6/A2014D80, desc: NEW_CID rel 1663/13580/2608; tid 65/104; cmin: 1, cmax: 4, combo: 2
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014DF8, prev 6/A2014DB8, desc: DELETE off 104 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/2608 blk 65
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014E30, prev 6/A2014DF8, desc: NEW_CID rel 1663/13580/1249; tid 64/19; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014E70, prev 6/A2014E30, desc: DELETE off 19 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 64
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014EA8, prev 6/A2014E70, desc: NEW_CID rel 1663/13580/1249; tid 59/52; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014EE8, prev 6/A2014EA8, desc: DELETE off 52 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014F20, prev 6/A2014EE8, desc: NEW_CID rel 1663/13580/1249; tid 59/51; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014F60, prev 6/A2014F20, desc: DELETE off 51 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2014F98, prev 6/A2014F60, desc: NEW_CID rel 1663/13580/1249; tid 59/50; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2014FD8, prev 6/A2014F98, desc: DELETE off 50 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2015010, prev 6/A2014FD8, desc: NEW_CID rel 1663/13580/1249; tid 59/49; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2015050, prev 6/A2015010, desc: DELETE off 49 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2015088, prev 6/A2015050, desc: NEW_CID rel 1663/13580/1249; tid 59/48; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A20150C8, prev 6/A2015088, desc: DELETE off 48 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2015100, prev 6/A20150C8, desc: NEW_CID rel 1663/13580/1249; tid 59/47; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2015140, prev 6/A2015100, desc: DELETE off 47 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1249 blk 59
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A2015178, prev 6/A2015140, desc: NEW_CID rel 1663/13580/1259; tid 14/37; cmin: 2, cmax: 5, combo: 4
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A20151B8, prev 6/A2015178, desc: DELETE off 37 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/1259 blk 14
rmgr: Heap2 len (rec/tot): 60/ 60, tx: 20365, lsn: 6/A20151F0, prev 6/A20151B8, desc: NEW_CID rel 1663/13580/2608; tid 65/106; cmin: 1, cmax: 5, combo: 3
rmgr: Heap len (rec/tot): 54/ 54, tx: 20365, lsn: 6/A2015230, prev 6/A20151F0, desc: DELETE off 106 flags 0x00 KEYS_UPDATED , blkref #0: rel 1663/13580/2608 blk 65
总结:修改字段长度numeric(6)->numeric(8,2),数据会发生一次拷贝。表对应的refilenode修改为:50032->50035。所以对大表修改数据类型,简直就是灾难性的。
所以:
(1)如果是整数位的修改,relfilenode不会改变,数据不会拷贝
(2)如果是小数位的修改,relfilenode会改变,数据发生拷贝
postgres=# create table t(id numeric(6,2));
CREATE TABLE
postgres=# insert into t values(10.05);
INSERT 0 1
postgres=# insert into t values(10.05);
INSERT 0 1
postgres=# insert into t values(10.05);
INSERT 0 1
postgres=# insert into t values(10.05);
INSERT 0 1
postgres=# insert into t values(10.05);
INSERT 0 1
relfilenode=1663/13580/90933
rmgr: Standby len (rec/tot): 42/ 42, tx: 20473, lsn: 6/1A008D18, prev 6/1A008400, desc: LOCK xid 20473 db 13580 rel 90933
rmgr: Transaction len (rec/tot): 405/ 405, tx: 20473, lsn: 6/1A008D48, prev 6/1A008D18, desc: COMMIT 2022-05-23 12:20:15.786658 CST; inval msgs: catcache 75 catcache 74 catcache 75 catcache 74 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 snapshot 2608 relcache 90933
rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 6/1A008EE0, prev 6/1A008D48, desc: RUNNING_XACTS nextXid 20474 latestCompletedXid 20473 oldestRunningXid 20474
rmgr: Heap len (rec/tot): 62/ 62, tx: 20474, lsn: 6/1A008F18, prev 6/1A008EE0, desc: INSERT+INIT off 1 flags 0x08, blkref #0: rel 1663/13580/90933 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20474, lsn: 6/1A008F58, prev 6/1A008F18, desc: COMMIT 2022-05-23 12:20:41.552383 CST
rmgr: CommitTs len (rec/tot): 30/ 30, tx: 0, lsn: 6/1A008F88, prev 6/1A008F58, desc: ZEROPAGE 25
rmgr: Heap len (rec/tot): 62/ 62, tx: 20475, lsn: 6/1A008FA8, prev 6/1A008F88, desc: INSERT off 2 flags 0x08, blkref #0: rel 1663/13580/90933 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20475, lsn: 6/1A008FE8, prev 6/1A008FA8, desc: COMMIT 2022-05-23 12:20:42.543305 CST
rmgr: Heap len (rec/tot): 62/ 62, tx: 20476, lsn: 6/1A009018, prev 6/1A008FE8, desc: INSERT off 3 flags 0x08, blkref #0: rel 1663/13580/90933 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20476, lsn: 6/1A009058, prev 6/1A009018, desc: COMMIT 2022-05-23 12:20:43.330493 CST
rmgr: Heap len (rec/tot): 62/ 62, tx: 20477, lsn: 6/1A009088, prev 6/1A009058, desc: INSERT off 4 flags 0x08, blkref #0: rel 1663/13580/90933 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20477, lsn: 6/1A0090C8, prev 6/1A009088, desc: COMMIT 2022-05-23 12:20:44.041929 CST
rmgr: Heap len (rec/tot): 62/ 62, tx: 20478, lsn: 6/1A0090F8, prev 6/1A0090C8, desc: INSERT off 5 flags 0x08, blkref #0: rel 1663/13580/90933 blk 0
rmgr: Transaction len (rec/tot): 46/ 46, tx: 20478, lsn: 6/1A009138, prev 6/1A0090F8, desc: COMMIT 2022-05-23 12:20:44.599857 CST
pg_waldump: fatal: error in WAL record at 6/1A009138: invalid record length at 6/1A009168: wanted 24, got 0
postgres=# alter table t alter COLUMN id type numeric(7,3);
relfilenode=1663/13580/90936 发现relfilenode变化了,数据也重写了一份
rmgr: Standby len (rec/tot): 42/ 42, tx: 20479, lsn: 6/1A00B898, prev 6/1A00B850, desc: LOCK xid 20479 db 13580 rel 90936
rmgr: Heap len (rec/tot): 62/ 62, tx: 20479, lsn: 6/1A00B8C8, prev 6/1A00B898, desc: INSERT+INIT off 1 flags 0x08, blkref #0: rel 1663/13580/90936 blk 0
rmgr: Heap len (rec/tot): 62/ 62, tx: 20479, lsn: 6/1A00B908, prev 6/1A00B8C8, desc: INSERT off 2 flags 0x08, blkref #0: rel 1663/13580/90936 blk 0
rmgr: Heap len (rec/tot): 62/ 62, tx: 20479, lsn: 6/1A00B948, prev 6/1A00B908, desc: INSERT off 3 flags 0x08, blkref #0: rel 1663/13580/90936 blk 0
rmgr: Heap len (rec/tot): 62/ 62, tx: 20479, lsn: 6/1A00B988, prev 6/1A00B948, desc: INSERT off 4 flags 0x08, blkref #0: rel 1663/13580/90936 blk 0
rmgr: Heap len (rec/tot): 62/ 62, tx: 20479, lsn: 6/1A00B9C8, prev 6/1A00B988, desc: INSERT off 5 flags 0x08, blkref #0: rel 1663/13580/90936 blk 0
总结:修改字段长度numeric(6,2)->numeric(7,3),数据会发生一次拷贝。表对应的refilenode修改为:90933->90936
尝试修改元数据。
postgres=# SELECT atttypmod, attname
FROM pg_attribute
WHERE 1 = 1
AND attrelid = 't'::regclass
AND attname ='id'
ORDER BY atttypmod;
atttypmod | attname
-----------+---------
524294 | id
(1 row)
这里atttypmod有个公式
atttypmod = precision * 65,536 + scale + 4
524294=8*65,536+2+4
如果我们要修改为numeric(10,3),那我们计算一下:atttypmod = precision * 65,536 + scale + 4=655360+4+4= 655368
postgres=# UPDATE pg_attribute
SET atttypmod = 655368
WHERE attrelid = 't'::regclass
AND attname = 'id';
查看表结构
postgres=# \d+ t
Table "public.t"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------------+-----------+----------+---------+---------+--------------+-------------
id | numeric(10,4) | | | | main | |
Access method: heap
查看数据
postgres=# select * from t;
id
----------
88888.00 ---这里为.00
(1 row)
重新插入一条数据
postgres=# insert into t values(1);
INSERT 0 1
postgres=# select * from t;
id
----------
88888.00 ---老的.00
1.0000 ---新的.0000
(2 rows)
所以pg为了格式的一致,在发生精度变化时,需要对表重新生成一次数据。如果我们修改了元数据,老的数据的精度是不会变化的