Oracle Data Guard Concepts and Administration Release 2 (9.2) Part Number A96653-02 |
|
|
View PDF |
This chapter describes how to manage a physical standby database. Data Guard provides the means to easily manage, manipulate, and change a physical standby database in many ways.
This chapter contains the following topics:
This section describes the procedures for starting up and shutting down a physical standby database.
To start up a physical standby database, use SQL*Plus to connect to the database with administrator privileges, and then use the SQL*Plus STARTUP
command with the NOMOUNT
option. (You must use the NOMOUNT
option with a standby database.)
If both the primary and standby databases are offline, then always (if possible) start the standby database before starting the primary database.
After the database is started, mount the database as a standby database. Once it is mounted, the database can receive archived redo data from the primary database.
You then have the option of either starting a managed recovery operation or opening the database for read-only access. Typically, you start a managed recovery operation. The following example shows how to start a standby database:
SQL> STARTUP NOMOUNT;
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE 2> DISCONNECT FROM SESSION;
Once the database is performing managed recovery, log apply services apply the archived redo logs to the standby database.
See Also:
Section 6.2.2 for information about managed recovery and Section 8.2 for information on opening a standby database for read-only access |
To shut down a physical standby database, use the SQL*Plus SHUTDOWN
command. If the database is performing managed recovery, you must cancel managed recovery operations before issuing the SHUTDOWN
command. Control is not returned to the session that initiates a database shutdown until shutdown is complete.
If the primary database is up and running, defer the archive log destination on the primary database and perform a log switch operation (to make the defer operation take effect) before shutting down the standby database. Otherwise, log transport services will not be able to transmit redo data to this standby site.
The following steps show you how to shut down a standby database:
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> SHUTDOWN IMMEDIATE;
When a standby database is open for read-only access, users can query the standby database without the potential for online data modifications. This reduces the load on the primary database by using the standby database for reporting purposes. You can periodically open the standby database for read-only access and perform ad hoc queries to ensure that log apply services are updating the standby database correctly.
Figure 8-1 shows a standby database open for read-only access.
Text description of the illustration sbr81099.gif
This section contains the following topics:
As you decide whether or not to open a physical standby database for read-only access, consider the following:
You can alternate between having a standby database open for read-only access and having a standby database perform managed recovery using the following procedures.
SQL> STARTUP NOMOUNT;
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> ALTER DATABASE OPEN READ ONLY;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE OPEN READ ONLY;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE; 2> DISCONNECT FROM SESSION;
Before you open your standby database for read-only access, consider the following topics regarding sorting operations:
To perform queries that sort a large amount of data on a standby database that is open for read-only access, the Oracle database server must be able to perform on-disk sorting operations. You cannot allocate space for sorting operations in tablespaces that cause Oracle software to write to the data dictionary.
Temporary tablespaces allow you to add tempfile
entries when the database is open for read-only access for the purpose of making queries without affecting dictionary files or generating redo entries. Therefore, you can use temporary tablespaces as long as you follow these requirements for creating them:
If you did not have a temporary tablespace on the primary database when you created the physical standby database, perform the following steps on the primary database:
SQL> CREATE TEMPORARY TABLESPACE temp1 TEMPFILE '/disk1/oracle/dbs/temp1.dbf' SIZE 20M REUSE EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;
SQL> ALTER SYSTEM SWITCH LOGFILE;
The redo data that is generated on the primary database automatically creates the temporary tablespace in the standby control file after the archived redo log is applied to the physical standby database. However, even if the temporary tablespace existed on the primary database before you created the physical standby database, you must use the ADD TEMPFILE
clause to actually create the disk file on the standby database.
On the physical standby database, perform the following steps:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; SQL> ALTER DATABASE OPEN READ ONLY;
Opening the physical standby database for read-only access allows you to add a temporary file. Because adding a temporary file does not generate redo data, it is allowed for a database that is open for read-only access.
SQL> ALTER TABLESPACE temp1 ADD TEMPFILE '/disk1/oracle/dbs/s_temp1.dbf' SIZE 10M REUSE;
See Also:
Oracle9i SQL Reference for information about the |
If a temporary file does not exist on the standby database, or if the standby database is not open and you attempt to sort a large amount of data, an error is returned, as shown in the following example.
SQL> SELECT * FROM V$PARAMETER; select * from v$parameter * ERROR at line 1: ORA-01220: file based sort illegal before database is open
Note that you can, however, sort small amounts of data if the SORT_AREA_SIZE
parameter is set to a sufficient value in your server parameter file. (The SORT_AREA_SIZE
parameter is a static parameter.)
You can use the physical standby database to off-load the database backup operation from the primary database because a physical standby database is a copy of the primary database. Using RMAN at the standby site, you can back up the datafiles and the archived redo logs while the standby database is performing managed recovery. Later, you can restore these backups to the primary database using RMAN.
See Also:
Oracle9i Recovery Manager User's Guide for more details about RMAN backup and recovery of a primary database using a standby database |
To prevent possible problems, you should be aware of events in the primary database that affect a standby database and learn how to respond to them. This section describes these events and the recommended responses to these events.
In some cases, the events or changes that occur on a primary database are automatically propagated through archived redo logs to the standby database and thus require no extra action on the standby database. In other cases, you might need to perform maintenance tasks on the standby database.
Table 8-1 indicates whether or not a change made on the primary database requires additional intervention by the database administrator (DBA) to be propagated to the standby database. It also briefly describes how to respond to these events. Detailed descriptions of the responses are described in the section references provided.
The following events are automatically administered by log transport services and log apply services, and therefore require no intervention by the database administrator:
ALTER DATABASE
statement is issued with the ENABLE THREAD
or DISABLE THREAD
clause.STANDBY_FILE_MANAGEMENT
initialization parameter is set to AUTO.
The initialization parameter, STANDBY_FILE_MANAGEMENT
, allows you to control whether or not adding a datafile to the primary database is automatically propagated to the standby database, as follows:
STANDBY_FILE_MANAGEMENT
initialization parameter in the standby database server parameter file to AUTO
, any new datafiles created on the primary database are automatically created on the standby database as well.STANDBY_FILE_MANAGEMENT
initialization parameter or if you set it to MANUAL
, then you must manually copy the new datafile to the standby database when you add a datafile to the primary database.Note that if you copy an existing datafile from another database to the primary database, then you must also copy the new datafile to the standby database and re-create the standby control file, regardless of the setting of STANDBY_FILE_MANAGEMENT
initialization parameter.
The following sections provide examples of adding a datafile to the primary and standby databases when the STANDBY_FILE_MANAGEMENT
initialization parameter is set to AUTO
and MANUAL,
respectively.
The following example shows the steps required to add a new datafile to the primary and standby databases when the STANDBY_FILE_MANAGEMENT
initialization parameter is set to AUTO
.
SQL> CREATE TABLESPACE new_ts DATAFILE 't_db2.dbf' 2> SIZE 1m AUTOEXTEND ON MAXSIZE UNLIMITED;
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
SQL> SELECT NAME FROM V$DATAFILE; NAME ---------------------------------------------------------------------- /disk1/oracle/dbs/t_db1.dbf /disk1/oracle/dbs/t_db2.dbf
SQL> SELECT NAME FROM V$DATAFILE; NAME ---------------------------------------------------------------------- /disk1/oracle/dbs/s2t_db1.dbf /disk1/oracle/dbs/s2t_db2.dbf
The following example shows the steps required to add a new datafile to the primary and standby database when the STANDBY_FILE_MANAGEMENT
initialization parameter is set to MANUAL
. You must set the STANDBY_FILE_MANAGEMENT
initialization parameter to MANUAL
when the standby datafiles reside on raw devices.
SQL> CREATE TABLESPACE new_ts DATAFILE 't_db2.dbf' 2> SIZE 1m AUTOEXTEND ON MAXSIZE UNLIMITED;
SQL> SELECT NAME FROM V$DATAFILE; NAME ---------------------------------------------------------------------- /disk1/oracle/dbs/t_db1.dbf /disk1/oracle/dbs/t_db2.dbf
SQL> ALTER TABLESPACE new_ts OFFLINE;
cp
command:
% cp t_db2.dbf s2t_db2.dbf
SQL> ALTER TABLESPACE new_ts ONLINE;
rcp
command:
%rcp s2t_db2.dbf standby_location
SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
SQL> SELECT NAME FROM V$DATAFILE; NAME ---------------------------------------------------------------------- /disk1/oracle/dbs/s2t_db1.dbf /disk1/oracle/dbs/s2t_db2.dbf
When you delete one or more datafiles or drop one or more tablespaces in the primary database, you also need to delete the corresponding datafiles in the standby database, as follows:
SQL> DROP TABLESPACE tbs_4; SQL> ALTER SYSTEM SWITCH LOGFILE; % rm tbs_4.dbf
SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;
% rm tbs_4.dbf
% rm tbs_4.dbf
When you rename one or more datafiles in the primary database, the change is not propagated to the standby database. Therefore, if you want to rename the same datafiles on the standby database, you must manually make the equivalent modifications on the standby database because the modifications are not performed automatically, even if the STANDBY_FILE_MANAGEMENT
initialization parameter is set to AUTO
.
The following steps describe how to rename a datafile in the primary database and manually propagate the changes to the standby database. If you do not want the standby database to have the same physical structure as the primary database, then these steps are not required.
SQL> ALTER TABLESPACE tbs_4 OFFLINE;
mv
command, to rename the datafile on the primary system:
% mv tbs_4.dbf tbs_x.dbf
SQL> ALTER TABLESPACE tbs_4 RENAME DATAFILE 'tbs_4.dbf' 2> TO 'tbs_x.dbf'; SQL> ALTER TABLESPACE tbs_4 ONLINE;
SQL> SELECT NAME, SEQUENCE#, ARCHIVED, APPLIED 2> FROM V$ARCHIVED_LOG; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> SHUTDOWN;
mv
command:
% mv tbs_4.dbf tbs_x.dbf
SQL> STARTUP NOMOUNT; SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
STANDBY_FILE_MANAGEMENT
initialization parameter must be set to MANUAL
.
SQL> ALTER DATABASE RENAME FILE 'tbs_4.dbf' 2> TO 'tbs_x.dbf';
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE 2> DISCONNECT FROM SESSION;
If you do not rename the corresponding datafile at the standby site, and then try to refresh the standby database control file, the standby database will attempt to use the renamed datafile, but it will not find it. Consequently, you will see error messages similar to the following in the alert log:
ORA-00283: recovery session canceled due to errors ORA-01157: cannot identify/lock data file 4 - see DBWR trace file ORA-01110: data file 4: '/disk1/oracle/dbs/tbs_x.dbf'
Changing the size and number of the online redo logs is sometimes done to tune the database. You can add redo log file groups or members to the primary database without affecting the standby database. Similarly, you can drop log file groups or members from the primary database without affecting your standby database. However, these changes do affect the performance of the standby database after switchover.
For example, if the primary database has 10 redo logs and the standby database has 2, and then you switch over to the standby database so that it functions as the new primary database, the new primary database is forced to archive more frequently than the original primary database.
Consequently, when you add or drop an online redo log at the primary site, it is important that you synchronize the changes in the standby database by following these steps:
STANDBY_FILE_MANAGEMENT
initialization parameter is set to AUTO
, change the value to MANUAL
.STANDBY_FILE_MANAGEMENT
initialization parameter and the managed recovery options to their original states.Using the SQL CREATE CONTROLFILE
statement with the RESETLOGS
option on your primary database will force the primary database to reset the online logs the next time the primary database is opened, thereby invalidating the standby database.
If you invalidated the control file for the standby database, re-create the file using the procedure provided in Section 3.2.3.
If you invalidated the standby database, you must re-create the standby database using the procedures in Chapter 3.
When you perform a DML or DDL operation using the NOLOGGING
or UNRECOVERABLE
clause, the standby database is invalidated and might require substantial DBA administrative activities to repair. You can specify the SQL ALTER DATABASE
or SQL ALTER TABLESPACE
statement with the FORCELOGGING
clause to override the NOLOGGING
setting. However, this statement will not repair an invalidated database.
If you perform an unrecoverable operation (such as a direct path load), you will see a performance improvement on the primary database; but there is no corresponding recovery process performance improvement on the standby database, and you will have to move the data manually to the standby database.
See Also:
Section 10.5 for information about recovering after the |
This section gives you a general overview on where to find information for monitoring the primary and standby databases in a Data Guard environment.
This section contains the following topics:
Table 8-2 summarizes common events that occur on the primary database and pointers to the files and views where you can monitor these events on the primary and standby sites.
Primary Database Event | Primary Site Information | Standby Site Information |
---|---|---|
A SQL |
Alert log |
|
Redo log changed |
Alert log |
|
|
Alert log |
Alert logFoot 1 |
Managed recovery performed |
Alert log |
Alert log |
Tablespace status changes made (made read/write or read-only, placed online or offline) |
|
|
Datafile added or tablespace created |
Alert log |
|
Tablespace dropped |
Alert log |
|
Tablespace or datafile taken offline, or datafile is deleted offline |
|
|
Rename datafile |
Alert log |
|
Unlogged or unrecoverable operations |
Alert log |
|
Recovery progress |
Alert log |
|
Autoextend a datafile |
Alert log |
Alert log |
Issue |
Alert log |
Alert log |
Change initialization parameter |
Alert log |
Alert log |
1 When you issue a CREATE CONTROLFILE statement on the primary database, the standby database functions normally until it encounters redo data that depends on initialization parameters. |
The database alert log is a chronological record of messages and errors. Besides providing information about the Oracle database, it also includes information about operations specific to Data Guard, including the following:
ALTER DATABASE RECOVER MANAGED STANDBY, STARTUP, SHUTDOWN
, ARCHIVE LOG
, and RECOVER
The alert log also provides pointers to the trace or dump files generated by a specific process.
The Oracle database server contains a set of underlying views that are maintained by the server. These views are often called dynamic performance views because they are continuously updated while a database is open and in use, and their contents relate primarily to performance. These views are also called fixed views because they cannot be altered or removed by the database administrator.
These view names are prefixed with either V$ or GV$, for example, V$ARCHIVE_DEST
or GV$ARCHIVE_DEST
.
Standard dynamic performance views (V$ fixed views) store information on the local instance. In contrast, global dynamic performance views (GV$ fixed views), store information on all open instances. Each V$ fixed view has a corresponding GV$ fixed view.
See Also:
Chapter 14, "Views" and the Oracle9i Database Reference for additional information on view columns |
This section shows some samples of the types of views discussed in Section 8.5.2 for monitoring recovery progress in a Data Guard environment. It contains the following examples:
You can obtain information about managed recovery operations on a standby database by monitoring the activities performed by the following processes:
The V$MANAGED_STANDBY
view on the standby database site shows you the activities performed by both log transport and log apply processes in a Data Guard environment. The CLIENT_P
column in the output of the following query identifies the corresponding primary database process.
SQL> SELECT PROCESS, CLIENT_PROCESS, SEQUENCE#, STATUS FROM V$MANAGED_STANDBY; PROCESS CLIENT_P SEQUENCE# STATUS ------- -------- ---------- ------------ ARCH ARCH 0 CONNECTED ARCH ARCH 0 CONNECTED MRP0 N/A 204 WAIT_FOR_LOG RFS LGWR 204 WRITING RFS N/A 0 RECEIVING
The V$ARCHIVE_DEST_STATUS
view on either a primary or standby database site provides you information such as the redo logs that are archived, the archived redo logs that are applied, and the log sequence numbers of each. The following query output shows the standby database is two archived logs behind in applying the redo logs received from the primary database.
SQL> SELECT ARCHIVED_THREAD#, ARCHIVED_SEQ#, APPLIED_THREAD#, APPLIED_SEQ# 2> FROM V$ARCHIVE_DEST_STATUS; ARCHIVED_THREAD# ARCHIVED_SEQ# APPLIED_THREAD# APPLIED_SEQ# ---------------- ------------- --------------- ------------ 1 947 1 945
You can also query the V$ARCHIVED_LOG
view on the standby database to find additional information about archived redo logs. Some information you can get includes the location of the archived redo log, which process created the archived redo log, redo log sequence number of each archived redo log, when the log was archived, and whether or not the archived redo log was applied. For example:
SQL> SELECT NAME, CREATOR, SEQUENCE#, APPLIED, COMPLETION_TIME 2> FROM V$ARCHIVED_LOG; NAME CREATOR SEQUENCE# APP COMPLETIO ---------------------------------------------- ------- --------- --- --------- H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00198.001 FGRD 198 YES 30-MAY-02 H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00199.001 FGRD 199 YES 30-MAY-02 H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00200.001 FGRD 200 YES 30-MAY-02 H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00201.001 LGWR 201 YES 30-MAY-02 H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00202.001 FGRD 202 YES 30-MAY-02 H:\ORACLE\ORADATA\PAYROLL\STANDBY\ARC00203.001 LGWR 203 YES 30-MAY-02 6 rows selected.
The V$LOG_HISTORY
on the physical standby site shows you a complete history of the archived log, including information such as the time of the first entry, the lowest SCN in the log, the highest SCN in the log, and the sequence number of the archived log.
SQL> SELECT FIRST_TIME, FIRST_CHANGE#, NEXT_CHANGE#, SEQUENCE# FROM V$LOG_ HISTORY; FIRST_TIM FIRST_CHANGE# NEXT_CHANGE# SEQUENCE# --------- ------------- ------------ ---------- 13-MAY-02 190578 214480 1 13-MAY-02 214480 234595 2 13-MAY-02 234595 254713 3 . . . 30-MAY-02 3418615 3418874 201 30-MAY-02 3418874 3419280 202 30-MAY-02 3419280 3421165 203 203 rows selected.
Query the V$LOG_HISTORY
view on the standby database, which records the latest log sequence number that was applied. For example, issue the following query:
SQL> SELECT THREAD#, MAX(SEQUENCE#) AS "LAST_APPLIED_LOG" 2> FROM V$LOG_HISTORY 3> GROUP BY THREAD#; THREAD# LAST_APPLIED_LOG ------- ---------------- 1 967
In this example, the archived redo log with log sequence number 967 is the most recently applied log.
You can also use the APPLIED
column in the V$ARCHIVED_LOG
fixed view on the standby database to find out which log is applied on the standby database. The column displays YES
for the log that was applied. For example:
SQL> SELECT THREAD#, SEQUENCE#, APPLIED FROM V$ARCHIVED_LOG; THREAD# SEQUENCE# APP ---------- ---------- --- 1 2 YES 1 3 YES 1 4 YES 1 5 YES 1 6 YES 1 7 YES 1 8 YES 1 9 YES 1 10 YES 1 11 NO 10 rows selected.
Each archive destination has a destination ID assigned to it. You can query the DEST_ID
column in the V$ARCHIVE_DEST
fixed view to find out your destination ID. You can then use this destination ID in a query on the primary database to discover logs that were not sent to a particular standby site.
For example, assume the current local archive destination ID on your primary database is 1, and the destination ID of one of your remote standby databases is 2. To find out which logs were not received by this standby destination, issue the following query on the primary database:
SQL> SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM 2> (SELECT THREAD#, SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=1) LOCAL 3> WHERE 4> LOCAL.SEQUENCE# NOT IN 5> (SELECT SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND 6> THREAD# = LOCAL.THREAD#); THREAD# SEQUENCE# ---------- ---------- 1 12 1 13 1 14
The preceding example shows the logs that were not received by standby destination 2.