search
HomeDatabaseMysql TutorialOracle 11g Data Guard 之物理备库角色转换

一. 物理备库的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;

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

2.主库启动switchover

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

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

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

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

3.关闭并mount前主库

SQL> SHUTDOWN ABORT;

SQL> STARTUP MOUNT;

这个时候,原主库已经变成了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;

   如果查询结果显示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;

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

6.打开新的主库

SQL> ALTER DATABASE OPEN;

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

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

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

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

二.物理备库的Failover操作

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

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

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

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

在主库执行SQL:

SQL> ALTER SYSTEM FLUSH REDO TO target_db_name;

   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;

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

SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';

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

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

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

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

4.关闭redo应用

在目标备库执行:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

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

在目标备库执行:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

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

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;

语句执行完进入第8步。

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

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

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

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

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

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

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

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

8.打开新的主库

SQL> ALTER DATABASE OPEN;

9.备份新的主库

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

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

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

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

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

Statement
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools