Oracle8i Standby Database Concepts and Administration Release 2 (8.1.6) Part Number A76995-01 |
|
This chapter describes how to manage a standby database. It includes the following topics:
As explained in Standby Database Modes, you can run the standby database in the following mutually exclusive modes:
Before running in these modes, you must first start the standby instance and then mount the database. The sections in this chapter describe the procedures for initiating the various modes as well as for performing failover to a standby database.
Typically, you create a standby database for one or more of the following reasons:
If you want maximum protection against data loss or corruption, then maintain the standby database in managed recovery mode in a managed standby environment. In this setup, the primary database archives logs to the standby site, and the standby database automatically applies these logs.
Note: You may need to apply archived logs manually to the standby database before managed recovery. To learn why, see Resolving a Gap Sequence Before Initiating Managed Recovery. |
If you want to use the standby database for reporting purposes, then open it in read-only mode in a managed standby environment. Oracle cannot apply archived redo logs to the standby database when it is in this mode, but you can still execute queries on the database. The primary database continues to archive to the standby site so long as the standby instance is started.
You can easily switch back and forth between managed recovery mode and read-only mode. In most implementations of a managed standby environment, you need to perform this switch at various times to either:
To learn how to initiate managed recovery, see Placing the Standby Database in Managed Recovery Mode. To learn how to open a standby database in read-only mode, see Opening a Standby Database in Read-Only Mode.
See Also:
Manual recovery mode is required in the following cases:
Managed Standby Environment? | Reason for Manual Recovery |
---|---|
Yes |
You must resolve a gap sequence; that is, you must put the standby database into a state in which you can initiate managed recovery (see Resolving a Gap Sequence Before Initiating Managed Recovery). |
No |
Managed recovery is not an option (see Non-Managed Recovery Environment), so you must manually transfer logs to the standby site and manually apply them to the standby database. |
Consequently, even if you implement a managed standby environment, you may occasionally need to perform manual recovery on the standby database.
See Also:
To learn how to perform manual recovery of a standby database, see Placing the Standby Database in Manual Recovery Mode. |
After you have started and mounted the standby database, you can place it in manual recovery mode. To keep the standby database current, you must manually apply archived redo logs from the primary database to the standby database.
Archived logs arrive at the standby site in one of the following ways:
The standby database assumes that the archived log file group is in the location specified by either of the following parameters in the standby initialization parameter file:
If the archived logs are not in the location specified in the initialization parameter file, you can specify an alternative location using the FROM option of the RECOVER statement.
STARTUP NOMOUNT pfile=initSTANDBY.ora
ALTER DATABASE MOUNT STANDBY DATABASE;
% cp /oracle/arc_dest/*.arc /standby/arc_dest
For example, execute one of the following statements:
RECOVER STANDBY DATABASE # uses location for logs specified in # initialization parameter file RECOVER FROM '/logs' STANDBY DATABASE # specifies nondefault location
As Oracle generates archived redo logs, you must continually transfer and apply them to the standby database to keep it current.
A gap sequence is a range of archived redo logs needed by the standby database before it can enter managed recovery mode. A standby database is able to begin managed recovery when you can apply the next archived log generated by the primary database to the standby database in managed recovery mode. This section contains the following topics:
A gap sequence can occur whenever the primary database archives a log but the log is not transferred to the standby site. Because the standby database requires the sequential application of redo logs, a missing log prevents managed recovery from applying subsquent logs.
Gap sequences can occur in the following situations:
One example of a gap sequence occurs when you create the standby database from an old backup. For example, if the standby database is made from a backup that contains changes through log 100, and the primary database currently contains changes through log 150, then the standby database requires that you manually apply logs 101 to 150 before managed recovery can begin.
Another typical example of a gap sequence occurs when you generate the standby database from a hot backup of an open database. For example, assume the scenario illustrated in Figure 3-1.
The following steps occur:
Archived logs 4 and 5 are now part of a gap sequence; that is, you must apply them manually to the standby database before managed recovery can apply archived logs 6, 7, and 8 to the standby database.
You may be required to shut down the standby database to resolve maintenance issues. For example, you must shut down the standby database in the following scenarios:
To avoid creating gap sequences, follow these rules:
If you violate either of these two rules, then the standby database is down while the primary database is open and archiving. Consequently, Oracle can create a gap sequence. When you restart the standby database later, you must synchronize the standby database manually with the primary database before you can initiate managed recovery.
Note: If the standby site is specified as MANDATORY in one of the LOG_ARCHIVE_DEST_n parameters of the primary initialization parameter file (see Specifying Mandatory and Optional Archive Destinations), dynamically change it to OPTIONAL before shutting down the standby database. Otherwise, the primary database eventually stalls because it cannot archive its online redo logs. |
If you maintain a managed standby environment, and the network goes down, the primary database may continue to archive to disk but be unable to archive to the standby site. In this situation, archived logs accumulate as usual on the primary site, but the standby instance is unaware of them.
To prevent this problem, you can specify that the standby destination have mandatory status. If the archiving destination is mandatory, then the primary database will not archive any logs until it is able to archive to the standby site. For example, you can set the following in the primary initialization parameter file to make STANDBY1 a mandatory archiving destination:
LOG_ARCHIVE_DEST_2 = 'SERVICE=standby1 MANDATORY'
One consequence of this configuration is that unless the network problem is fixed, the primary database eventually stalls because it cannot switch into an unarchived online redo log. This problem is exacerbated if you maintain only two online redo logs in your primary database.
See Also:
For a detailed account of the significance of the OPTIONAL and MANDATORY options for standby archival, see the chapter on archived redo logs in the Oracle8i Administrator's Guide. See Scenario 7: Recovering After a Network Failure for additional information. |
To determine whether there is a gap sequence, execute the SQL script in the following procedure. If there is a gap sequence, the output of the query specifies the thread number and log sequence number of all logs in the gap sequence. If there is no gap sequence for a given thread, the query returns either no rows or an identical number in the LowSeq# and HighSeq# columns.
SQL> CONNECT sys/sys_pwd@standby1 AS SYSDBA SQL> STARTUP NOMOUNT pfile=/oracle/admin/pfile/init.ora SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SELECT high.thread#, "LowGap#", "HighGap#" FROM ( SELECT thread#, MIN(sequence#)-1 "HighGap#" FROM ( SELECT a.thread#, a.sequence# FROM ( SELECT * FROM v$archived_log ) a, ( SELECT thread#, MAX(next_change#)gap1 FROM v$log_history GROUP BY thread# ) b WHERE a.thread# = b.thread# AND a.next_change# > gap1 ) GROUP BY thread# ) high, ( SELECT thread#, MIN(sequence#) "LowGap#" FROM ( SELECT thread#, sequence# FROM v$log_history, v$datafile WHERE checkpoint_change# <= next_change# AND checkpoint_change# >= first_change# ) GROUP BY thread# ) low WHERE low.thread# = high.thread#;
SQL> @gap THREAD# LowSeq# HighSeq# ---------- ---------- ---------- 1 460 463 2 202 204 3 100 100
Not every thread has a gap sequence. As this example illustrates, the LowSeq# and HighSeq# for thread 3 are identical, so no gap sequence exists for this thread.
You must apply the logs in the gap sequence for each thread to the standby database to prepare it for managed recovery.
See Also:
To learn how to perform manual recovery, see Placing the Standby Database in Manual Recovery Mode. |
After you have obtained the log sequence numbers of the logs in the gap sequence, you can obtain their filenames by querying the V$ARCHIVED_LOG view on the primary site (see Determining Which Archived Logs Have Been Received by the Standby Site). The archived log filenames on the standby site are generated by the STANDBY_ARCHIVE_DEST and LOG_ARCHIVE_FORMAT parameters in the standby initialization parameter file.
If the standby database is on the same host as the primary database, or the standby database is on a remote host with a different directory structure from the primary database, the filenames for the logs on the standby site cannot be the same as the filenames of the logs archived by the primary database. Before transmitting the archived logs to the standby site, determine the correct filenames for the logs at the standby site.
THREAD# LowSeq# HighSeq# ---------- ---------- ---------- 1 460 463 2 202 204 3 100 100
Note that no gap sequence exists for thread 3, so you only need to transmit logs from threads 1 and 2.
SQL> CONNECT sys/sys_pwd@primary SQL> SELECT name 2> FROM v$archived_log 3> WHERE sequence# in (460, 202); NAME ---------------------------------------------------------------------------- /primary/thread1_dest/arcr_1_460.arc /primary/thread2_dest/arcr_2_202.arc 2 rows selected.
STANDBY_ARCHIVE_DEST = /standby/arc_dest/ LOG_ARCHIVE_FORMAT = log_%t_%s.arc
These parameter settings determine the filenames of the archived redo logs at the standby site.
% cp /primary/thread1_dest/arcr_1_460.arc /standby/arc_dest/log_1_460.arc % cp /primary/thread1_dest/arcr_1_461.arc /standby/arc_dest/log_1_461.arc % cp /primary/thread1_dest/arcr_1_462.arc /standby/arc_dest/log_1_462.arc % cp /primary/thread1_dest/arcr_1_463.arc /standby/arc_dest/log_1_463.arc % cp /primary/thread1_dest/arcr_2_202.arc /standby/arc_dest/log_2_202.arc % cp /primary/thread1_dest/arcr_2_203.arc /standby/arc_dest/log_2_203.arc % cp /primary/thread1_dest/arcr_2_204.arc /standby/arc_dest/log_2_204.arc
For example, assume the following standby initialization parameter settings:
STANDBY_ARCHIVE_DEST = /standby/arc_dest/ LOG_ARCHIVE_DEST = /log_dest/
Because the parameter values are different, copy the archived logs to the LOG_ARCHIVE_DEST location:
% cp /standby/arc_dest/* /log_dest/
When you initiate manual recovery, Oracle looks at the LOG_ARCHIVE_DEST value to determine the location of the logs.
Now that all required logs are in the STANDBY_ARCHIVE_DEST directory, you can proceed to the next stage: applying the gap sequence logs to the standby database.
After you have transmitted the logs in the gap sequence to the standby site, you can apply them using the RECOVER AUTOMATIC statement. Once applied, you can go on to place the standby database in managed recovery mode.
SQL> CONNECT sys/sys_pwd@standby1 AS SYSDBA SQL> STARTUP NOMOUNT pfile=/oracle/admin/pfile/initSTBY.ora SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER AUTOMATIC STANDBY DATABASE
After recovering the available logs, Oracle prompts for the name of a log that does not exist. The reason is that the recovery process does not know about the logs archived to the standby site by the primary database. For example, you might see:
ORA-00308: cannot open archived log '/oracle/standby/standby_logs/arcr_1_ 540.arc' ORA-27037: unable to obtain file status SVR4 Error: 2: No such file or directory Additional information: 3 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
SQL> CANCEL Media recovery cancelled.
Note that the following error messages are acceptable after recovery cancellation and do not indicate a problem:
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below ORA-01194: file 1 needs more recovery to be consistent ORA-01110: data file 1: 'some_filename' ORA-01112: media recovery not started
You are now able to initiate managed recovery.
If you implement a managed standby environment, you can automate archiving to either a local or remote host. Oracle keeps the standby database synchronized with the primary database by waiting for archived logs from the primary database and then automatically applying them to the standby database, as shown in Figure 3-2. This feature eliminates the need to interactively provide the recovery process with the filenames of the archived logs.
Enable managed recovery using the following SQL*Plus statement:
RECOVER MANAGED STANDBY DATABASE
You can use the TIMEOUT option of the RECOVER statement to specify an optional timeout interval. In this case, the managed recovery operation waits the specified number of minutes for Oracle to write the requested archived log entry to the standby control file's directory.
If Oracle times out because it cannot find the required next log entry in the standby control file, the system issues an appropriate message and exits managed recovery mode. By default, the managed recovery operation waits indefinitely for the next archived log; it terminates only through a CANCEL statement (or CTRL+C key combination), a shutdown, or a crash.
STARTUP NOMOUNT pfile=initSTANDBY.ora
ALTER DATABASE MOUNT STANDBY DATABASE;
RECOVER MANAGED STANDBY DATABASE
If you want to use the optional timeout option, add TIMEOUT integer to the command syntax:
RECOVER MANAGED STANDBY DATABASE TIMEOUT 60
Oracle now begins managed recovery. As the primary database archives redo logs to the standby site, the standby database automatically applies them.
Several methods exist for determining the status of archived redo logs, as explained in Troubleshooting the Standby Database Configuration. The following procedure forces archiving at the primary site, which allows you to query a view on the standby database to determine whether the archived log was applied.
% sqlplus sys/sys_pwd@primary SQL> SELECT status FROM v$instance; STATUS ------- OPEN
ALTER SYSTEM ARCHIVE LOG CURRENT; System altered.
SQL> SELECT max(sequence#) FROM v$log_history; MAX(SEQUENCE#) -------------- 541
% sqlplus sys/sys_pwd@standby1 SQL> SELECT max(sequence#) FROM v$log_history; MAX(SEQUENCE#) -------------- 541
The sequence number should be the same as the number on the primary site. If it is not, wait a short time for Oracle to finish receiving and applying the log and try again. If Oracle still does not apply the log, see Troubleshooting the Standby Database Configuration for ways of obtaining troubleshooting information.
Cancel the managed recovery operation at any time by issuing either of the following SQL*Plus statements:
RECOVER MANAGED STANDBY DATABASE CANCEL RECOVER MANAGED STANDBY DATABASE CANCEL IMMEDIATE
The first statement waits for the managed recovery operation to finish with the current redo log before terminating recovery. If you use the IMMEDIATE option, however, Oracle stops the managed recovery operation either before reading another block from the redo log or before opening the next redo log file, whichever comes first. Note the following scenarios:
The read-only mode allows users to open and query a standby database without the potential for online data modifications. This functionality enables you to reduce system overhead on the primary database by using the standby database for reporting purposes. Also, you can periodically open the standby database in read-only mode to ensure that a managed standby database is being updated properly.
This section contains the following topics:
When determining whether to run the standby database in read-only mode, consider the following:
If you need the standby database both for disaster prevention and reporting, then you can maintain multiple standby databases, some read-only and some in managed recovery mode. You will need to resynchronize the read-only database, but the recovery mode databases give you protection against disaster.
While the standby database is in read-only mode, the site can still receive archived redo logs from the primary site. Nevertheless, Oracle does not apply these logs automatically, as in managed recovery. Consequently, a read-only standby database is not synchronized with the primary database at the archive level. You should not activate the standby database in a failover situation unless all archived redo logs have been applied.
The following states are possible for a standby database:
You can move from any of the first three states into read-only mode (and back again) using the following procedures.
SQL> STARTUP NOMOUNT pfile=initSTANDBY.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> ALTER DATABASE OPEN READ ONLY;
SQL> RECOVER CANCEL
SQL> ALTER DATABASE OPEN READ ONLY;
SQL> RECOVER MANAGED STANDBY DATABASE CANCEL
SQL> ALTER DATABASE OPEN READ ONLY;
SQL> RECOVER MANAGED STANDBY DATABASE # you can also set the TIMEOUT option
SQL> RECOVER STANDBY DATABASE # you can also set the TIMEOUT option
In order to perform queries on a read-only standby database, the Oracle database server needs to be able to perform on-disk sorting operations. You cannot allocate space for sorting operations in tablespaces that cause Oracle to write to the data dictionary, however, for these modifications cause the standby control file to diverge from the primary control file.
Temporary tablespaces allow you to add tempfile entries in read-only mode for the purposes of making queries. You can then perform on-disk sorting operations in an Oracle8i read-only database without affecting dictionary files or generating redo entries.
Note the following requirements for creating temporary tablespaces:
You should also follow these guidelines:
For more information about using tempfiles and temporary tablespaces, see the Oracle8i Administrator's Guide.
See Also:
SQL> CREATE TEMPORARY TABLESPACE tbs_1 TEMPFILE 'file_1.f' EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;
You should not activate or perform a failover to the standby database except in an emergency. After it is activated, the standby database becomes a normal production database and loses its standby functionality. You cannot undo the activation and return the database to standby mode.
Depending on the nature of the emergency, you may not have access to your primary database files. If you do have access, then you should attempt to archive the current online redo log on the primary database manually, and then transfer and apply all available archived redo logs to the standby database.
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
% cp /oracle/arc_dest/*.arc /standby/arc_dest
SQL> CANCEL
If the standby database is not currently in managed recovery mode, put it in a mounted state. For example, if the standby instance is not started, enter:
SQL> STARTUP NOMOUNT pfile=initSTANDBY.ora SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER AUTOMATIC STANDBY DATABASE # uses location for logs listed in initialization parameter file SQL> RECOVER AUTOMATIC FROM '/logs' STANDBY DATABASE # specifies nondefault location
Following this procedure rolls forward the standby database to the time immediately before the failure of the primary database. You can apply any redo log other than the current redo log to the standby database. If you have lost your noncurrent online redo logs and they have not been archived, then activate the standby database without recovering the transactions from the unarchived redo logs of the primary database.
Activating the standby database automatically resets the online redo logs. Note that the redo logs from the standby database and primary database are now incompatible. You cannot apply archived redo logs from the original primary database to the activated standby database or vice versa. Also, the standby database is not mounted when activated; therefore, the tables and views do not contain useful information immediately after activation.
SQL> SELECT name,value FROM v$parameter WHERE name='parallel_server'; NAME VALUE ----------------------------------------------------------------- parallel_server FALSE 1 row selected.
If the value is TRUE, then the database is not mounted exclusively; if the value is FALSE, then the database is mounted exclusively.
SQL> ALTER DATABASE ACTIVATE STANDBY DATABASE;
Note that this command resets the online redo logs.
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT SQL> ALTER DATABASE READ ONLY; # opens the database in read-only mode SQL> ALTER DATABASE READ WRITE; # opens the database in read/write mode
You can use a standby database in conjunction with the Oracle Parallel Server (OPS) option. The following table describes the possible combinations of nodes in the primary and standby databases:
Single-Instance Standby Database | Multi-Instance Standby Database | |
---|---|---|
Single-Instance Primary Database |
Yes |
Yes (for read-only queries) |
Multi-Instance Primary Database |
Yes |
Yes |
In each scenario, each node of the primary database transmits its own thread of archived redo logs to the standby database. For example, Figure 3-3 illustrates an Oracle Parallel Server database with two nodes transmitting redo logs to a single-instance standby database.
In this case, node 1 of the primary database transmits logs 1, 2, 3, 4, 5 while node 2 transmits logs 32, 33, 34, 35, 36. If the standby database is in managed recovery mode, it automatically determines the correct order in which to apply the archived redo logs.
If both your primary and standby databases are in an Oracle Parallel Server configuration, and the standby database is in managed recovery mode, then a single node of the standby database applies all sets of logs transmitted by the primary nodes. In this case, the standby nodes that are not applying redo cannot be in read-only mode while managed recovery is in progress; in most cases, the non-recovery nodes should be shut down, although they can also be mounted.
See Also:
For information about configuring a database for Oracle Parallel Server, see the Oracle8i Parallel Server Setup and Configuration Guide. |
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|