oracle物理dg角色转换

Data Guard Concepts and Administration

8.2 Role Transitions Involving Physical Standby Databases

The following sections describe how to perform a switchover or failover to a physical standby database:
接下来的章节介绍怎样switchover或是failover到物理备库

8.2.1 Performing a Switchover to a Physical Standby Database

This section describes how to perform a switchover to a physical standby database.A switchover is initiated on the primary database and is completed on the target standby database.
本节介绍怎样switchover到物理备库。switchover在主库上发起,在目标物理备库上结束(先将主库转成备库,才能将备库转成主库,一个dg中不能同时有两个主库)。


Step 1   Verify that the primary database can be switched to the standby role.
  验证主库可以被转成物理备库

Query the SWITCHOVER_STATUS column of the V$DATABASE view on the primary database.For example:
在主库上查询视图V$DATABASESWITCHOVER_STATUS列。如下:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS 
 ----------------- 
 TO STANDBY 
 1 row selected 

A value of TO STANDBY or SESSIONS ACTIVE indicates that the primary database can be switched to the standby role. If neither of these values is returned, a switchover is not possible because redo transport is either misconfigured or is not functioning properly. See Chapter 6 for information about configuring and monitoring redo transport.
如果查询的结果是TO STANDBY或是SESSIONS ACTIVE,则表明主库可以被转成物理备库。如果返回的不是这两个会下,则switchover不能进行,原因可能是 日志传输redo transport没有正确配置或是运行不正常。查看第6章中获取关于配置及监控日志传输的信息。

Step 2   Initiate the switchover on the primary database.  主库上发起switchover

Issue the following SQL statement on the primary database to switch it to the standby role:
在主库上执行以下sql语句,将主库转成备库角色:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH -
> SESSION SHUTDOWN;

This statement converts the primary database into a physical standby database. The current control file is backed up to the current SQL session trace file before the switchover. This makes it possible to reconstruct a current control file, if necessary.
此语句将主库转成物理备库。在switchover之前,当前控制文件会被备份到trace file中。如果需要的话,可以通过trace file中的备份重建控当前控制文件。

Note:

The WITH SESSION SHUTDOWN clause can be omitted from the switchover statement if the query performed in the previous step returned a value of TO STANDBY.
如果上一步查询的返回值是TO STANDBY,则WITH SESSION SHUTDOWN 子句可以被省略。
Step 3   Shut down and then mount the former primary database.  关闭并重新mount之前的主库
SQL> SHUTDOWN ABORT;
SQL> STARTUP MOUNT;

At this point in the switchover process, the original primary database is a physical standby database (see Figure 8-2).
此时,原主库已经转成物理备库。

Note:

In Oracle Database 11 g release 2 (11.2.0.4) and later, it is not necessary to issue the SHUTDOWN ABORT statement in this step because the database instance is shut down by default when the ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN statement is issued.
11.2.0.4及以后版本,在这一步中没有必要再执行SHUTDOWN   ABORT,因为在执行ALTER   DATABASE   COMMIT   TO   SWITCHOVER   TO   PHYSICAL   STANDBY   WITH   SESSION   SHUTDOWN时,数据库会被自动关闭。
Step 4   Verify that the switchover target is ready to be switched to the primary role.  验证目标备库可以被转成主库

Query the SWITCHOVER_STATUS column of the V$DATABASE view on the standby database.

For example:
在备库上查询视图V$DATABASESWITCHOVER_STATUS列。如下:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS 
----------------- 
TO_PRIMARY 
1 row selected

A value of TO PRIMARY or SESSIONS ACTIVE indicates that the standby database is ready to be switched to the primary role. If neither of these values is returned, verify that Redo Apply is active and that redo transport is configured and working properly. Continue to query this column until the value returned is either TO PRIMARY orSESSIONS ACTIVE.
如果查询的结果是TO PRIMARYSESSIONS ACTIVE,则表明此物理备库可以被转成主库。如果返回值不是这两个值,检查Redo Apply是不是active,并且redo transport是不是正确配置及工作正常。继续查询此列,直到返回值是TO PRIMARY或是SESSIONS ACTIVE


Step 5   Switch the target physical standby database role to the primary role. 将目标物理备库转成主库

Issue the following SQL statement on the target physical standby database:
在目标备库上执行以下sql语句:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Note:

The WITH SESSION SHUTDOWN clause can be omitted from the switchover statement if the query performed in the previous step returned a value of TO PRIMARY.
如果上一步查询的返回值是TO PRIMARY,则WITH SESSION SHUTDOWN 子句可以被省略。
Step 6   Open the new primary database.  打开新的主库
SQL> ALTER DATABASE OPEN;
Step 7   Start Redo Apply on the new physical standby database.  在新备库(即原主库)上启动Redo Apply

For example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE -
> DISCONNECT FROM SESSION;
Step 8   Restart Redo Apply if it has stopped at any of the other physical standby databases in your Data Guard configuration.  dg中关闭Redo Apply的物理备库需要重新启动Redo Apply

For example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE -
> DISCONNECT FROM SESSION;

8.2.2 Performing a Failover to a Physical Standby Database

This section describes how to perform a failover to a physical standby database.
本节介绍怎样failover到物理备库


Step 1   Flush any unsent redo from the primary database to the target standby database. 将主库中没有发到备库的日志发到目标备库

If the primary database can be mounted, it may be possible to flush any unsent archived and current redo from the primary database to the standby database. If this operation is successful, a zero data loss failover is possible even if the primary database is not in a zero data loss data protection mode.
如果主库可以被mount,则可以把未发送的归档和当前日志从主库发送到备库。如果此操作成功,即使主库不是 最大保护 模式,也不会有数据丢失。

Ensure that Redo Apply is active at the target standby database.
确认Redo Apply在目标备库正常运行。

Mount, but do not open the primary database. If the primary database cannot be mounted, go to Step 2.
mount但是不open主库。如果主库不能被mount,则 跳转到 step2.

Issue the following SQL statement at the primary database:
在主库执行以下sql语句:

SQL> ALTER SYSTEM FLUSH REDO TO target_db_name;

For target_db_name, specify the DB_UNIQUE_NAME of the standby database that is to receive the redo flushed from the primary database.
target_db_name(需要用单引号引起来)是指接收主库发来的redo的备库的yyDB_UNIQUE_NAME

This statement flushes any unsent redo from the primary database to the standby database, and waits for that redo to be applied to the standby database.
此语句会将未发送的redo从主库发到备库,并且等待redo在备库上应用(直到备库上日志apply结束,才返回命令行)。

If this statement completes without any errors, go to Step 5. If the statement completes with any error, or if it must be stopped because you cannot wait any longer for the statement to complete, continue with Step 2.
如果此语句成功完成,没有报错,则 跳转到step5。如果有报错,或是因为你不想再等了,人为退出,则 继续执行step2。


Step 2   Verify that the standby database has the most recently archived redo log file for each primary database redo thread. 验证备库上有最近的主库的归档日志(rac中一个数据库有多个实例,一个实例对应一个thread,所以要检查一下每个实例上最新的日志是不是都发送到了备库)

Query the V$ARCHIVED_LOG view on the target standby database to obtain the highest log sequence number for each redo thread.

For example:
在备库上查询视图V$ARCHIVED_LOG来获取每一个thread发一来的最大sequence的日志。如下:

SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) -
> OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;

    THREAD       LAST
---------- ----------
         1        100

If possible, copy the most recently archived redo log file for each primary database redo thread to the standby database if it does not exist there, and register it. This must be done for each redo thread.

For example:
如果备库上缺少主库的最近的归档日志,需要把缺少的日志拷贝到备库,并将拷来的日志注册一下。主库的每个thread的日志都要拷(如果缺少的话)。

SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
Step 3   Identify and resolve any archived redo log gaps.  检查、解决归档日志gap(gap就是备库缺少主库的日志)

Query the V$ARCHIVE_GAP view on the target standby database to determine if there are any redo gaps on the target standby database.

For example:
在备库上查询视图V$ARCHIVE_GAP,检查是不是有日志的gap。如下:

SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

THREAD#    LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ------------- --------------
         1            90             92

In this example the gap comprises archived redo log files with sequence numbers 90, 91, and 92 for thread 1.
上面的查询说明备库有一个gap,gap对应thread 1的sequence是90-92的日志。

If possible, copy any missing archived redo log files to the target standby database from the primary database and register them at the target standby database. This must be done for each redo thread.
从主库拷贝缺少的归档日志到目标备库,并在备库注册归档日志。主库的每个thread的日志都要拷(如果缺少的话)。

For example:

SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
Step 4   Repeat Step 3 until all gaps are resolved.  重复step3直到所有gap都被解决

The query executed in Step 3 displays information for the highest gap only. After resolving a gap, you must repeat the query until no more rows are returned.
step3中执行的查询只会显示第一个gap。解决这个gap后,需要重复上面的查询,直到没有数据返回为止。

If, after performing Step 2 through Step 4, you are not able to resolve all gaps in the archived redo log files (for example, because you do not have access to the system that hosted the failed primary database), some data loss will occur during the failover.
如果执行step2到step4后,还是不能解决所有的gap(例如,数据库的服务器不能登录),则在failover时会丢数据。


Step 5   Stop Redo Apply. 停止Redo Apply

Issue the following SQL statement on the target standby database:
在备库执行以下sql语句:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Step 6   Finish applying all received redo data.

Issue the following SQL statement on the target standby database:
在备库上执行以下sql语句:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

If this statement completes without any errors, proceed to Step 7.
如果此语句执行成功,没有报错,则继续执行step7.

If an error occurs, some received redo data was not applied. Try to resolve the cause of the error and re-issue the statement before proceeding to the next step.
如果有报错,一些接收到的redo不能被应用。在继续下一步之前,试着解决出错的原因,并重新执行上面的sql。

Note that if there is a redo gap that was not resolved in Step 3 and Step 4, you will receive an error stating that there is a redo gap.
如果redo gap在step3和step4中不能被解决,你会看到关于redo gap的报错。

If the error condition cannot be resolved, a failover can still be performed (with some data loss) by issuing the following SQL statement on the target standby database:
如果报错不能被解决,通过在备库上执行以下sql,failover还是可以执行的(会丢数据):

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;

Proceed to Step 9 when the ACTIVATE statement completes.
ACTIVATE语句完成后,跳转到step8


Step 7   Verify that the target standby database is ready to become a primary database. 验证目标备库可以被转成主库

Query the SWITCHOVER_STATUS column of the V$DATABASE view on the target standby database.

For example:
在备库上查询视图V$DATABASESWITCHOVER_STATUS列。如下:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS
-----------------
TO PRIMARY
1 row selected

A value of either TO PRIMARY or SESSIONS ACTIVE indicates that the standby database is ready to be switched to the primary role. If neither of these values is returned, verify that Redo Apply is active and continue to query this view until either TO PRIMARY or SESSIONS ACTIVE is returned.
如果查询的结果是TO PRIMARYSESSIONS ACTIVE,则表明此物理备库可以被转成主库。如果返回值不是这两个值,检查Redo Apply是不是active,继续查询此列,直到返回值是TO PRIMARY或是SESSIONS ACTIVE


Step 8   Switch the physical standby database to the primary role. 将物理备库转成主库

Issue the following SQL statement on the target standby database:
在目标备库上执行以下sql语句:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

Note:

The WITH SESSION SHUTDOWN clause can be omitted from the switchover statement if the query of the SWITCHOVER_STATUS column performed in the previous step returned a value of TO PRIMARY.
如果上一步查询中SWITCHOVER_STATUS的返回值是TO PRIMARY,则WITH SESSION SHUTDOWN 子句可以被省略。
Step 9   Open the new primary database. 打开新主库
SQL> ALTER DATABASE OPEN;
Step 10   Back up the new primary database. 备份新主库

Oracle recommends that a full backup be taken of the new primary database.
oracle建议新主库做一个全库备份。


Step 11   Restart Redo Apply if it has stopped at any of the other physical standby databases in your Data Guard configuration.  dg中关闭Redo Apply的物理备库需要重新启动Redo Apply

For example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE -
> DISCONNECT FROM SESSION;
Step 12   Optionally, restore the failed primary database.  可选操作,恢复坏掉的主库

After a failover, the original primary database can be converted into a physical standby database of the new primary database using the method described in Section 13.2or Section 13.7, or it can be re-created as a physical standby database from a backup of the new primary database using the method described in Section 3.2.
failover之后,原来的主库可以被转成新主库的物理备库,或是可以通过新主库的备份重新创建一个物理备库。

Once the original primary database is running in the standby role, a switchover can be performed to restore it to the primary role.
一旦原主库成为了新主库的物理备库,可以通过switchover再将它转成主库。

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

转载于:http://blog.itpub.net/7417681/viewspace-2076513/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值