2008年5月8日星期四

DG主备库切换

连不上主库,查看bdump下的日志,发觉链接不上。而备库的bdump下同样显示的disconnect,无奈重启主库,发觉仍旧不能连上,查看dmesg网卡坏了。。。。不过刚好,给我个主备库切换的机会。
因为主库的网卡以坏,同时也没有其他的生产用机连接,因为是测试机^ ^所以开始切换。根据piner在书中提到的switchover脚本,开始进行切换。基于以上原因我就没有修改备库IP。

$ more switchprimary.sh
#!/bin/sh ORACLE_BASE=/SERVER/ora9;export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/9.2;export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH;export PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib; LD_LIBRARY_PATH
ORACLE_SID=ora9i; export ORACLE_SID
ORACLE_NLS=$ORACLE_HOME/ocommon/nls/admin/data; export ORACLE_NLS
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK; export NLS_LANG NLS_DATE_FORMAT='yyyy-mm-dd
hh24:mi:ss';export NLS_DATE_FORMAT

$ORACLE_HOME/bin/sqlplus /nolog <

startup pfile=?/dbs/initora9i.ora_pri
exit
EOF
lsnrctl stop
listenerdb lsnrctl start

但是服务器由此出来的提示是ora-01153错误,然后我做了下查看
[oracle@ora9-2 oracle]$ oerr ora 01153
01153, 00000, "an incompatible media recovery is active"
// *Cause: Attempted to start an incompatible media recovery or open
resetlogs
// during media recovery or
RMAN backup . Media recovery sessions
// are incompatible if they
attempt to recover the same data file.
// Incomplete media
recovery or open resetlogs is incompatible with
// any media recovery.
Backup or restore by RMAN is incompatible
// with open
resetlogs
// *Action: Complete or cancel the other media recovery session or RMAN
backup

所以根据提示我有做了以下动作
[oracle@ora9-2 oracle]$recover managed standby database cancel;
[oracle@ora9-2 oracle]$ shutdown immediate;

但是似乎很不性,我shutdown了以后起来的时候用pfile启动到nomount但是alterdatabase到mount下是提示的这是备库的controlfile。如下错误:
ORA-01666: controlfile is for a standby database
之后又做了一次后提示ORA-01012: not logged on 。。 然后就开始飚血~~~~~~~~~~~
麻烦了,之后重启了机器,重启后就OK了,但是还是提示好了还是如此。我继续shutdown然后重新启动到原来的备库状态。。
startup nomount pfile = initora9i.ora_std
alter database mount standby database

这样就启动到了备库的状态了。那么余下的就是如何切换了,没有用piner提供的脚本而是google了下,这次我做
alter database commit to switchover to primary;

的时候提示
[oracle@ora9-2 oracle]$ oerr ora 16139
16139, 00000, "media recovery required"
// *Cause: The database has not been recovered through the end of log
stream.
// Graceful
switchover is not possible.
// *Action: Ensure that the entire log stream has been applied. If
appropriate,
// reissue the
graceful switchover command.

所以根据GOOGLE的经验,需进行以下操作
结束备库的管理恢复
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
如果报错,则执行
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH SKIP STANDBY
LOGFILE;
切换备库到主库
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SQL> shutdown immediate
SQL> startup mount
SQL> startup

至此切换成功
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY

很好,很强大
还需要增加三个REDO,和一个临时表空间

没有评论: