[[toc]]
適用范圍
當文件系統異常等原因導致csnlog文件丟失或損壞,在沒有備份或者其它更合適的處理辦法時,可嘗試該文檔中的方法應急啟動數據庫。
問題概述
丟失csnlog文件,數據庫可以正常啟動,可讀,但新事務會報錯,導致數據庫實例終止
如下所示,提示csnlog pg_csnlog/000000000000文件不存在。
test=# create table t3(id int);
WARNING: AbortTransaction while in COMMIT state
ERROR: could not access status of transaction 27085 , nextXid is 27086
DETAIL: Could not open file “pg_csnlog/000000000000”: No such file or directory.
PANIC: could not access status of transaction 27085 , nextXid is 27086
DETAIL: Could not open file “pg_csnlog/000000000000”: No such file or directory.
ERROR: could not access status of transaction 27085 , nextXid is 27086
DETAIL: Could not open file “pg_csnlog/000000000000”: No such file or directory.
PANIC: could not access status of transaction 27085 , nextXid is 27086
DETAIL: Could not open file “pg_csnlog/000000000000”: No such file or directory.
The connection to the server was lost. Attempting reset: Failed.
問題原因
csnlog保存時事務提交邏輯時間戳,是事務系統正常運行不可缺少的組成部分,丟失將導致數據庫系統無法正常運行。
csn作用可參考文章
https://support.enmotech.com/article/1430/publish
解決方案
只有在 latestCompletedXid<=>nextXid 之間的事務才需要csn判斷可見性
latestCompletedXid 最后提交的事務ID
nextXid 事務系統下一個分配的事務ID(類似sequence last value)
重啟庫后,latestCompletedXid=nextXid,歷史數據不太可能需要csn判斷可見性
因此手工生成全為0的csnlog即可,每個文件256k。
dd if=/dev/zero of=data2/pg_csnlog/000000000000 bs=1024 count=256
再次起庫
gs_ctl start -D data2
test=# create table t3(id int);
CREATE TABLE
test=# \dt
List of relations
Schema | Name | Type | Owner | Storage
--------±-----±------±------±---------------------------------
public | t1 | table | omm | {orientation=row,compression=no}
public | t2 | table | omm | {orientation=row,compression=no}
public | t3 | table | omm | {orientation=row,compression=no}
(3 rows)
參考文檔
https://support.enmotech.com/article/1430/publish
可查看源碼




