PRIMARY数据库和STANDBY数据库采用的都是RAC 11.1.0.6 for Solaris10 sparc,共享存储PRIMARY数据库采用VOLUMN CLUSTER MANAGER,而STANDBY数据库使用ASM。
在部署之前,首先检查目前的PRIMARY数据库是否满足切换后逻辑STANDBY的角色,发现目前PRIMARY数据库还没有建立STANDBY LOGFILE,因此首先创建PRIMARY数据库的STANDBY LOGFILE:
root@newtrade1 # cd /dev/vx/rdsk/datavg
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo1_1_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo1_2_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo1_3_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo2_1_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo2_2_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # vxassist -g datavg make rac11g_standby_redo2_3_1_1g1025muser=oracle group=oinstall mode=660
root@newtrade1 # su - oracle
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ sqlplus "/ as sysdba"
SQL*Plus: Release 11.1.0.6.0 - Production on星期四9月18 14:45:14 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
连接到:
Oracle Database11gEnterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> alter database add standby logfile group 5 '/dev/vx/rdsk/datavg/rac11g_standby_redo1_1_1_1g' size1g;
数据库已更改。
SQL> alter database add standby logfile group 6 '/dev/vx/rdsk/datavg/rac11g_standby_redo1_2_1_1g' size1g;
数据库已更改。
SQL> alter database add standby logfile group 7 '/dev/vx/rdsk/datavg/rac11g_standby_redo1_3_1_1g' size1g;
数据库已更改。
SQL> alter database add standby logfile group 8 '/dev/vx/rdsk/datavg/rac11g_standby_redo2_1_1_1g' size1g;
数据库已更改。
SQL> alter database add standby logfile group 9 '/dev/vx/rdsk/datavg/rac11g_standby_redo2_2_1_1g' size1g;
数据库已更改。
SQL> alter database add standby logfile group 10 '/dev/vx/rdsk/datavg/rac11g_standby_redo2_3_1_1g' size1g;
数据库已更改。
下面准备实施SWITCHOVER切换。
首先检查主库的状态:
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- ------------------------------ ------------------------------
RAC11G READ WRITE PRIMARY NONE rac11g rac11g_s
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
SQL> select inst_id,
2 username,
3 program,
4 module
5 from gv$session
6 where username is not null;
INST_ID USERNAME PROGRAM MODULE
---------- ---------- ------------------------------ ------------------------------
1 SYS sqlplus@newtrade1 (TNS V1-V3) sqlplus@newtrade1 (TNS V1-V3)
1 SYS racgimon@newtrade1 (TNS V1-V3) racgimon@newtrade1 (TNS V1-V3)
1 SYS oracle@newtrade1 (PZ99) sqlplus@newtrade1 (TNS V1-V3)
1 SYS racgimon@newtrade1 (TNS V1-V3) racgimon@newtrade1 (TNS V1-V3)
2 SYS oracle@newtrade2 (PZ99) sqlplus@newtrade1 (TNS V1-V3)
2 SYS racgimon@newtrade2 (TNS V1-V3) racgimon@newtrade2 (TNS V1-V3)
已选择6行。
虽然SWITCHOVER的状态为SESSION ACTIVE,但是剩下的会话已经没有其它用户的会话了,需要注意的是,目前实例2仍然启动,在执行SWITCHOVER的时候,应该只保留一个实例:
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
rac11g2
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE例程已经关闭。
检查STANDBY数据库状态,确保LOGICAL STANDBY数据库打开,且处于应用SQL的状态:
SQL> select instance_name, status from gv$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g1 OPEN
rac11g2 OPEN
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- -------------------------
RAC11G_L READ WRITE LOGICAL STANDBY ALL rac11g_s rac11g
SQL> select * from v$logstdby_state;
PRIMARY_DBID SESSION_ID REALTIME_APPLY STATE
------------ ---------- --------------- ------------------------------
1712482917 1 Y IDLE
关闭实例2:
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
rac11g2
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE例程已经关闭。
下面回到PRIMARY数据库,准备切换:
SQL> alter database prepare to switchover to logical standby;
数据库已更改。
SQL> select name, switchover_status from v$database;
NAME SWITCHOVER_STATUS
--------- --------------------
RAC11G PREPARING SWITCHOVER
在STANDBY库进行准备切换:
SQL> alter database prepare to switchover to primary;
Database altered.
SQL> select name, switchover_status from v$database;
NAME SWITCHOVER_STATUS
--------- --------------------
RAC11G_L PREPARING SWITCHOVER
再次检查主库,switchover_status应该变成TO LOGICAL STANDBY:
SQL> select name, switchover_status from v$database;
NAME SWITCHOVER_STATUS
--------- --------------------
RAC11G TO LOGICAL STANDBY
将主库切换为LOGICAL STANDBY数据库:
SQL> alter database commit to switchover to logical standby;
数据库已更改。
检查逻辑STANDBY数据库的状态是否为TO PRIMARY:
SQL> select name, switchover_status from v$database;
NAME SWITCHOVER_STATUS
--------- --------------------
RAC11G_L TO PRIMARY
下面可以将STANDBY数据库切换为PRIMARY数据库:
SQL> alter database commit to switchover to primary;
Database altered.
最后打开新逻辑STANDBY数据库的SQL应用即可:
SQL> alter database start logical standby apply immediate;
数据库已更改。
检查逻辑STANDBY运行情况:
SQL> select * from v$logstdby_state;
PRIMARY_DBID SESSION_ID REALTIME_APPLY STATE
------------ ---------- --------------- ------------------------------
3515162368 1 Y IDLE
下面可以将主库和STANDBY数据库的第二实例启动:
SQL> startup
ORACLE例程已经启动。
Total System Global Area 1.7108E+10 bytes
Fixed Size 2101632 bytes
Variable Size 3478638208 bytes
Database Buffers 1.3623E+10 bytes
Redo Buffers 4431872 bytes
数据库装载完毕。
数据库已经打开。
SQL> select instance_name, status from gv$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g2 OPEN
rac11g1 OPEN
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- -------------------------
RAC11G_L READ WRITE PRIMARY NONE rac11g_s rac11g
新STANDBY数据库打开第二实例后:
SQL> startup
ORACLE例程已经启动。
Total System Global Area 1.7108E+10 bytes
Fixed Size 2101632 bytes
Variable Size 4149726848 bytes
Database Buffers 1.2952E+10 bytes
Redo Buffers 4431872 bytes
数据库装载完毕。
数据库已经打开。
SQL> select instance_name, status from gv$instance;
INSTANCE_NAME STATUS
---------------- ------------
rac11g2 OPEN
rac11g1 OPEN
SQL> select name,
2 open_mode,
3 database_role,
4 guard_status,
5 db_unique_name,
6 primary_db_unique_name
7 from v$database;
NAME OPEN_MODE DATABASE_ROLE GUARD_S DB_UNIQUE_NAME PRIMARY_DB_UNIQUE_NAME
--------- ---------- ---------------- ------- --------------- -------------------------
RAC11G READ WRITE LOGICAL STANDBY ALL rac11g rac11g_s
至此,RAC环境的LOGICAL STANDBY的SWICHOVER切换完成。
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html