ITPub博客

首页 > Linux操作系统 > Linux操作系统 > dataguard角色转换—switchover

dataguard角色转换—switchover

原创 Linux操作系统 作者:wang_0720 时间:2013-11-06 14:53:35 0 删除 编辑
本文用的oracle为10g2
SYS>select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 
   10.2.0.1.0    Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
一 将主库切换为standby role
确定primary数据库是否支持switchover操作
SYS>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
显示结果表示primary数据库支持转换为standby角色
将primary数据库转换为standby角色
SYS>alter database commit to switchover to physical standby with session shutdown;
Database altered.
将primary数据库重启到mount状态
SYS>shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SYS>startup mount
ORACLE instance started.
Total System Global Area  595591168 bytes
Fixed Size            1220748 bytes
Variable Size          180359028 bytes
Database Buffers      406847488 bytes
Redo Buffers            7163904 bytes
Database mounted.
将备库切换为primary role
确定待转换的standby数据库是否支持switchover操作
SYS>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
显示结果表示standby数据库支持转换为primary角色
将standby转换为primary角色
SYS>alter database commit to switchover to primary;
Database altered.
角色转换完成,启动数据库
SYS>shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SYS>startup
ORACLE instance started.
Total System Global Area  268435456 bytes
Fixed Size            1218868 bytes
Variable Size           92276428 bytes
Database Buffers      167772160 bytes
Redo Buffers            7168000 bytes
Database mounted.
Database opened.
原主库(新的备库)以REDO LOG实时APPLY的方式开启和主数据库的同步
SYS>alter database recover managed standby database using current logfile disconnect from session;
Database altered
三 同步测试
查看当前数据库的角色及数据库名
select database_role,db_unique_name from v$database;
新primary
scott用户下有这些表
SYS>select table_name from all_tables where owner='SCOTT';
TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE

新的standby
SYS>alter database recover managed standby database cancel;
Database altered.
SYS>alter database open read only;
Database altered.
scott用户下有这些表
SYS>select table_name from all_tables where owner='SCOTT';
TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE

新primary
在scott用户下创建表e
SYS>create table scott.e as select * from scott.emp;
Table created.
SYS>select table_name from all_tables where owner='SCOTT';
TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE
E
新standby
应用redo log日志
SYS>alter database recover managed standby database using current logfile disconnect from session;
Database altered.
查看同步时间
SYS>select name,value from v$dataguard_stats;
NAME                 VALUE
-------------------------------- ----------------------------------------------------------------
apply finish time
apply lag             +00 00:03:19
estimated startup time         8
standby has been open         Y
transport lag             +00 00:00:00
待同步完成即apply lag值为+00 00:00:00时停止日志应用
SYS>alter database recover managed standby database cancel;
Database altered.
以只读方式打开数据库
SYS>alter database open read only;
Database altered.
查看是否有e表生成
SYS>select table_name from all_tables where owner='SCOTT';

TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE
E
standby有e表生成,结果表明同步成功
四 错误处理
SYS>alter database commit to switchover to primary with session shutdown wait;
alter database commit to switchover to primary with session shutdown wait
*
ERROR at line 1:
ORA-16139: media recovery required
解决:
alter database recover managed standby database finish
alter database commit to switchover to primary;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27181165/viewspace-775871/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    111
  • 访问量
    907411