Table of Contents
一.物理备库的Switchover操作" >一.物理备库的Switchover操作
二.物理备库的Failover操作" >二.物理备库的Failover操作
Home Database Mysql Tutorial Oracle 11g Data Guard 之物理备库角色转换

Oracle 11g Data Guard 之物理备库角色转换

Jun 07, 2016 pm 02:50 PM
data guard oracle physics Role

一. 物理备库的Switchover操作 本节主要内容是物理备库的switchover操作,该操作起始于主库,结束于目标备库。 1.确认主库可以切换为standby角色 SQL SELECT SWITCHOVER_STATUS FROM V$DATABASE; 如果结果显示TO STANDBY或者SESSIONS ACTIVE,则表明主库可以

一.物理备库的Switchover操作

本节主要内容是物理备库的switchover操作,该操作起始于主库,结束于目标备库。

1.确认主库可以切换为standby角色

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
Copy after login
Copy after login
Copy after login

   如果结果显示TO STANDBY或者SESSIONS ACTIVE,则表明主库可以切换为standby角色,否则,切换操作将不可行,因为redo传输不是配置错误就是不能正常进行。

2.主库启动switchover

执行如下SQL语句将主库切换为standby角色:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
Copy after login

   在switchover之前,当前的控制文件备份到当前SQL执行的会话跟踪文件中,这使得,如果需要的话,可以重建当前的控制文件。

注意:如果第1步中查询结果显示是TO STANDBY,该SQL语句中的WITH SESSION SHUTDOWN子句可以省略。

3.关闭并mount前主库

SQL> SHUTDOWN ABORT;

SQL> STARTUP MOUNT;
Copy after login

这个时候,原主库已经变成了standby角色。

   注意:Oracle 11g (11.2.0.4) 或者更新的版本,不需要执行SHUTDOWN ABORT,因为一旦数据库执行“ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN”就默认包括了该操作。

4.确保switchover目标可以切换为primary角色

通过V$DATABASE查询standby库的SWITCHOVER_STATUS值:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
Copy after login
Copy after login
Copy after login

   如果查询结果显示TO PRIMARY或者SESSIONS ACTIVE,则表明备库可以切换为primary角色。否则,确认redo应用是否是激活的、redo传输的配置是否正确并且能否正常运行,直到查询结果显示TO PRIMARY或者SESSIONS ACTIVE。

5.切换目标物理备库到primary角色

在目标物理备库上执行如下SQL:

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

注意:如果第1步中查询结果显示是TO PRIMARY,该SQL语句中的WITH SESSION SHUTDOWN子句可以省略。

6.打开新的主库

SQL> ALTER DATABASE OPEN;
Copy after login
Copy after login

7.打开新物理备库的redo应用

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Copy after login
Copy after login
Copy after login

8.重启redo应用,如果在该Data Guard配置中任何其他物理备库中redo应用已经关闭

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Copy after login
Copy after login
Copy after login

二.物理备库的Failover操作

物理备库进行failover操作步骤如下:

1.将主库所有未传至目标备库的redo数据刷新到目标备库

   如果主库可以mounted,可能可以将主库所有未发送的归档日志和当前的redo从主库刷新到备库,如果这个操作能成功执行,那么即便主库不是运行在零数据丢失保护模式下,零数据丢失的故障转移也是可能的。

确保目标备库的redo应用是开启的,然后mount但不要打开主库(如果主库不能mounted,直接跳到第2步)。

在主库执行SQL:

SQL> ALTER SYSTEM FLUSH REDO TO target_db_name;
Copy after login

   target_db_name,指定备库的DB_UNIQUE_NAME,它用来接收主库刷新过来的redo数据。该SQL用来刷新主库所有未发送的redo数据到备库,然后等待redo应用到备库。如果该步骤无误完成,那么直接进入第5步;如果该步骤执行有误或者因为不能等它执行完就已停止,则进入第2步。

2.确保备库拥有每个主库线程最新的归档日志

通过V$ARCHIVED_LOG视图查询目标备库查询每个redo线程的最大日志序列:

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

如果备库中不存在每个主库redo线程的最大日志序列对应的归档日志,如果可以,从主库复制并注册它们到备库:

SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
Copy after login

3.确认并解决所有归档日志的缺失

通过V$ARCHIVE_GAP视图查询目标备库是否存在日志缺失:

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

对于缺失的日志,执行第2步的操作,直到没有日志缺失的情况存在。

4.关闭redo应用

在目标备库执行:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Copy after login

5.完成所有收到的redo日志应用

在目标备库执行:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
Copy after login

   如果该SQL执行无误,进入第7步,如果执行有误,说明收到的redo没有被应用,需要解决错误再进入下一步。注意,如果第3步redo缺失没有解决,将收到redo缺失的错误警告,如果错误没有被解决,failover通过备库上如下SQL也可以完成:

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
Copy after login

语句执行完进入第8步。

6.确认目标备库可以转换为primary角色

通过查询V$DATABASE视图的SWITCHOVER_STATUS值来确认:

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
Copy after login
Copy after login
Copy after login

   如果查询结果显示TO PRIMARY或者SESSIONS ACTIVE,则表明备库可以切换为primary角色。否则,确认redo应用是否是启动的,直到查询结果显示TO PRIMARY或者SESSIONS ACTIVE。

7.切换物理备库到primary角色

在目标物理备库上执行如下SQL:

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

注意:如果第1步中查询结果显示是TO PRIMARY,该SQL语句中的WITH SESSION SHUTDOWN子句可以省略。

8.打开新的主库

SQL> ALTER DATABASE OPEN;
Copy after login
Copy after login

9.备份新的主库

10.重启redo应用,如果在该Data Guard配置中任何其他物理备库中redo应用已经关闭

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Copy after login
Copy after login
Copy after login

11.有选择的恢复故障主库

   Failover后,通过Flashback或者RMAN工具,原主库可以转换为新主库的物理备库,或者可以通过新主库的备份以作为物理备库的身份被重建。一旦原主库转为standby角色,就可以通过switchover操作恢复其主库身份。

   本文参阅Oracle官方文档翻译,不足之处欢迎批评指正害羞

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to paginate oracle database How to paginate oracle database Apr 11, 2025 pm 08:42 PM

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to solve garbled code in oracle How to solve garbled code in oracle Apr 11, 2025 pm 10:09 PM

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.

See all articles