dataguard成功实现物理switchover

一直都不能实现switchover,在看了不少文档后终于实现,当然只是照葫芦画瓢,原理还是不理解的

环境:
oracle 10g
thadgdb10  原primary=>physical standby
thadgdb9   原physical standby=>primary

1.现有状态
thadg10:
--环境、版本
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          SESSIONS ACTIVE

thadg9:
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE


2已经同步:
thadg10:
SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            49          SESSIONS ACTIVE

thadg9:
SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            49


3.开始对原primary操作
thadgdb10:
SQL> 
SQL> alter database commit to switchover to physical standby WITH SESSION SHUTDOWN; 

Database altered.

SQL> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> 
SQL> 
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  536870912 bytes
Fixed Size                  2085288 bytes
Variable Size             150998616 bytes
Database Buffers          377487360 bytes
Redo Buffers                6299648 bytes
SQL> alter database mount standby database;--以standby模式Mount

Database altered.

SQL> alter database recover managed standby database disconnect from session; --启动redo log的监听

Database altered.

SQL> 
SQL> select database_role,switchover_status from v$database;--检查状态,转换成功

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE

SQL> 


3.开始对原standby操作
thadgdb9:
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE


SQL> alter database commit to switchover to primary with session shutdown;--转换

Database altered.

SQL> select open_mode from v$database;--检查当前的open_mode

OPEN_MODE
----------
MOUNTED

SQL> shutdown immediate; --重新打开数据库
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  536870912 bytes
Fixed Size                  2085288 bytes
Variable Size             150998616 bytes
Database Buffers          377487360 bytes
Redo Buffers                6299648 bytes
Database mounted.
Database opened.
SQL> select database_role,switchover_status from v$database;--检查状态

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

SQL> 


4.检查当前的dataguard是否正常
thadgdb9:
--检查arch dest是否报错
SQL> select status,target,archiver,error,process from v$archive_dest; 

STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
VALID     PRIMARY ARCH
                                                                  ARCH

VALID     STANDBY LGWR
                                                                  LGWR

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH


10 rows selected.

SQL> 
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PRIMARY          TO STANDBY

SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            53

SQL> alter system switch logfile;

System altered.

SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            54

thadgdb10:
SQL> select database_role,switchover_status from v$database;

DATABASE_ROLE    SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY SESSIONS ACTIVE

SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            53

SQL> select max(sequence#) from v$archived_log; 

MAX(SEQUENCE#)
--------------
            54

大功告成!

留下点东西:
1.为什么我经常遇到SESSIONS ACTIVE的情况?
2.要确保strandby ok的情况下再startup primary,不然会遇到ORA-03113: end-of-file on communication channel
SQL> select status,target,archiver,error,process from v$archive_dest;

STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
VALID     PRIMARY ARCH
                                                                  ARCH

ERROR     STANDBY LGWR
ORA-03113: end-of-file on communication channel                   LGWR

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH

INACTIVE  PRIMARY ARCH
                                                                  ARCH


STATUS    TARGET  ARCHIVER
--------- ------- ----------
ERROR                                                             PROCESS
----------------------------------------------------------------- ----------
INACTIVE  PRIMARY ARCH
                                                                  ARCH


10 rows selected.

3.以只读模式打开standby以后再作讨论

参考链接(各参考一部分,请按照实际情况操作):
盖老师的文章,就是实在,可读性高!
swtich over的一些操作

你可能感兴趣的:(oracle,sql,linux,.net,Blog)