當(dāng)前位置:首頁 > IT技術(shù) > 數(shù)據(jù)庫 > 正文

記一次pg_rman備份postgresql數(shù)據(jù)庫報段錯誤的處理過程
2021-09-08 11:51:19

作者:瀚高PG實驗室(Highgo PG Lab)- 徐云鶴

數(shù)據(jù)庫備機前期穩(wěn)定執(zhí)行備份操作,成功無報錯。近期發(fā)現(xiàn)pg_rman無法完成備份,提示段錯誤并產(chǎn)生core文件。

通過執(zhí)行pg_rman debug模式定位到checkpoint后發(fā)生錯誤。

postgres@備機:~> pg_rman backup -b incremental -Z -F --keep-data-days=2 --standby-host=x.x.x.x4 --standby-port=5432 -h x.x.x.x3 -p 5432 -d postgres -U repuser -w --debug -c

DEBUG: the initially configured target database : SYSTEM_IDENTIFIER = 12345678902345678 
DEBUG: the system identifier of current target database : 12345678902345678 

DEBUG: the backup target database is the same as initial configured one.

DEBUG: destination directories of backup are initialized

DEBUG: checking PostgreSQL server version

DEBUG: server version is 10.0.3

DEBUG: checking block size setting

DEBUG: (query) SELECT current_setting($1)

DEBUG:  (param:0) = block_size

DEBUG: block size is 8192

DEBUG: checking block size setting

DEBUG: (query) SELECT current_setting($1)

DEBUG:  (param:0) = wal_block_size

DEBUG: wal block size is 8192

DEBUG: data checksum disabled on the initially configured database

INFO: copying database files

DEBUG: executing pg_start_backup()

DEBUG: (query) SELECT * from pg_walfile_name_offset(pg_start_backup($1, $2, $3))

DEBUG:  (param:0) = 2021-08-05 11:42:31 with pg_rman

DEBUG:  (param:1) = true

DEBUG:  (param:2) = false

DEBUG: backup start point is (WAL file: 00000001000004700000008C, xrecoff: 99072)

DEBUG: (query) SELECT * FROM pg_last_wal_replay_lsn()

DEBUG: (query) CHECKPOINT

段錯誤(core dumped) 

通過查詢源碼定位到是backup.c中執(zhí)行do_backup_database函數(shù)拋出的異常。

為定位到具體報錯行,工程師決定對pg_rman進(jìn)行重新編譯。并添加-g參數(shù),便于使用gdb進(jìn)行分析定位。

首先修改pg_rman源碼中Makefile文件中相關(guān)編譯參數(shù),找到如下行,在后邊添加-g關(guān)鍵字,保存。

PG_CPPFLAGS = -I$(libpq_srcdir) -lm -g

使用make &&make install 重新編譯安裝。

然后重新運行pg_rman備份命令,生成新的core文件。

通過gdb進(jìn)行調(diào)試,調(diào)試命令及結(jié)果如下。
記一次pg_rman備份postgresql數(shù)據(jù)庫報段錯誤的處理過程_數(shù)據(jù)庫報段錯誤
通過上邊結(jié)果定位到是dir.c的第95行pgFileNew函數(shù)執(zhí)行報錯,傳入這個函數(shù)的參數(shù)包括/sxxxxxxxxxxxx1,懷疑是該目錄引起的報錯,對該目錄進(jìn)行排查。

排查發(fā)現(xiàn)存在data目錄下存在一個軟連接,軟連接指向為當(dāng)前目錄,當(dāng)前目錄還存在一個軟連接指向自己,導(dǎo)致pg_rman讀取該目錄的時候造成死循環(huán)現(xiàn)象。

與相關(guān)人員進(jìn)行確認(rèn),是由于該文件創(chuàng)建錯誤。經(jīng)同意后進(jìn)行刪除。

驗證后問題不再出現(xiàn)。

至此問題解決。

本文摘自 :https://blog.51cto.com/u

開通會員,享受整站包年服務(wù)立即開通 >