這篇文章主要介紹“怎么使用PostgreSQL中pg_waldump工具”,在日常操作中,相信很多人在怎么使用PostgreSQL中pg_waldump工具問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么使用PostgreSQL中pg_waldump工具”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),橋東企業(yè)網(wǎng)站建設(shè),橋東品牌網(wǎng)站建設(shè),網(wǎng)站定制,橋東網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,橋東網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
按照先前幾節(jié)對(duì)WAL文件結(jié)構(gòu)的介紹,我們可以自行寫一個(gè)解析事務(wù)日志的小程序用于查看日志文件中的內(nèi)容,不過PG已經(jīng)幫我們考慮到了,PG提供了dump事務(wù)日志的工具:pg_waldump.
注:pg_waldump for PG 10.x+,如果是PG 9.x或以下版本,則使用pg_xlogdump.
在Linux下執(zhí)行,使用--help查看幫助.
[xdb@localhost pg_wal]$ pg_waldump --help pg_waldump decodes and displays PostgreSQL write-ahead logs for debugging. Usage: pg_waldump [OPTION]... [STARTSEG [ENDSEG]] Options: -b, --bkp-details output detailed information about backup blocks -e, --end=RECPTR stop reading at WAL location RECPTR -f, --follow keep retrying after reaching end of WAL -n, --limit=N number of records to display -p, --path=PATH directory in which to find log segment files or a directory with a ./pg_wal that contains such files (default: current directory, ./pg_wal, $PGDATA/pg_wal) -r, --rmgr=RMGR only show records generated by resource manager RMGR; use --rmgr=list to list valid resource manager names -s, --start=RECPTR start reading at WAL location RECPTR -t, --timeline=TLI timeline from which to read log records (default: 1 or the value used in STARTSEG) -V, --version output version information, then exit -x, --xid=XID only show records with transaction ID XID -z, --stats[=record] show statistics instead of records (optionally, show per-record statistics) -?, --help show this help, then exit [xdb@localhost pg_wal]$
-b, --bkp-details output detailed information about backup blocks
輸出backup blocks即full-write-page的詳細(xì)信息.
-e, --end=RECPTR stop reading at WAL location RECPTR
搜索在此LSN偏移處結(jié)束
-f, --follow keep retrying after reaching end of WAL
在到達(dá)WAL末尾時(shí)仍繼續(xù)嘗試
-n, --limit=N number of records to display
XLOG Record的輸出個(gè)數(shù)
-p, --path=PATH directory in which to find log segment files or a
directory with a ./pg_wal that contains such files
(default: current directory, ./pg_wal, $PGDATA/pg_wal)
在哪個(gè)目錄下尋找WAL segment files
-r, --rmgr=RMGR only show records generated by resource manager RMGR;
use --rmgr=list to list valid resource manager names
只顯示指定的RMGR的XLOG Record
-s, --start=RECPTR start reading at WAL location RECPTR
在此LSN偏移處開始搜索
-t, --timeline=TLI timeline from which to read log records
(default: 1 or the value used in STARTSEG)
指定的時(shí)間線timeline
-V, --version output version information, then exit
輸出版本信息,然后退出
-x, --xid=XID only show records with transaction ID XID
只輸出指定的事務(wù)ID的XLOG Record
-z, --stats[=record] show statistics instead of records
(optionally, show per-record statistics)
輸出統(tǒng)計(jì)信息
-?, --help show this help, then exit
輸出幫助信息
下面是測(cè)試機(jī)上pg_wal目錄中的文件
[xdb@localhost pg_wal]$ ll total 98332 -rw-------. 1 xdb xdb 16777216 Dec 20 12:02 000000010000000100000048 -rw-------. 1 xdb xdb 16777216 Dec 19 16:47 000000010000000100000049 -rw-------. 1 xdb xdb 16777216 Dec 19 16:47 00000001000000010000004A -rw-------. 1 xdb xdb 16777216 Dec 19 16:47 00000001000000010000004B -rw-------. 1 xdb xdb 16777216 Dec 19 16:47 00000001000000010000004C -rw-------. 1 xdb xdb 16777216 Dec 19 16:47 00000001000000010000004D drwx------. 2 xdb xdb 6 Nov 16 15:48 archive_status
輸出文件000000010000000100000048最開始的4個(gè)XLOG Record
命令:pg_waldump -p ./ -s 1/48000000 -n 4
[xdb@localhost pg_wal]$ pg_waldump -p ./ -s 1/48000000 -n 4 rmgr: Heap len (rec/tot): 77/ 77, tx: 1964, lsn: 1/48000070, prev 1/47FFFFF8, desc: INSERT off 117, blkref #0: rel 1663/16402/17028 blk 1110 rmgr: Heap len (rec/tot): 77/ 77, tx: 1964, lsn: 1/480000C0, prev 1/48000070, desc: INSERT off 7, blkref #0: rel 1663/16402/17031 blk 1111 rmgr: Heap len (rec/tot): 77/ 77, tx: 1964, lsn: 1/48000110, prev 1/480000C0, desc: INSERT off 8, blkref #0: rel 1663/16402/17031 blk 1111 rmgr: Heap len (rec/tot): 77/ 77, tx: 1964, lsn: 1/48000160, prev 1/48000110, desc: INSERT off 9, blkref #0: rel 1663/16402/17031 blk 1111
注意第一條記錄,上一個(gè)LSN為1/47FFFFF8(prev 1/47FFFFF8),提示上一page最后一個(gè)XLOG Record存儲(chǔ)在本頁的XLogLongPageHeaderData中,存儲(chǔ)的空間大小可以從該XLOG Record的LSN(1/48000070)和XLogLongPageHeaderData的大小(40B)推算獲得,有興趣的同學(xué)可以自行計(jì)算.
注:LSN的計(jì)算請(qǐng)參照PostgreSQL DBA(15) - WAL文件結(jié)構(gòu)
查看Redo point后的XLOG Record
首先使用pg_controldata命令查看Redo point --> 1/484336A0
[xdb@localhost pg_wal]$ pg_controldata pg_control version number: 1100 Catalog version number: 201809051 Database system identifier: 6624362124887945794 Database cluster state: in production pg_control last modified: Thu 20 Dec 2018 12:17:39 PM CST Latest checkpoint location: 1/484336D8 Latest checkpoint's REDO location: 1/484336A0 Latest checkpoint's REDO WAL file: 000000010000000100000048 Latest checkpoint's TimeLineID: 1 ...
然后使用pg_waldump查看
命令:pg_waldump -p ./ -s 1/484336A0
[xdb@localhost pg_wal]$ pg_waldump -p ./ -s 1/484336A0 rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 1/484336A0, prev 1/48433668, desc: RUNNING_XACTS nextXid 1971 latestCompletedXid 1970 oldestRunningXid 1971 rmgr: XLOG len (rec/tot): 106/ 106, tx: 0, lsn: 1/484336D8, prev 1/484336A0, desc: CHECKPOINT_ONLINE redo 1/484336A0; tli 1; prev tli 1; fpw true; xid 0:1971; oid 17046; multi 1; offset 0; oldest xid 561 in DB 16402; oldest multi 1 in DB 16402; oldest/newest commit timestamp xid: 0/0; oldest running xid 1971; online rmgr: Standby len (rec/tot): 50/ 50, tx: 0, lsn: 1/48433748, prev 1/484336D8, desc: RUNNING_XACTS nextXid 1971 latestCompletedXid 1970 oldestRunningXid 1971 pg_waldump: FATAL: error in WAL record at 1/48433748: invalid record length at 1/48433780: wanted 24, got 0 [xdb@localhost pg_wal]$
到此,關(guān)于“怎么使用PostgreSQL中pg_waldump工具”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!