Introduction
This paper describes the procedures to perform “graceful”
failovers and failbacks of standby databases in Oracle environments
that are not using Automatic Data Guard.
A “graceful” failover is one that does
not require databases to be opened with the RESETLOGS option—and as a
result, graceful failbacks do not require the primary database to be
rebuilt. (That is, they do not require the standby database’s datafiles
to be copied to the primary server.) Graceful failovers and failbacks
are also known as “switchovers” and “switchbacks”.
In order to avoid confusion, the original primary database will be referred to as database “ABC”, and the original standby database will be referred to as database “XYZ”. In other words, before any of these procedures are run, the primary database is “ABC” and the standby database is “XYZ”..
The procedures in this document are generally based on the information contained in Metalink document 90817.1.
Graceful Failover or SwitchOver Procedure
ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'filename';
STARTUP NOMOUNT
ALTER DATABASE MOUNT STANDBY DATABASE;
Graceful Failback or SwitchBack Procedure
(These steps are basically identical to the failover procedure above—the only difference is that you are reversing the roles of the "ABC" and "XYZ" databases.)
ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'filename';
STARTUP NOMOUNT
ALTER DATABASE MOUNT STANDBY DATABASE;
Requirements and Notes
This section describes the requirements that must be met in order to use these procedures; along with some notes.
First, the primary database’s host must be accessible. In order to use these procedures, the control files and online redo logs from the primary database need to be copied from the primary database’s host to the standby database’s host. Therefore, these procedures can not be used if the primary database’s host is inaccessible—because that would prevent those files from being copied to the standby server. (It may be possible to configure a geographic disk mirroring utility between the primary and standby hosts in order to be able to eliminate this requirement; but I have not seen any successful implementation of geographic disk mirroring in Oracle environments.)
Next, the primary and standby databases must be shut down with normal or immediate priority. If the databases (particularly the primary database) are shut down with SHUTDOWN ABORT, then it might not be possible to fully recover the standby database—and that would prevent these procedures from being usable.
These procedures include converting the original primary database into a standby database during graceful failover (after the original standby database has been converted into a primary database). It should be pointed out that it is not required to convert the primary into a standby—it is still possible to fail back to the original primary, even if that database was not converted into a standby. However, if you do not convert the original primary database into a standby, then you must ensure that that database never gets opened until you are performing the failback procedure. This is because the act of opening a primary database generates some redo in that database—and that redo will cause the primary database’s datafiles to become permanently out of sync with the redo in the standby database. So, if you open up the original primary database without converting it to a standby, you will not be able to use these procedures; you will have to completely rebuild the primary database from a copy of the standby database’s datafiles.
Thirdly, these procedures specify to copy the control files from the primary database to the standby database. An alternative to doing this is to rebuild the standby’s control files from the output of an ALTER DATABASE BACKUP CONTROLFILE TO TRACE command. Note, however, that if you wish to rebuild the standby’s control files, then you must ensure that the CREATE CONTROLFILE statement contains the NORESETLOGS option. If you change that option to specify RESETLOGS, then you will not be able to open the database with a regular ALTER DATABASE OPEN. Instead, you will be forced to specify RESETLOGS when opening the database, and, of course, the whole purpose of these procedures is to avoid opening the database with RESETLOGS.
Finally, there is an “idiosyncrasy” with these procedures when they are used in conjunction with locally-managed temporary tablespaces. To be specific, if these procedures are used with a database that contains a locally-managed temporary tablespace, and if the tempfiles of that tablespace were not added to the hot standby database before the standby was converted into the new primary database, then that locally managed temporary tablespace will have to be completely dropped and re-created in the new primary database in order to use the tempfiles in question.
The reason for this is that these procedures specify to copy the control files from the primary database to the standby database. Therefore, if you try to add the tempfiles to the standby database’s temporary tablespace after converting it to the new primary, you will receive a “file is already part of database” error message – because the control files (which were copied from the original primary) will already contain the information about those tempfiles. Also, if the new primary instance tries to use any of the tempfiles (such as for a sorting operation) then a “cannot identify/lock data file xxx” error message will be displayed – because the tempfile in question does not actually exist on the new primary’s host. As mentioned above, one solution to this issue is to simply drop and re-create the locally managed temporary tablespace completely, after converting the standby database into a primary database. An alternate solution is to manually ensure that all tempfiles have been added to the standby before converting the standby into the new primary.