DB2的日誌使用通常有兩種方式,既稱之為迴圈日誌,也就是不採用歸檔記錄模式,另外一種就是歸檔記錄模式,預設是迴圈記錄模式,也就是無法進行日誌歸檔或線上備份。通常來說決定DB2日誌配置的幾個database層級的參數如下:
當前的資料庫版本為:
[db2inst1@localhost ]$ db2level
DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL09075"
with level identifier "08060107".
Informational tokens are "DB2 v9.7.0.5", "s111017", "IP23291", and Fix Pack
"5".
Product is installed at "/opt/ibm/db2/V9.7".
[db2inst1@localhost ]$ db2 get db cfg|grep -i log
Log retain for recovery status = NO
User exit for logging status = YES
Log buffer size (4KB) (LOGBUFSZ) = 256
Log file size (4KB) (LOGFILSIZ) = 2000
Number of primary log files (LOGPRIMARY) = 20
Number of secondary log files (LOGSECOND) = 30
Changed path to log files (NEWLOGPATH) =
Path to log files = /home/db2inst1/db2inst1/NODE0000/SQL00001/SQLOGDIR/
Overflow log path (OVERFLOWLOGPATH) =
Mirror log path (MIRRORLOGPATH) =
First active log file = S0000001.LOG
Block log on disk full (BLK_LOG_DSK_FUL) = NO
Block non logged operations (BLOCKNONLOGGED) = NO
Percent max primary log space by transaction (MAX_LOG) = 0
Num. of active log files for 1 active UOW(NUM_LOG_SPAN) = 0
Percent log file reclaimed before soft chckpt (SOFTMAX) = 100
Log retain for recovery enabled (LOGRETAIN) = OFF
User exit for logging enabled (USEREXIT) = OFF
HADR log write synchronization mode (HADR_SYNCMODE) = NEARSYNC
First log archive method (LOGARCHMETH1) = DISK:/db2src/TS/backup/
Options for logarchmeth1 (LOGARCHOPT1) =
Second log archive method (LOGARCHMETH2) = OFF
Options for logarchmeth2 (LOGARCHOPT2) =
Failover log archive path (FAILARCHPATH) =
如上常用的參數介紹如下:
LOGPRIMARY+LOGSECOND是記錄檔的個數,而每個記錄檔的大小由LOGFILSIZ參數設定,如上當前的記錄檔大小為2000 pages,而page大小為4K,所以每個記錄檔為8M,總共的日誌空間為400M,NEWLOGPATH參數決定了記錄檔存放目錄路徑,修改後可以動態生效。
First active log file就是指DB當前使用的活動紀錄檔案名稱
MAX_LOG 指定單個事物可以使用主日誌空間的百分比,當達到這個百分比後,這個事物就得被復原,預設設定為0,也就是單個交易記錄空間使用不受限制,可以使用主附日誌的所有空間。
SOFTMAX 指定軟檢查點頻率和範圍,單位為一個記錄檔大小的百分比,100也就是一個記錄檔,當發生資料庫崩潰恢複時,需要保持一致狀態,就會發生崩潰恢複,需要使用指定記錄檔數來做恢複,當然日誌量越小恢複就越快,通常保持預設值。
LOGARCHMETH1 這個即設定歸檔的方式,可以指定DISK、TSM等參數。
上面大概介紹了參數設定,那麼如何配置DB2歸檔呢?
其實DB2的歸檔配置比較簡單,只需要需要修改LOGARCHMETH1參數即可如下:
[db2inst1@localhost backup]$ db2 update db cfg using LOGARCHMETH1 'disk:/db2src/TS/backup'
DB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.
SQL1363W One or more of the parameters submitted for immediate modification
were not changed dynamically. For these configuration parameters, all
applications must disconnect from this database before the changes become
effective.
但是修改了這個參數還是無法生效的,需要執行重啟資料庫這裡直接重啟執行個體:
[db2inst1@localhost backup]$ db2stop force
11/25/2013 22:17:02 0 0 SQL1064N DB2STOP processing was successful.
SQL1064N DB2STOP processing was successful.
[db2inst1@localhost backup]$ db2start
11/25/2013 22:17:07 0 0 SQL1063N DB2START processing was successful.
SQL1063N DB2START processing was successful.
[db2inst1@localhost backup]$ db2 connect to sample
SQL1116N A connection to or activation of database "SAMPLE" cannot be made
because of BACKUP PENDING. SQLSTATE=57019
發現重啟後還是不能串連,這時資料庫狀態為BACKUP PENDING,需要做一個備份,記住是離線備份。
更多詳情見請繼續閱讀下一頁的精彩內容:
推薦閱讀:
DB2資料庫效能調整和最佳化(第1、2版) PDF
DB2資料庫效能最佳化介紹