崩潰恢複(crash recovery)與 AUTORESTART參數,crashautorestart
關於這個參數設定的影響,在生產系統中經曆過兩次:
第一次是有套不太重要的系統安裝在虛擬機器,這套系統所有應用(DB2 WAS IHS)都配置到/etc/rc.local中,每次啟動機器會自動拉起應用,然後有次虛擬機器宕機,重啟後檢查了各個應用進程都正常啟動,但是前台頁面訪問異常無法訪問,然後到後台手動串連資料庫報:
SQL1015N The database is in an inconsistent state. SQLSTATE=55025
根據SQL1015N提示:需要執行RESTART DATABASE DBNAME命令,執行後然後資料庫可以正常串連
第二次是一套HA伺服器的主機電源故障發生系統切換,切換到備機後,檢查應用都正常被拉起,但是前台無法訪問,和第一次是相同的問題,AUTORESTART參數被設定了OFF
這個參數解釋如下:
如果DB2資料庫遭受斷電或者異常關閉,資料庫沒有乾淨的關閉,那麼資料庫在啟動的時候將會進行crash recovery. 但是如果資料庫參數AUTORESTART設定為OFF的話,在啟動資料庫後DB2不會進行CRASH RECOVERY。關於crash recovery,在db2diag.log日誌會有相關體現
下面重現這一情境:
/* 1 設定AUTORESTART為OFF */[db2inst1@limt ~]$ db2 UPDATE DATABASE CONFIGURATION for limtdb USING AUTORESTART OFF IMMEDIATEDB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.[db2inst1@limt ~]$ db2 get db cfg for limtdb|grep -i AUTORESTART Auto restart enabled (AUTORESTART) = OFF [db2inst1@limt yunwei]$ db2 connect to limtdb Database Connection Information Database server = DB2/LINUXX8664 10.1.0 SQL authorization ID = DB2INST1 Local database alias = LIMTDB/* 2 插入一條資料但不提交,為了資料庫處於不一致性 */[db2inst1@limt yunwei]$ db2 +c "insert into A values(15485,'asdas','asdas')"DB20000I The SQL command completed successfully.[db2inst1@limt yunwei]$ /* 3 kill資料庫,類比異常宕機情況 */[db2inst1@limt yunwei]$ ps -ef|grep db2sysdb2inst1 5287 5285 1 08:07 pts/1 00:00:04 db2sysc 0 db2inst1 5827 3612 0 08:12 pts/1 00:00:00 grep db2sys[db2inst1@limt yunwei]$ kill -9 5287/* 4 啟動資料庫,此時資料庫沒有進行崩潰恢複,因為AUTORESTART為OFF */[db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ db2start12/19/2014 08:13:04 0 0 SQL1063N DB2START processing was successful.SQL1063N DB2START processing was successful.[db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ /* 5 此處報錯是因為剛才的db2bp進程沒有terminate */[db2inst1@limt yunwei]$ db2 connect to limtdbSQL0752N Connecting to a database is not permitted within a logical unit of work when the CONNECT type 1 setting is in use. SQLSTATE=0A001[db2inst1@limt yunwei]$ db2 terminateDB20000I The TERMINATE command completed successfully./* 6 再次啟動時候報資料庫不一致 */[db2inst1@limt yunwei]$ db2 connect to limtdbSQL1015N The database is in an inconsistent state. SQLSTATE=55025/* 7 db2 ? SQL1015N 有一條建議: using the RESTART DATABASE command*/[db2inst1@limt yunwei]$ db2 restart database limtdbDB20000I The RESTART DATABASE command completed successfully. /* 8 資料庫可以正常串連*/[db2inst1@limt yunwei]$ db2 connect to limtdb Database Connection Information Database server = DB2/LINUXX8664 10.1.0 SQL authorization ID = DB2INST1 Local database alias = LIMTDB/* 9 以下是設定AUTORESTART為ON情況下,資料庫宕機重啟(不需要執行RESTART DATABASE) */[db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ db2 UPDATE DATABASE CONFIGURATION for limtdb USING AUTORESTART ON IMMEDIATEDB20000I The UPDATE DATABASE CONFIGURATION command completed successfully.[db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ db2 get db cfg for limtdb|grep -i AUTORESTART Auto restart enabled (AUTORESTART) = ON[db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ [db2inst1@limt yunwei]$ db2 +c "insert into A values(15485,'asdas','asdas')"DB20000I The SQL command completed successfully.[db2inst1@limt yunwei]$ ps -ef|grep db2sysdb2inst1 5870 5868 1 08:13 pts/1 00:00:03 db2sysc 0 db2inst1 6122 3612 0 08:16 pts/1 00:00:00 grep db2sys[db2inst1@limt yunwei]$ kill -9 5870[db2inst1@limt yunwei]$ db2start12/19/2014 08:16:35 0 0 SQL1063N DB2START processing was successful.SQL1063N DB2START processing was successful.[db2inst1@limt yunwei]$ db2 connect to limtdbSQL0752N Connecting to a database is not permitted within a logical unit of work when the CONNECT type 1 setting is in use.[db2inst1@limt yunwei]$ db2 terminateDB20000I The TERMINATE command completed successfully.[db2inst1@limt yunwei]$ db2 connect to limtdb Database Connection Information Database server = DB2/LINUXX8664 10.1.0 SQL authorization ID = DB2INST1 Local database alias = LIMTDB