以下给大家展现一下10g物理standby主备之间通过switchover方式进行切换的详细步骤,供参考。
1、主库检查是否为“TO STANDBY”状态,若不是,需要重新启动一下主库(主库ora10g操作)
sys@ora10g> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
sys@ora10g> startup force ;
ORACLE instance started.
Total System Global Area 104857600 bytes
Fixed Size 1266056 bytes
Variable Size 83889784 bytes
Database Buffers 16777216 bytes
Redo Buffers 2924544 bytes
Database mounted.
Database opened.
sys@ora10g> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2.将primary转换为standby角色(主库ora10g操作)
sys@ora10g> alter database commit to switchover to physical standby;
Database altered.
3.原主库重启动到mount状态(原主库ora10g操作)
NotConnected@> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
NotConnected@>
NotConnected@> startup mount;
ORACLE instance started.
Total System Global Area 104857600 bytes
Fixed Size 1266056 bytes
Variable Size 88084088 bytes
Database Buffers 12582912 bytes
Redo Buffers 2924544 bytes
Database mounted.
4.检查原备库是否为“TO PRIMARY”状态,如果为“SWITCHOVER PENDING”状态,需要先进行一下恢复再切换 (待切换备库ora10gdg操作)
ora10g@linux5 /home/oracle$ export ORACLE_SID=ora10gdg
ora10gdg@linux5 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:26:53 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
NotConnected@> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SWITCHOVER PENDING
NotConnected@> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
NotConnected@> alter database recover managed standby database disconnect from session;
Database altered.
NotConnected@> alter database recover managed standby database cancel;
Database altered.
NotConnected@> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
5.原备库转换角色到primary (待切换备库ora10gdg操作)
NotConnected@> alter database commit to switchover to primary;
Database altered.
6.主备切换完成,open新的primary数据库 (待切换备库ora10gdg操作)
NotConnected@> alter database open;
Database altered.
7.最后验证阶段
1).新的primary库在sec用户创建一个新表test_new
sec@ora10g> create table test_new (a int);
Table created.
sec@ora10g> insert into test_new values ( 100 );
1 row created.
sec@ora10g> commit;
Commit complete.
sec@ora10g> select * from test_new;
A
----------
100
sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> alter system switch logfile;
System altered.
sys@ora10g> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
69
2).查看新standby库,验证切换是否成功
ora10gdg@linux5 /home/oracle$ export ORACLE_SID=ora10g
ora10g@linux5 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:55:09 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
NotConnected@> alter database recover managed standby database disconnect from session;
Database altered.
NotConnected@> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
69
NotConnected@> alter database recover managed standby database cancel;
Database altered.
NotConnected@> alter database open read only;
Database altered.
NotConnected@> conn sec/sec
Connected.
sec@ora10g> select * from test_new;
A
----------
100
OK!到此主备之间的switchover方式切换成功。
secooler
1、主库检查是否为“TO STANDBY”状态,若不是,需要重新启动一下主库(主库ora10g操作)
sys@ora10g> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
sys@ora10g> startup force ;
ORACLE instance started.
Total System Global Area 104857600 bytes
Fixed Size 1266056 bytes
Variable Size 83889784 bytes
Database Buffers 16777216 bytes
Redo Buffers 2924544 bytes
Database mounted.
Database opened.
sys@ora10g> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2.将primary转换为standby角色(主库ora10g操作)
sys@ora10g> alter database commit to switchover to physical standby;
Database altered.
3.原主库重启动到mount状态(原主库ora10g操作)
NotConnected@> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
NotConnected@>
NotConnected@> startup mount;
ORACLE instance started.
Total System Global Area 104857600 bytes
Fixed Size 1266056 bytes
Variable Size 88084088 bytes
Database Buffers 12582912 bytes
Redo Buffers 2924544 bytes
Database mounted.
4.检查原备库是否为“TO PRIMARY”状态,如果为“SWITCHOVER PENDING”状态,需要先进行一下恢复再切换 (待切换备库ora10gdg操作)
ora10g@linux5 /home/oracle$ export ORACLE_SID=ora10gdg
ora10gdg@linux5 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:26:53 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
NotConnected@> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SWITCHOVER PENDING
NotConnected@> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16139: media recovery required
NotConnected@> alter database recover managed standby database disconnect from session;
Database altered.
NotConnected@> alter database recover managed standby database cancel;
Database altered.
NotConnected@> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
5.原备库转换角色到primary (待切换备库ora10gdg操作)
NotConnected@> alter database commit to switchover to primary;
Database altered.
6.主备切换完成,open新的primary数据库 (待切换备库ora10gdg操作)
NotConnected@> alter database open;
Database altered.
7.最后验证阶段
1).新的primary库在sec用户创建一个新表test_new
sec@ora10g> create table test_new (a int);
Table created.
sec@ora10g> insert into test_new values ( 100 );
1 row created.
sec@ora10g> commit;
Commit complete.
sec@ora10g> select * from test_new;
A
----------
100
sec@ora10g> conn / as sysdba
Connected.
sys@ora10g> alter system switch logfile;
System altered.
sys@ora10g> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
69
2).查看新standby库,验证切换是否成功
ora10gdg@linux5 /home/oracle$ export ORACLE_SID=ora10g
ora10g@linux5 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Sat Mar 28 08:55:09 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, Data Mining and Real Application Testing options
NotConnected@> alter database recover managed standby database disconnect from session;
Database altered.
NotConnected@> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
69
NotConnected@> alter database recover managed standby database cancel;
Database altered.
NotConnected@> alter database open read only;
Database altered.
NotConnected@> conn sec/sec
Connected.
sec@ora10g> select * from test_new;
A
----------
100
OK!到此主备之间的switchover方式切换成功。
secooler
09.03.27
本文转自东方之子736651CTO博客,原文链接: http://blog.51cto.com/ecloud/1381045,如需转载请自行联系原作者