Created
December 1, 2022 09:23
-
-
Save mizhka/fadfd719715a7c4ff848188afbff703b to your computer and use it in GitHub Desktop.
Transaction information from pg_waldump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
function process_pgclass (line) { | |
split(line,field,";") | |
relid2name[field[8]] = field[2] | |
#printf("'%s' %s\n", field[8], field[2]) | |
return | |
} | |
BEGIN { | |
pgclassfile = "pg_class_202211231517.csv" | |
while ((getline line < pgclassfile) > 0) { | |
process_pgclass(line) | |
} | |
} | |
function getrelname(relid) { | |
split(relid,item,"/") | |
#printf("'%s' %s\n", item[3], relid2name[item[3]]) | |
return relid2name[item[3]] | |
} | |
function newmodify(tx,relation,modtype) { | |
if (!((tx,relation,modtype) in tx_rel)) { | |
tx_rel[tx,relation,modtype] = 1 | |
} else { | |
tx_rel[tx,relation,modtype] = tx_rel[tx,relation,modtype] + 1 | |
} | |
} | |
function printmodbytx(tx,mod) { | |
for(comb in tx_rel) { | |
split(comb,sep,SUBSEP); | |
if (sep[1] == tx && sep[3] == mod) { | |
printf("%d %s %s ", tx_rel[sep[1],sep[2],sep[3]], sep[3], sep[2]) | |
delete tx_rel[sep[1],sep[2],sep[3]] | |
} | |
} | |
} | |
/^rmgr\:/ { | |
rmgr = $2 | |
lsn = $10 | |
gsub(",", "", lsn) | |
tx = $8 | |
gsub(",", "", tx) | |
type = "---" | |
if (! (tx in ts_start)) { | |
ts_start[tx] = ts | |
} | |
if (rmgr == "Transaction") { | |
type = $14 | |
if (type == "COMMIT_PREPARED") { | |
# rmgr: Transaction len (rec/tot): 84/ 84, tx: 0, lsn: 310/D3878CB0, prev 310/D3878B58, desc: COMMIT_PREPARED 168839249: 2022-11-09 13:18:43.853038 MSK | |
tx = $15 | |
gsub(":","",tx) | |
ts = ($16" "$17) | |
#printf("%s,%s,%s,%s\n", tx, ts_start[tx], ts_prep[tx], ts) | |
#printf("%s,%s,%s,%s,", tx, ts_start[tx], ts_prep[tx], ts) | |
printmodbytx(tx,"insert") | |
printmodbytx(tx,"update") | |
printmodbytx(tx,"lock") | |
printmodbytx(tx,"index") | |
printf("\n") | |
# Clean garbage on commit | |
delete ts_start[tx] | |
delete ts_prep[tx] | |
} else if (type == "PREPARE") { | |
# rmgr: Transaction len (rec/tot): 309/ 309, tx: 0, lsn: 310/D3FFF350, prev 310/D3FFF1E8, desc: PREPARE gid MTM-1-168839942-5: 2022-11-09 13:18:44.713872 MSK | |
gid = $16 | |
gsub("MTM-.-","",gid) | |
gsub("-.:","",gid) | |
if (! (gid in ts_prep)) { | |
ts_prep[gid] = ($17" "$18) | |
} | |
if (tx != "0") { | |
ts = ($17" "$18) | |
} | |
} | |
} else if (rmgr == "Btree") { | |
type = $14 | |
if (type == "INSERT_LEAF" || type == "INSERT_POST" ) { | |
# rmgr: Btree len (rec/tot): 63/ 2103, tx: 168839640, lsn: 310/D3FF8B08, prev 310/D3FF8AB8, desc: INSERT_LEAF off 74, blkref #0: rel 1663/16385/51524204 blk 418073 FPW | |
# rmgr: Btree len (rec/tot): 74/ 74, tx: 168838021, lsn: 310/D39CE088, prev 310/D39CE038, desc: INSERT_POST off 5, blkref #0: rel 1663/16385/51524260 blk 11575 | |
newmodify(tx,getrelname($20),"index") | |
} | |
} else if (rmgr == "Heap") { | |
type = $14 | |
if (type == "UPDATE" || type == "HOT_UPDATE") { | |
# rmgr: Heap len (rec/tot): 414/ 414, tx: 168839900, lsn: 310/D3FEC660, prev 310/D3FEC618, desc: UPDATE off 11 xmax 168839900 flags 0x10 ; new off 32 xmax 0, blkref #0: rel 1663/16385/51523883 blk 100784, blkref #1: rel 1663/16385/51523883 blk 96267 | |
# rmgr: Heap len (rec/tot): 406/ 406, tx: 168839900, lsn: 310/D3FECC08, prev 310/D3FECBB0, desc: HOT_UPDATE off 37 xmax 168839900 flags 0x10 ; new off 21 xmax 0, blkref #0: rel 1663/16385/51523883 blk 94464 | |
newmodify(tx,getrelname($30),"update") | |
} else if (type == "LOCK") { | |
# rmgr: Heap len (rec/tot): 66/ 66, tx: 168839900, lsn: 310/D3FEA2F0, prev 310/D3FEA2A0, desc: LOCK off 42: xid 168839900: flags 0x00 LOCK_ONLY EXCL_LOCK , blkref #0: rel 1663/16385/51523883 blk 96269 | |
newmodify(tx,getrelname($27),"lock") | |
} else if (type == "INSERT" || type == "INSERT+INIT") { | |
#rmgr: Heap len (rec/tot): 591/ 591, tx: 168839681, lsn: 310/D3DDF118, prev 310/D3DDEED8, desc: INSERT+INIT off 18663 flags 0x10, blkref #0: rel 1663/16385/51524149 blk 2780200 | |
#rmgr: Heap len (rec/tot): 207/ 207, tx: 168839727, lsn: 310/D3DE4C20, prev 310/D3DE4AB8, desc: INSERT off 42 flags 0x08, blkref #0: rel 1663/16385/51522972 blk 548 | |
newmodify(tx,getrelname($22),"insert") | |
} | |
} | |
} | |
# | |
# Example: | |
# | |
# rmgr: XLOG len (rec/tot): 59/ 1821, tx: 168838830, lsn: 310/D34B4F20, prev 310/D34B4588, desc: FPI_FOR_HINT , blkref #0: rel 1663/16385/51523996 blk 1677684 FPW | |
/^rmgr\: XLOG/ { | |
type = $14 | |
if (type == "FPI_FOR_HINT") { | |
relation = getrelname($19) | |
} | |
} | |
# Debug | |
{ | |
#if (type == "---" && tx != "0") { | |
#printf("%s %s %s %s %s\n", $14, lsn, ts, tx, type) | |
#} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment