首页 > 代码库 > 崩溃恢复(crash recovery)与 AUTORESTART参数
崩溃恢复(crash recovery)与 AUTORESTART参数
关于这个参数设置的影响,在生产系统中经历过两次:
第一次是有套不太重要的系统安装在虚拟机,这套系统所有应用(DB2 WAS IHS)都配置到/etc/rc.local中,每次启动机器会自动拉起应用,然后有次虚拟机宕机,重启后检查了各个应用进程都正常启动,但是前台页面访问异常无法访问,然后到后台手动连接数据库报:
SQL1015N The database is in an inconsistent state. SQLSTATE=55025
根据SQL1015N提示:需要执行RESTART DATABASE DBNAME命令,执行后然后数据库可以正常连接
如果DB2数据库遭受断电或者异常关闭,数据库没有干净的关闭,那么数据库在启动的时候将会进行crash recovery. 但是如果数据库参数AUTORESTART设置为OFF的话,在启动数据库后DB2不会进行CRASH RECOVERY。关于crash recovery,在db2diag.log日志会有相关体现
第一次是有套不太重要的系统安装在虚拟机,这套系统所有应用(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参数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。