1. 程式人生 > >The database cluster was initialized with RELSEG_SIZE 1048576, but the server was compiled with RELSEG_SIZE 8388608

The database cluster was initialized with RELSEG_SIZE 1048576, but the server was compiled with RELSEG_SIZE 8388608

database physical 都在 script back 對應關系 com 發現 logs

  由於一次誤操作,將線上機器的數據庫程序目錄刪除,雖然不影響程序的正常使用,數據也未丟失,但後面如果出現服務器宕機或數據庫宕機,數據庫將無法啟動,而且數據庫對應的編譯參數也已無法查看,所以征得開發同意後,關閉數據庫,重新編譯數據庫程序,嘗試可能正確的參數。其中最重要的是關於數據大小的幾個:

  --with-blocksize=BLOCKSIZE
                          set table block size in kB [8]
  --with-segsize=SEGSIZE  set table segment size in GB [1]
  --with-wal-blocksize=BLOCKSIZE
                          set WAL block size 
in kB [8] --with-wal-segsize=SEGSIZE set WAL segment size in MB [16]

如有一個不一致,數據庫程序將無法啟動數據庫。

  剛開始,是根據線上常見幾個參數做的嘗試,有幾次報錯,其中block size和wal blocks大小不一致的可以很簡單識別,但報的錯誤中有報出RELSEG_SIZE不一致的,百度、google都沒查到這個對應的哪個參數,好在數據都在,後面通過查看數據表的大小來確定了--with-wal-segsize大小為64,--with-segsize大小為8。

  事後,查看相關資料,發現下面幾個對應關系:

XLOG_SEG_SIZE  ----  --with-wal-segsize
RELSEG_SIZE    ----  --with-segsize
XLOG_BLCKSZ    ----  --with-wal-blocksize
BLCKSZ         ----  --with-blocksize

  感覺pg的資料還是較少,遇到一些報錯的時候,只能看代碼中有無說明:

  下面是在src\backend\storage\smgr\md.c中查到的說明:


The magnetic disk storage manager keeps track of open file
descriptors in its own descriptor pool. This is done to make it
easier to support relations that are larger than the operating
system‘s file size limit (often 2GBytes). In order to do that,
we break relations up into "segment" files that are each shorter than
the OS file size limit. The segment size is set by the RELSEG_SIZE
configuration constant in pg_config.h.

  在src\include\access\xlog_internal.h查到:

  The XLOG is split into WAL segments (physical files) of the size indicated
  by XLOG_SEG_SIZE.

  編譯數據庫後的參數可以通過pg_controldata和pg_config查看。但由於沒有了應用程序,所以也就沒有了這個渠道。pg_controldata是讀取的pg_control file的信息,但pg_control是二進制文件,無法查看,使用strings查看顯示為空,說明其中沒有可以直接打印的信息。之前了解過丟失pg_control文件如何恢復,至於從pg_control 文件恢復配置信息,後面再研究一下。

參考:

src\backend\storage\smgr\md.c

src\include\access\xlog_internal.h

The database cluster was initialized with RELSEG_SIZE 1048576, but the server was compiled with RELSEG_SIZE 8388608