码迷,mamicode.com
首页 > 其他好文 > 详细

崩溃恢复(crash recovery)与 AUTORESTART参数

时间:2014-12-20 18:18:46      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

       关于这个参数设置的影响,在生产系统中经历过两次:
       第一次是有套不太重要的系统安装在虚拟机,这套系统所有应用(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 IMMEDIATE
DB20000I  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 db2sys
db2inst1  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]$ db2start
12/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 limtdb
SQL0752N  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 terminate
DB20000I  The TERMINATE command completed successfully.
/* 6  再次启动时候报数据库不一致 */
[db2inst1@limt yunwei]$ db2 connect to limtdb
SQL1015N  The database is in an inconsistent state.  SQLSTATE=55025
/* 7  db2 ? SQL1015N 有一条建议: using the RESTART DATABASE command*/
[db2inst1@limt yunwei]$ db2 restart database limtdb
DB20000I  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 IMMEDIATE
DB20000I  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 db2sys
db2inst1  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]$ db2start
12/19/2014 08:16:35     0   0   SQL1063N  DB2START processing was successful.
SQL1063N  DB2START processing was successful.
[db2inst1@limt yunwei]$ db2 connect to limtdb
SQL0752N  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 terminate
DB20000I  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


崩溃恢复(crash recovery)与 AUTORESTART参数

标签:

原文地址:http://blog.csdn.net/lmt818583/article/details/42044087

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!