standby 管理和维护
查询库状态:
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';
SQL>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
先确认能否转换:
SQL>select switchover_status from v$database;
主 -> 备
$lsnrclt stop
杀光进程或者重启数据库
SQL> alter system archive log current;(多次执行)
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> shutdown immediate;
SQL> startup nomount;
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
如果考虑在主备库来回切换,要保证数据库版本一致,参数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
如果还有未传递的归档日志或者主库的联机日志
SQL>alter database register logfile 'c:\...';
SQL>recover standby database;
强行切换(激活)
主库执行:
SQL>alter system archive log current; (多次执行)
备库执行:
激活备用服务器,在重启数据库时,备库要resetlog。
SQL>recover managed standby database cancel;
SQL>alter database activate standby database;
SQL>shutdown immediate;
SQL>startup
-----
apply 主库redolog并强制切换
SQL> alter database recover managed standby database cancel;
--选定redolog恢复
SQL> recover standby database until cancel;
Specify log: {=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=''
相关视图
v$archive_dest
v$archive_dest_status
v$log_history
v$archvied_log
v$managed_standby
v$archive_gap
文章出自:http://hi.baidu.com/dbaeyes/blog/item/740c3bfb3e0d5361034f568e.html
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11134237/viewspace-631338/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/11134237/viewspace-631338/