DB2數據庫歸檔日誌的管理方案簡介(轉)

DB2數據庫歸檔日誌的管理方案簡介

 
   | |

導讀:由於使用了LOGRETAIN=ON數據庫配置,數據庫日誌文件將不會被刪除或循環利用,日誌文件越來越多,IBM建議用戶使用USEREXIT程序來管理日誌文件。

關鍵詞:LOGRETAIN=ON 數據庫 日誌文件 USEREXIT 管理

  需求描述

  由於使用了LOGRETAIN=ON數據庫配置,所以數據庫日誌文件將不會被數據庫從活動日誌目錄中自動刪除或循環利用,活動日誌目錄中的日誌文件將會越來越多,所以需要對該目錄下的日誌文件進行歸檔。

  問題分析

  將LOGRETAIN設置爲ON後,數據庫將支持前滾恢復。此時,系統中將會存在三種類型的日誌文件:

  活動日誌:該日誌包含尚未提交或回滾的事務單元的相關信息,以及已提交但尚未寫入數據庫文件的事務的信息。

  聯機存檔日誌:活動日誌中所有改動對正常處理已不需要,即該日誌中所記錄的事務都已提交併寫入數據庫文件時,該活動日誌轉換爲聯機存檔日誌。稱之爲聯機,是由於它們與活動日誌存放在同一個目錄下。

  脫機存檔日誌:將聯機存檔日誌從活動日誌目錄下Copy到另外的地方存檔,就稱爲脫機存檔日誌。這些日誌可能在數據庫前滾恢復的時候仍然需要。

  管理數據庫日誌的工作可以手工完成(即將聯機存檔日誌手工拷貝到某個archive目錄),也可由編寫USEREXIT程序自動維護。

  由於DB2對所有平臺都提供了相應的USEREXIT示例程序,而且非常易於修改和使用,所以IBM建議用戶使用USEREXIT程序來管理日誌文件。

  使用USEREXIT程序的方法

  要使用User exit program自動化log文件的archiving和retrieval過程:

  1. 設置database cfg參數logarchmeth1 爲USEREXIT。 connect to sample
update db cfg using logarchmeth1 USEREXIT
connect reset

  2. 創建user exit programs。該程序必須是一個名爲db2uext2的可執行文件。DB2在各種平臺上都提供了User Exit的示例程序,用戶可以通過直接修改該樣本文件來實現自己的user exit程序。

  在UNIX(R) based的系統中,該程序存放在sqllib/samples/c目錄下. There are four sample user exit programs for UNIX based systems:
? db2uext2.ctsm
This sample uses Tivoli(R) Storage Manager to archive and retrieve database log files.
? db2uext2.ctape
This sample uses tape media to archive and retrieve database log files .
? db2uext2.cdisk
This sample uses the operating system COPY command and disk media to archive and
retrieve database log files.
? db2uxt2.cxbsa
This sample works with the XBSA Draft 0.8 published by the X/Open group.
It can be used to archive and retrieve database log files. This sample is
only supported on AIX.
?

  在Windows(R) 系統中,該文件存放在sqllib/samples/c目錄下。 There are two sample user exit programs for Windows operating systems:
? db2uext2.ctsm
This sample uses Tivoli Storage Manager to archive and retrieve database log files.
? db2uext2.cdisk
This sample uses the operating system COPY command and disk media to archive
and retrieve database log files.

  3. 配置該示例程序,指定要將日誌文件Archive到哪個系統目錄中(在windows平臺下,程序中默認爲c:/mylogs)。 #define ARCHIVE_PATH "c://mylogs//"
#define RETRIEVE_PATH "c://mylogs//"
#define AUDIT_ERROR_PATH "c://mylogs//"

  4. 編譯該C文件。 cl db2uext2.c

  5. 拷貝db2uext2.exe到/SQLLIB/BIN目錄下。

  6. 在db2cmd中鍵入archive log for db sample user db2admin using duan1980命令強制執行log日誌歸檔任務。查看c:/mylogs目錄下有無日誌文件歸檔,驗證是否成功。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章