這篇文章主要介紹“怎么使用PostgreSQL中pg_waldump工具”,在日常操作中,相信很多人在怎么使用PostgreSQL中pg_waldump工具問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么使用PostgreSQL中pg_waldump工具”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
為江陽等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及江陽網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站建設(shè)、成都做網(wǎng)站、江陽網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!按照先前幾節(jié)對WAL文件結(jié)構(gòu)的介紹,我們可以自行寫一個解析事務(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的詳細信息.
-e, --end=RECPTR stop reading at WAL location RECPTR
搜索在此LSN偏移處結(jié)束
-f, --follow keep retrying after reaching end of WAL
在到達WAL末尾時仍繼續(xù)嘗試
-n, --limit=N number of records to display
XLOG Record的輸出個數(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)
在哪個目錄下尋找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)
指定的時間線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)計信息
-?, --help show this help, then exit
輸出幫助信息
下面是測試機上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個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
注意第一條記錄,上一個LSN為1/47FFFFF8(prev 1/47FFFFF8),提示上一page最后一個XLOG Record存儲在本頁的XLogLongPageHeaderData中,存儲的空間大小可以從該XLOG Record的LSN(1/48000070)和XLogLongPageHeaderData的大小(40B)推算獲得,有興趣的同學可以自行計算.
注:LSN的計算請參照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工具”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
文章題目:怎么使用PostgreSQL中pg_waldump工具-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://muchs.cn/article12/pgdgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、自適應(yīng)網(wǎng)站、動態(tài)網(wǎng)站、網(wǎng)站策劃、定制開發(fā)、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容