查询库状态:
SQL> select name,SWITCHOVER_STATUS,open_mode,PROTECTION_MODE,DATABASE_ROLE
from v$database;
验证archive log是否接收和 applied.
SQL> alter session set nls_datE_format='YYYY-MM-DD HH24:MI:SS';
select SEQUENCE#,DEST_ID,ARCHIVED,APPLIED,DELETED,
STATUS,FIRST_TIME from v$archived_log order by SEQUENCE#;
启动到管理模式:
SQL> shutdown immediate;
SQL> startup nomount
SQL> alter database mount standby database
SQL> recover managed standby database disconnect from session;
----------
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
10g以后,采用联机日志的传递传递方式,
SQL> recover managed standby database using current logfile disconnect from session;
启动到只读模式:
SQL> shutdown immediate;
SQL> startup nomount
SQL> alter database mount standby database
SQL> alter databae open read only;
在管理模式恢复到只读模式:
SQL> recover managed standby database cancel;
SQL> alter database open read only
在只读模式可以给数据库添加临时数据文件(在rman备份是没有备份的),想让standby提供只读服务或者切换成主库,最好先增加链式文件
SQL> alter tablespace temp add tempfile 'C:\oracle\product\10.2.0\oradata\dgtest\temp02.dbf' size 100m;
只读模式到管理模式
SQL> recover managed standby database disconnect from session;
在备库进行备份
1.停止应用程序,跳转到 read only模式,同坐backup database命令来备份数据库,这样数据库处于一致性模式
2. 备份完成后,备份控制文件
SQL> ALTER DATABASE BACKUP CONTROLFILE TO 'FILE NAME';
主备切换
正常切换 (switchover)
切换准备: 准备参数文件,平时应该备好,注意参数 fal_server,fal_client
先确认能否转换:
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
主 -> 备
$lsnrclt stop
杀光进程或者重启数据库
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> shutdown immediate;
SQL> startup nomount pfile ='';
SQL> alter database mount standby database;
SQL> recover managed standby database disconnect;
备 -> 主
SQL> alter database commit to switchover to primary with session shutdown;
SQL> shutdown immediate
SQL> startup pfile =''
如果考虑在主备库来回切换,要保证数据库版本一致,参数compatible一致
失败切换 (Failover)
主服务器不能使用情况下
在备库
SQL> recover managed standby database cancel;
--如果在备用库上有备用库日志文件,参考命令
SQL> alter database recover managed standby database finish; -- [force|wait|nowait] 10g or later
--没有备库日志文件[10gR2之前]
SQL> alter database recover managed standby database finish skip standby logfile;
--切换备库到主库
SQL> alter database commit to switchover to primary;
-- open
SQL> shutdown immediate;
SQL> startup pfile=''
如果还有为传递的归档日志或者主库的联机日志
SQL>alter database register logfile 'c:\...'
SQL>recover standby database;
强行切换(激活)
激活备用服务器,在重启数据库时,备库会resetlog。
SQL>alter system archive log current;
SQL>recover managed standby database cancel;
SQL>alter database activate standby database;
SQL>shutdown immediate;
SQL>startup pfile=''
-----
apply 主库redolog并强制切换
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
--选定redolog恢复
SQL> recover standby database until cancel;
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
/u01/oradata/dgtest/redo02.log
Log applied.
Media recovery complete.
recovery 完成之后就要failover了。
SQL>alter database activate standby database;
SQL>shutdown immediate;
SQL>startup pfile=''
-- http://hi.baidu.com/wa0362/blog/item/33e52912a91eadcbc2fd78b9.html
-- http://zf_wu.itpub.net/
-- 参考来源: 《oracle高可用环境》
--http://www.oracleblog.cn/study-note/reduce-the-data-loss-of-data-guard-when-failover/
相关视图
v$archive_dest
v$archive_dest_status
v$log_history
v$archvied_log
v$managed_standby
v$archive_gap