不停机 data guard 及 switchover

DATA GUARD实施文档:

 

环境描述:

服务器1:一个运行的OLTP数据库,不能停机。数据库安装归属人 ora ,ORACLE_SID=research

服务器2:一个已经安装了数据库的服务器,有一个数据库在跑,不能影响。数据库安装归属人 oracle ,ORACLE_SID=orcl

 

服务器基本环境

 

Hostmachine IP

OS release

sys passwd

database release

database SID

databse unique_name

DG role

installers

192.168.0.15

Red Hat 5

oracle

oracle Enterprise 10.2.0.1.0

orcl

orcl

standby

oracle

192.168.0.16

Red Hat 5

oracle

oracle Enterprise 10.2.0.1.0

research

research

primary

ora

 

实施步骤:

DG我们的主备都是用SPFILE启动实例的。

primary端:

一、强制数据库logging和开启archivelog

SQL> archive log list;
SQL> shutdown immediate
;
SQL> startup mount
;
SQL> alter database archivelog;
SQL> archive log list;

SQL> alter database force logging;

SQL> select force_logging from v$database;

SQL> altet database open;

二、          创建或是修改OS密码文件:

  orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=30 force=y

然后SCP到standby端去。 (注意要修改ORACLE_SID 因为我们这里的SID 不同。直接MV 就可以了。)

三、备份控制文件:

Sql>alter database create standby controlfie  as  ‘/u01/backup/control.ctl’;或是RMAN 备份

RMAN>backup current controlfile for standby format =‘/u01/backup/control.ctl’;(我是用RMAN全库备份带上controlfile 所以没有单独进行备份)。然后SCP给standby注意复制成多份,并MV到parameter file 指定位置。

修改listener.ora 和 tnsname.ora

Listener.ora 加上静态监听 (主备都加上静态监听)

# listener.ora Network Configuration File: /opt/oracle/product/10.2.0/db_1/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /opt/oracle/product/10.2.0/db_1)

      (PROGRAM = extproc)

    )

        (SID_DESC =

     (GLOBAL_DBNAME = research.bj)     

      (ORACLE_HOME =  /opt/oracle/product/10.2.0/db_1)     

      (SID_NAME = research)     

      )

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

      (ADDRESS = (PROTOCOL = TCP)(HOST = dg-pp)(PORT = 1521))

    )

  )

 

这里注意细节,SID_DESC 不能顶格,还有括号不能少哦!GLOBAL_DBNAME=service_name

 

Tnsname.ora

# tnsnames.ora Network Configuration File: /opt/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

 

 

EXTPROC_CONNECTION_DATA =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

    )

    (CONNECT_DATA =

      (SID = PLSExtProc)

      (PRESENTATION = RO)

    )

  )

 

 

orcl =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.16)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

 

research =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.15)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = research.bj)

    )

  )

 

这里注意orcl必须顶格,否则报错

五、修改parameter file

 

 

research.__db_cache_size=310378496

research.__java_pool_size=4194304

research.__large_pool_size=4194304

research.__shared_pool_size=134217728

research.__streams_pool_size=0

*.audit_file_dest='/opt/oracle/admin/research/adump'

*.background_dump_dest='/opt/oracle/admin/research/bdump'

*.compatible='10.2.0.1.0'

*.control_files='/opt/oracle/oradata/research/control01.ctl','/opt/oracle/oradata/research/control02.ctl','/opt/oracle/oradata/research/control03.ctl'

*.core_dump_dest='/opt/oracle/admin/research/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=8

*.db_name='research'

*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.dispatchers='(PROTOCOL=TCP) (SERVICE=researchXDB)'

*.job_queue_processes=10

*.open_cursors=300

*.pga_aggregate_target=150994944

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=455081984

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/opt/oracle/admin/research/udump'

 

####以下是主库修改的参数部分###

*.fal_client='research'

*.fal_server='orcl'

*.log_archive_config='DG_CONFIG=(research,orcl)'

*.log_archive_dest_1='LOCATION=/arch  VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=research'

*.log_archive_dest_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'

*.log_archive_dest_state_1='ENABLE'

*.log_archive_dest_state_2='DEFER'

*.standby_file_management='AUTO'

 

因为我们是在线搭建DG,所以我们就直接命令修改了,但是DB_UNIQUE_NAME需要重启才能生效,所以我们就按默认research好了

 

以下为主库在线修改命令:

alter system set fal_client='research';

alter system set fal_server='orcl';

alter system set log_archive_config='DG_CONFIG=(research,orcl)';

alter system set log_archive_dest_1='LOCATION=/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=research';

alter system set log_archive_dest_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl';

alter system set log_archive_dest_state_1='ENABLE';

alter system set log_archive_dest_state_2='DEFER'; ##(这里为什么要DEFER,因为ENABLE自动传输会照成我们RMAN全库备份长时间等待,ENABLE他就会传输,可是咱们还没有搭建成功呢,所以这里先DEFER,等我们DG搭建好,我们在修改成ENABLE,然日志输出)##

alter system set standby_file_management='AUTO';

 

六、RMAN备份全库

 

RUN {

allocate channel c1 type disk;

allocate channel c2 type disk;

sql 'alter system archive log current';

backup current controlfile for standby format='/u01/backup/control_%U';

BACKUP FORMAT '/u01/backup/orcl_%U_%T' skip inaccessible filesperset 5 DATABASE ;

sql 'alter system archive log current';

BACKUP FORMAT '/u01/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;

release channel c2;

release channel c1;

}

过程省略,然后把备份文件SCP 到 standby相同的目录下,如果不同会出现ORA-19505

 

到这里primary端操作基本完成,下面我们来standby

 

*********************************************************************

*********************************************************************

standby端

一、 修改OS密码文件:

primary端的 OS密码文件scp过来,并修改成standby的 ORACLE_SID

 

二、修改parameter file

primary端的parameter file 文件 scp过来,并修改成standby的 ORACLE_SID

Primary file  修改

 

oracle.__db_cache_size=310378496(这里注意我们scp过来的是research.修改成oracle.)

oracle.__java_pool_size=4194304

oracle.__large_pool_size=4194304

oracle.__shared_pool_size=134217728

oracle.__streams_pool_size=0

*.audit_file_dest='/opt/oracle/admin/research/adump'

*.background_dump_dest='/opt/oracle/admin/research/bdump'

*.compatible='10.2.0.1.0'

*.control_files='/opt/oracle/oradata/research/control01.ctl','/opt/oracle/oradata/research/control02.ctl','/opt/oracle/oradata/research/control03.ctl'

*.core_dump_dest='/opt/oracle/admin/research/cdump'

*.db_block_size=8192

*.db_domain=''

*.db_file_multiblock_read_count=8

*.db_name='research'

*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'

*.db_recovery_file_dest_size=2147483648

*.dispatchers='(PROTOCOL=TCP) (SERVICE=researchXDB)'

*.job_queue_processes=10

*.log_archive_dest_1='location=/u01/arch'

*.open_cursors=300

*.pga_aggregate_target=150994944

*.processes=150

*.remote_login_passwordfile='EXCLUSIVE'

*.sga_target=455081984

*.undo_management='AUTO'

*.undo_tablespace='UNDOTBS1'

*.user_dump_dest='/opt/oracle/admin/research/udump'

 

####  add standby parameter file  ###

*.DB_UNIQUE_NAME='orcl'

*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,research)'

*.LOG_ARCHIVE_DEST_1='LOCATION=/u01/arch  VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'

*.LOG_ARCHIVE_DEST_2='SERVICE=research LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=research'

*.LOG_ARCHIVE_DEST_STATE_1=ENABLE

*.LOG_ARCHIVE_DEST_STATE_1=ENABLE

*.FAL_SERVER='research'

*.FAL_CLIENT='orcl'

*.STANDBY_FILE_MANAGEMENT='AUTO'

 

如果我们准备的数据文件目录,和admin目录不同,那我们需要在参数文件内指出并修改(这里我们主库和备库的目录相同所以没有修改目录,也方便了我们RMAN恢复的时候,不用RENAME了)。

 

三、修改控制文件:

primary端的控制文件scp过来后,要修改成参数文件制定的名字和目录。否则参数文件找不到,要把一份复制成多份,具体几份那就看你的参数文件了。

(我们这里是用RMAN直接恢复的,我们的目录也没有改变所以就不用指定了)

 

四、修改listener.ora和tnsname.ora

 

Listener.ora 加上静态监听

 

# listener.ora Network Configuration File: /opt/oracle/product/10g/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /opt/oracle/product/10g)

      (PROGRAM = extproc)

    )

      (SID_DESC =

      (GLOBAL_DBNAME = orcl)    

      (ORACLE_HOME =  /opt/oracle/product/10g)    

      (SID_NAME = orcl)    

     

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

      (ADDRESS = (PROTOCOL = TCP)(HOST = dg-ss)(PORT = 1521))

    )

  )

 

Tnsname.ora 修改

# tnsnames.ora Network Configuration File: /opt/oracle/product/10g/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

RMAN =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = dg-ss)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = rman)

    )

  )

 

EXTPROC_CONNECTION_DATA =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))

    )

    (CONNECT_DATA =

      (SID = PLSExtProc)

      (PRESENTATION = RO)

    )

  )

 

orcl =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.16)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

 

research =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.15)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = research.bj)

    )

  )

 

Lsnrctl stop

Lsnrctl start

Lsnrclt status

 

这里我们配置了2个,主要目的就是切换的时候不用在配置了。这里主备的相同的。如果备库没有network/admin的文件,可以从主库cp过来。TNSPING 互相必须能PING通。

 

五、recover standby database

1)把主库备份的备份文件,scp到相同的目录下,如果目录不同需要注册。

2)Standby 端需要启动到nomount 状态,且用spfile启动。(具体过程省略)。

3)利用RMAN 恢复standby database 

Primary 端:

[ora@dg-pp dbs]$rman target / auxiliary sys/system@orcle
_s

恢复管理器: Release 10.2.0.4.0 - Production on 星期五 5月 27 15:33:05 2011

Copyright (c) 1982, 2007, Oracle. All rights reserved.

连接到目标数据库: DGDB1 (DBID=152223982)
已连接到辅助数据库: DGDB1 (未装载)

RMAN> duplicate target database for standby nofilenamecheck dorecover;

1.      这里需要解释一下我们直接用了 NOFILENAMECHECK 参数,是因为我们的主库,备库的数据文件目录相同。不同的话,需要我们制定脚本。
2.      RUN{  # set new file names for the datafiles  SET NEWNAME FOR DATAFILE 1 TO '?/dbs/standby_data_01.f';   SET NEWNAME FOR DATAFILE 2 TO '?/dbs/standby_data_02.f';   # run the DUPLICATE command  DUPLICATE TARGET DATABASE FOR STANDBY;}

接下来就等待了,等到RMAN RECOVER 结束。查看STANDBY状态,为MOUNT。这里一般情况会提示 未完成恢复,因为我们做DG这些操作的时候必须耗费时间,这段时间内我们没有备份主库的归档,也就是说你做完全库后,主库在运行还会产生归档的。这里恢复的时候会提示,但是这不用担心,我们的目的不就是做 DG ,DG的意义就在于把没有同步过来的数据进行同步,我们的DG搭建好后。没有被RMAN恢复的归档自然会被DG传送过来了。

 

Standby 端:

 

SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 1 17:58:41 2012

 

Copyright (c) 1982, 2005, Oracle. All rights reserved.

 

SQL> conn /as sysdba

Connected.

SQL> select status from v$instance;

 

STATUS

------------------------

MOUNTED

 

六、创建STANDYB REDO

 

因为我们使用的 LOG ASYNC  ROLE 所以我们需要创建 standby redo

这里需要在主备都创建standby redo 且大小,组数,必须相同。

Standby redo = (onredo+1) * 线程数   线程数这里可以认为是RAC的节点数。

我们这里是单实例,所以创建了4组 standby redo。

SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4(’/数据文件目录/redo04.log)size 50M; (一共创建4组,步骤省略)

 

Primary 端:

在主库也创建哦!

SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4(’/数据文件目录/redo04.log)size 50M; (一共创建4组,步骤省略)

 

 

接下来有点混乱一会primary端 一会standby端 注意好哦

 

standby端:

确保主库OPEN,备库MOUNT。

 

1、从库将接收从主库传送过来的日志

primary端:

 

SQL> alter system set log_archive_dest_state_2='ENABLE';

 

System altered.

 

Standby 端:

 

2、接收并应用日志。

SQL> alter database recover managed standby database disconnect from session;

 

System altered.

 

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

SESSIONS ACTIVE

 

这里sessions active 有session活动,这种情况正常。即使出现 NOT ALLOWED 也不要害怕,因为这些状态不能确定你的DG 是否成功。因为SWITCHOVER_STATUS仅仅表示DG转换的状态。

到这里standby端的操作完成了。

 

 

 

*********************************************************************

*********************************************************************

日志传送和应用测试

 

测试日志有没有传送和同步

1、主库

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

SQL>alter system switch logfile;

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

2、从库

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

两个库上看到的序列号一致表示日志成功传送;

 

在从库上应用日志

SQL>alter database recover managed standby database disconnect from session;

 

测试日志是否能应用(测试数据是否一致)

1、主库

在主库上建立一个测试表并插入数据并提交 比如:

SQL>conn scott/tigger

SQL>create table test (name varchar2(10),job varchar2(20));

SQL>insert into test values('qiujunhua','dba');

SQL>insert into test values('qjh','plsql developer');

SQL>commit;

SQL>alter system switch logfile;

 

2、从库

在从库上应用日志

SQL>alter database recover managed standby database disconnect from session;

在open从库之前先停止应用日志

SQL>alter database recover managed standby database cancel;

打开数据库验证数据是否一致

SQL>alter database open;

SQL>conn scott/tigger

SQL>select * from test;

若看到的数据和主库一致,说明日志成功应用

 

3、返回到接收日志状态

从库启动应用日志:(在从库OPEN的状态下直接执行不用先shutdown)

SQL>alter database recover managed standby database disconnect from session;

从库停止应用日志,但是继续接收日志

SQL>alter database recover managed standby database cancel;

执行后从库处于mount状态

 

*********************************************************************

*********************************************************************

 

Data guard switchover

查看主库,备库的状态。

primary端:

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

--------------------

SESSIONS ACTIVE (证明还有session活动)

standby端:

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

NOT ALLOWED (备库等待主库经行操作,此状态不影响switchover)

2、进行switchover 操作:

primary端:

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

--------------------

SESSIONS ACTIVE

 

如果此状态为to standby’ 则可以直接切换

使用alter database commit to switchover to physical standby ;

 

我们当前状态为sessions active’ 说明还有session 活动。

使用alter database commit to switchover to physical standbywith session shutdown;” 执行完这个命令,数据库为nomount状态。

 

SQL> alter database commit to switchover to physical standby with session shutdown;

 

Database altered.

 

SQL> select status from v$instance;

 

STATUS

------------

STARTED

 

执行这个命令后,我们来看看 alert 日志。这样可以让我们知道 命令都干了些什么

alter database commit to switchover to physical standby with session shutdown

Sun Apr  1 18:49:21 2012

ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY (orcl)

Sun Apr  1 18:49:25 2012

Thread 1 advanced to log sequence 31

  Current log# 2 seq# 31 mem# 0: /opt/oracle/oradata/research/redo02.log

Sun Apr  1 18:49:25 2012

ARCH: Standby redo logfile selected for thread 1 sequence 30 for destination LOG_ARCHIVE_DEST_2

Sun Apr  1 18:49:27 2012

Stopping background process CJQ0

Sun Apr  1 18:49:27 2012

SMON: disabling tx recovery

Sun Apr  1 18:49:27 2012

Stopping background process QMNC

Sun Apr  1 18:49:28 2012

Thread 1 advanced to log sequence 32

  Current log# 3 seq# 32 mem# 0: /opt/oracle/oradata/research/redo03.log

Sun Apr  1 18:49:28 2012

ARC0: Standby redo logfile selected for thread 1 sequence 31 for destination LOG_ARCHIVE_DEST_2

Sun Apr  1 18:49:28 2012

Stopping Job queue slave processes

Sun Apr  1 18:49:36 2012

Waiting for Job queue slaves to complete

Sun Apr  1 18:50:03 2012

Job queue slave processes stopped

All dispatchers and shared servers shutdown

Sun Apr  1 18:50:05 2012

SMON: disabling cache recovery

Sun Apr  1 18:50:05 2012

Shutting down archive processes

Archiving is disabled

Sun Apr  1 18:50:10 2012

ARCH shutting down

ARC1: Archival stopped

Sun Apr  1 18:50:15 2012

ARC0: Becoming the heartbeat ARCH

ARC0: Archiving disabled

ARCH shutting down

ARC0: Archival stopped

Sun Apr  1 18:50:16 2012

Thread 1 closed at log sequence 32

Successful close of redo thread 1

Sun Apr  1 18:50:16 2012

ARCH: Noswitch archival of thread 1, sequence 32

ARCH: End-Of-Redo Branch archival of thread 1 sequence 32

ARCH: Archiving is disabled due to current logfile archival

Clearing standby activation ID 2102571270 (0x7d52b106)

The primary database controlfile was created using the

'MAXLOGFILES 16' clause.

There is space for up to 13 standby redo logfiles

Use the following SQL commands on the standby database to create

standby redo logfiles that match the primary database:

ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;

Archivelog for thread 1 sequence 32 required for standby recovery

MRP0 started with pid=10, OS id=17838

Sun Apr  1 18:50:17 2012

MRP0: Background Managed Standby Recovery process started (orcl)

Managed Standby Recovery not using Real Time Apply

Online logfile pre-clearing operation disabled by switchover

Media Recovery Log /u01/arch/1_32_779474103.dbf

Identified End-Of-Redo for thread 1 sequence 32

Sun Apr  1 18:50:22 2012

Media Recovery End-Of-Redo indicator encountered

Sun Apr  1 18:50:22 2012

Media Recovery Applied until change 500306

Sun Apr  1 18:50:22 2012

MRP0: Media Recovery Complete: End-Of-REDO (orcl)

Resetting standby activation ID 2102571270 (0x7d52b106)

Sun Apr  1 18:50:23 2012

Waiting for MRP0 pid 17838 to terminate

Sun Apr  1 18:50:24 2012

MRP0: Background Media Recovery process shutdown (orcl)

Sun Apr  1 18:50:24 2012

idle dispatcher 'D000' terminated, pid = (13, 1)

Sun Apr  1 18:50:24 2012

Switchover: Complete - Database shutdown required (orcl)

Sun Apr  1 18:50:24 2012

Completed: alter database commit to switchover to physical standby with session shutdown

 

此时看备库的状态已经成为 switchover  pending 。这足以证明我们之前看到standby状态为not allowed 只是等待主库给她发状态命令罢了。

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

SWITCHOVER PENDING

 

此时主库已切换成了,备库。现在重启到mount

 

Shut immediate

Startup mount

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

--------------------

TO PRIMARY

 

此时的状态也表明了我们转换成功了,现在这个是备库,备库的switchover 状态为to primary 。

 

到这里primary 已经转换成 standby了。

 

 

Standby 端:

1、上面的 primary 已经转换成功了,我们看一下standby状态。

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

SWITCHOVER PENDING

 

这里需要我们应用日志了。

使用alter database recover managed standby database disconnect from session;

 

SQL> alter database recover managed standby database disconnect from session;

 

Database altered.

 

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

TO PRIMARY

 

此时standby的状态时to primary  允许我们转换了。

 

使用alter database commit to switchover to primary;如果执行此命令后hold住的话,你可以使用下面命令经行操作。

 

SQL> alter database recover managed standby database disconnect from session;

alter database recover managed standby database disconnect from session

*

ERROR at line 1:

ORA-01153: an incompatible media recovery is active

 

SQL> alter database recover managed standby database cancel;

 

Database altered.

 

SQL> alter database commit to switchover to primary;

 

Database altered.  转换成功之后,数据库状态为 nomount

 

SQL> select status from v$instance;

 

STATUS

------------------------

STARTED

 

Shut immediate

Statrtup

查看状态

SQL> select switchover_status from v$database;

 

SWITCHOVER_STATUS

----------------------------------------

SESSIONS ACTIVE

 

此时已经切换成功。如果真正的成功没有,那我们还需要做 日志传输和应用实验。

 

证明我们的switchover 成功了。

 

FAILOVER(没有做测试)

1、原则上在主库上不进行操作

因为既然是FAILOVER ,生产情况主库已经崩溃或者无法打开!!!无法执行,这里仅测试。

1、从库取消恢复

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;

    ---force关键字将会停止当前活动RFS进程,以便立即执行failover
2备库直接切换为主库

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

3、启动数据库

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP;

 

切换成功后原来主库已经不是dg里的一部分了。

接下来的工作就是将原来的主库恢复数据 或者重新改造成dg里的standby库!!!

 

你可能感兴趣的:(不停机 data guard 及 switchover)