資料庫歸檔日誌管理方案

來源:互聯網
上載者:User

需求描述:
由於使用了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目錄下。

UNIX環境下應該在/sqllib/adm下

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.