search
HomeDatabaseMysql TutorialOracle 11g Data Guard Role Transitions: Failover

Role TransitionsInvolving Physical Standby Databases A database operates in one of the following mutuallyexclusive roles: primary or standby . Data Guard enables you to change theseroles dynamically by issuing the SQL statements described

Role TransitionsInvolving Physical Standby Databases

 

A database operates in one of the following mutuallyexclusive roles:primary or standby. Data Guard enables you to change theseroles dynamically by issuing the SQL statements described in this chapter, orby using either of the Data Guard broker's interfaces. Oracle Data Guardsupports the following role transitions:

 

  • Switchover
    Allows the primary database to switch roles with one of its standby databases. There is no data loss during a switchover. After a switchover, each database continues to participate in the Data Guard configuration with its new role.

 

  • Failover
    Changes a standby database to the primary role in response to a primary database failure. If the primary database was not operating in either maximum protection mode or maximum availability mode before the failure, some data loss may occur. If Flashback Database is enabled on the primary database, it can be reinstated as a standby for the new primary database once the reason for the failure is corrected.

 

Performing a Failoverto a Physical Standby Database

 

Fault Simulation

 

Original Primary:

SQL>set linesize 200

SQL>  selectOPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,DB_UNIQUE_NAME,SWITCHOVER_STATUS fromv$database;

 

OPEN_MODE            PROTECTION_MODE      DATABASE_ROLE    DB_UNIQUE_NAME                 SWITCHOVER_STATUS

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

READWRITE           MAXIMUM AVAILABILITYPRIMARY          prod                           TO STANDBY

 

SQL>exit

Disconnectedfrom Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production

Withthe Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@prod~]$ ps -ef | grep smon

oracle    3915    1  0 16:20 ?        00:00:01 ora_smon_prod

oracle    4584 3323  0 16:57 pts/1    00:00:00 grep --color=auto smon

[oracle@prod~]$ kill -9 3915

 

Step1   Flush any unsent redo from the primary database to thetarget standby database.

 

If the primary database can be mounted, it may be possible to flush any unsent archived andcurrent redo from the primary database to the standby database. If thisoperation is successful, a zero data loss failover is possible even if theprimary database is not in a zero data loss data protection mode.

 

Ensure that Redo Apply is active at the targetstandby database.

Standby:

SQL>select OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,DB_UNIQUE_NAME,SWITCHOVER_STATUSfrom v$database;

 

OPEN_MODE            PROTECTION_MODE      DATABASE_ROLE    DB_UNIQUE_NAME                 SWITCHOVER_STATUS

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

READ ONLY WITH APPLY MAXIMUM AVAILABILITY PHYSICALSTANDBY standby                        TOPRIMARY

 

Primary:

Mount, but do not open the primarydatabase. If the primary database cannot be mounted, go toStep2.

Issue the following SQL statement at the primarydatabase:

SQL>startup mount;

ORACLEinstance started.

TotalSystem Global Area  263639040 bytes

FixedSize                  1344312 bytes

VariableSize             230689992 bytes

DatabaseBuffers           25165824 bytes

RedoBuffers                6438912 bytes

Databasemounted.

SQL>alter system flush redo to 'standby';

Systemaltered.

 

 ALTER SYSTEMFLUSH REDO TO target_db_name .

For target_db_name, specify the DB_UNIQUE_NAME of thestandby database that is to receive the redo flushed from the primary database.

This statement flushes any unsent redo from theprimary database to the standby database, and waits for that redo to be appliedto the standby database.

If this statement completes without anyerrors, go toStep5. If the statement completes with any error,or if it must be stopped because you cannot wait any longer for the statementto complete, continue with Step2.

 

Step2   Verify that the standby database has the most recentlyarchived redo log file for each primary database redo thread.

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

 

Primary and Standby

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

 

    THREAD      LAST

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

         1         98

standby

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

 

ALTERDATABASE REGISTER PHYSICAL LOGFILE 'redo_logfile';

 

Step3   Identify and resolve any archived redo log gaps.

 

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

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

norows selected

 

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

In this example the gap comprises archived redo logfiles with sequence numbers 90, 91, and 92 for thread 1.

If possible, copy any missing archived redo log filesto the target standby database from the primary database and register them atthe target standby database. This must be done for each redo thread.

 

SQL>ALTER DATABASE REGISTER PHYSICAL LOGFILE 'redo_logfile';

 

 

Step4   Repeat Step 3 until all gaps are resolved.

The query executed inStep3 displays information for the highest gaponly. After resolving a gap, you must repeat the query until no more rows arereturned.

If, after performingStep2 throughStep4, you are not able to resolve all gaps in thearchived redo log files (for example, because you do not have access to thesystem that hosted the failed primary database), some data loss will occurduring the failover.

 

Step5   Stop Redo Apply.

Issue the following SQL statement on the targetstandby database:

 

SQL>alter database recover managed standby database cancel;

Databasealtered.

 

Step6   Finish applying all received redo data.

Issue the following SQL statement on the targetstandby database:

 

SQL>alter database recover managed standby database finish;

Databasealtered.

 

If this statement completes without anyerrors, proceed toStep7.

If an error occurs, some received redo data was notapplied. Try to resolve the cause of the error and re-issue the statementbefore proceeding to the next step.

Note that if there is a redo gap thatwas not resolved inStep3 andStep4, you will receive an error stating that thereis a redo gap.

If the error condition cannot be resolved, a failovercan still be performed (with some data loss) by issuing the following SQLstatement on the target standby database:

 

SQL>alter database activate physical standby database;

Databasealtered.

SQL>select OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,DB_UNIQUE_NAME,SWITCHOVER_STATUSfrom v$database;

 

OPEN_MODE            PROTECTION_MODE      DATABASE_ROLE    DB_UNIQUE_NAME                 SWITCHOVER_STATUS

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

MOUNTED              MAXIMUM AVAILABILITY PRIMARY          standby                        NOT ALLOWED

 

Proceed toStep9 when the ACTIVATE statement completes.

 

Step7   Verify that the target standby database is ready to become aprimary database.

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

SQL>SELECT SWITCHOVER_STATUS FROM V$DATABASE;

 

SWITCHOVER_STATUS

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

NOTALLOWED

 

A value of either TO PRIMARY or SESSIONS ACTIVEindicates that the standby database is ready to be switched to the primaryrole. If neither of these values is returned, verify that Redo Apply is activeand continue to query this view until either TO PRIMARY or SESSIONS ACTIVE isreturned.

 

Step8   Switch the physical standby database to the primary role.

Issue the following SQL statement on the targetstandby database:

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

 

Note:

The WITH SESSION SHUTDOWN clause can be omitted fromthe switchover statement if the query of the SWITCHOVER_STATUS column performedin the previous step returned a value of TO PRIMARY.

 

Step9   Open the new primary database.

SQL>alter database open;

Databasealtered.

SQL>select OPEN_MODE,PROTECTION_MODE,DATABASE_ROLE,DB_UNIQUE_NAME,SWITCHOVER_STATUSfrom v$database;

 

OPEN_MODE            PROTECTION_MODE      DATABASE_ROLE    DB_UNIQUE_NAME                 SWITCHOVER_STATUS

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

READWRITE           MAXIMUM AVAILABILITYPRIMARY          standby                        FAILED DESTINATION

 

Step10   Back up the new primary database.

Oracle recommends that a full backup be taken of thenew primary database.

 

Step11   Restart Redo Apply if it has stopped at any of the otherphysical standby databases in your Data Guard configuration.

SQL>alter database recover managed standby database using current logfiledisconnect from session;

 

Step12   Optionally, restore the failed primary database.

After a failover, the original primary database canbe converted into a physical standby database of the new primary database usingthe method

As following:


Flashing Back a FailedPrimary Database into a Physical Standby Database



作者:xiangsir

QQ:444367417

MSN:xiangsir@hotmail.com


 

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
When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Describe MySQL asynchronous master-slave replication process.Describe MySQL asynchronous master-slave replication process.Apr 10, 2025 am 09:30 AM

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL: Simple Concepts for Easy LearningMySQL: Simple Concepts for Easy LearningApr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL: A User-Friendly Introduction to DatabasesMySQL: A User-Friendly Introduction to DatabasesApr 10, 2025 am 09:27 AM

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

How does the InnoDB Buffer Pool work and why is it crucial for performance?How does the InnoDB Buffer Pool work and why is it crucial for performance?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL: The Ease of Data Management for BeginnersMySQL: The Ease of Data Management for BeginnersApr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),