Pages

Tuesday, September 15, 2015

Log Apply Services

Log Apply Services


This chapter describes how redo logs are applied to a standby database. It includes the following topics:

6.1 Introduction to Log Apply Services

Log apply services automatically apply archived redo logs to maintain synchronization with the primary database and allow transactionally consistent access to the data. Archived redo data is not available for log apply services until a log switch occurs on the primary database.
The main difference between physical and logical standby databases is the manner in which log apply services apply the archived redo logs. For physical standby databases, log apply services maintain the standby database by performing managed recovery operations. For logical standby databases, log apply services maintain the standby database by executing SQL statements. The following list summarizes these operations:
  • Managed recovery operations (physical standby databases only)
    In this mode, log transport services transmit redo data to the standby site, and log apply services automatically apply the redo logs.
    .

    Caution:
    You can also open a physical standby database for read-only operations to allow users to query the standby database for reporting purposes. However, while a standby database that is open for read-only access, it is not kept transactionally current with the primary database, resulting in prolonging a failover or switchover operation if one is required for disaster recovery. See Section 8.2, "Using a Standby Database That Is Open for Read-Only Access" for more information.

  • SQL apply operations (logical standby databases only)
    Log apply services manage logical standby databases by executing SQL statements. Logical standby databases can be opened in read/write mode, but the target tables being maintained by the logical standby database are opened in read-only mode for reporting purposes. The SQL apply mode allows you to use the logical standby database for reporting activities even while SQL statements are being applied.
The sections in this chapter describe the managed recovery and SQL apply operations, and log apply services in more detail.

6.2 Applying Redo Data to Physical Standby Databases

The physical standby database uses several processes to automate archiving redo data and recovering redo logs on the standby database. On the standby database, log apply services use the following processes:
  • Remote file server (RFS)
    The remote file server (RFS) process receives redo data from the primary database either in the form of archived redo logs or standby redo logs.
  • Archiver (ARCn)
    If standby redo logs are being used, the ARCn process archives the standby redo logs that are to be applied by the managed recovery process (MRP).
  • Managed recovery process (MRP)
    The managed recovery process (MRP) applies information from the archived redo logs to the standby database. When performing managed recovery operations, log apply services automatically apply archived redo logs to maintain transactional synchronization with the primary database.
Log apply services can apply logs to a physical standby database when the database is performing recovery, but not when it is open for read-only operations). A physical standby database can be performing one of the following:
  • Managed recovery operations
  • Read-only operations
Table 6-1 summarizes the basic tasks for configuring and monitoring log apply services.
Table 6-1 Task List: Configuring Log Apply Services for Physical Standby Databases
StepTaskSee ...
1
Start the standby instance and mount the standby database.
2
Enable managed recovery or read-only operations.
Section 6.2.2.1 or Section 8.2, respectively
3
If performing managed recovery operations, set initialization parameters to automatically resolve archive gaps.
4
Monitor log apply services.

6.2.1 Starting the Physical Standby Instance

After all necessary parameter and network files are configured, you can start the standby instance. If the standby instance is not started and mounted, the standby database cannot receive redo data from the primary database.
To start the physical standby database instance, perform the following steps:
  1. Start the physical standby instance without mounting the database:
    SQL> STARTUP NOMOUNT;
    
  2. Mount the physical standby database. For example:
    SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
    

6.2.2 Starting Managed Recovery Operations

Log apply services keep the standby database synchronized with the primary database by automatically applying archived redo logs to the standby database, as shown in Figure 6-1.

Figure 6-1 Automatic Updating of a Physical Standby Database

Text description of redoapply.gif follows.
Text description of the illustration redoapply.gif

6.2.2.1 Starting Log Apply Services

You can specify that log apply services run as a foreground session or as a background process.
  • To start a foreground session, issue the SQL statement:
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
    
    
    If you started a foreground session, by default, control is not returned to the command prompt.
  • To start a background process, you must use the DISCONNECT keyword on the SQL statement. For example:
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT;
    
    
    This statement starts a detached server process and immediately returns control to the user. While the managed recovery process is performing recovery in the background, the foreground process that issued the RECOVER statement can continue performing other tasks. This does not disconnect the current SQL session.
  • If you did not start log apply services as a detached server process, you can stop log apply services by the issuing the following SQL statement in another window:
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
    
    
    See Also:

6.2.2.2 Monitor the Recovery Process

You can query views to monitor log apply services as follows:
  1. To verify that you have correctly initiated log apply services, query the V$MANAGED_STANDBY fixed view on the standby database. This view monitors the progress of a standby database in managed recovery mode. For example:
    SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS
      2> FROM V$MANAGED_STANDBY;
    
    PROCESS STATUS       THREAD#    SEQUENCE#  BLOCK#     BLOCKS
    ------- ------------ ---------- ---------- ---------- ----------
    MRP0    APPLYING_LOG 1          946        10         1001
    
    If you did not start a detached server process, you need to execute this query from another SQL session.
  2. To monitor activity on the standby database, query the V$ARCHIVE_DEST_STATUS fixed view.
    See Also:

6.2.3 Controlling Redo Apply Operations

Although this SQL ALTER DATABASE RECOVER MANAGED STANDBY DATABASE statement does not require any additional clauses, it provides many keywords to help you control the redo apply process.
See Also:
Section 13.12 and Oracle9i SQL Reference for complete information about the SQL statement syntax

6.2.4 Datafile Management

To enable the automatic creation of new datafiles on a physical standby database when datafiles are created on the primary database, you must define the STANDBY_FILE_MANAGEMENT initialization parameter.
If the directory structures on the primary and standby databases are different, you must also set the DB_FILE_NAME_CONVERT initialization parameter to convert the filenames of one or more sets of datafiles on the primary database to filenames on the standby database.

6.2.4.1 Setting the STANDBY_FILE_MANAGEMENT Initialization Parameter

When you set the STANDBY_FILE_MANAGEMENT initialization parameter to AUTO, it automatically creates on the standby database any datafiles that were newly created on the primary database, using the same name that you specified on the primary database.
The STANDBY_FILE_MANAGEMENT initialization parameter works with the DB_FILE_NAME_CONVERT parameter to convert the datafile locations from the primary site to standby site.

6.2.4.2 Setting the DB_FILE_NAME_CONVERT Initialization Parameter

When a new datafile is added on the primary database, the same datafile is created on the standby database. The DB_FILE_NAME_CONVERT parameter is used to convert the datafile name on the primary database to a datafile name on the standby database. This parameter works the same if the STANDBY_FILE_MANAGEMENT initialization parameter is set to AUTO or MANUAL.
The DB_FILE_NAME_CONVERT initialization parameter must specify paired strings. The first string is a sequence of characters to be looked for in a primary database filename. If that sequence of characters is matched, it is replaced by the second string to construct the standby database filename. You can specify multiple pairs of filenames. For example:
DB_FILE_NAME_CONVERT= "/disk1/oracle/oradata/payroll/df1", \ 
"/disk1/oracle/oradata/payroll/standby/df1", \
"/disk1/oracle/oradata/payroll", "/disk1/oracle/oradata/payroll/standby/"
STANDBY_FILE_MANAGEMENT=AUTO

Note:
When you specify pairs of files, be sure to specify the most restrictive path names before the least restrictive, as shown in the example.

6.2.4.3 Restrictions on ALTER DATABASE Operations

You cannot rename the datafile on the standby site when the STANDBY_FILE_MANAGEMENT initialization parameter is set to AUTO. When you set the STANDBY_FILE_MANAGEMENT initialization parameter to AUTO, use of the following SQL statements is not allowed:
  • ALTER DATABASE RENAME
  • ALTER DATABASE ADD/DROP LOGFILE
  • ALTER DATABASE ADD/DROP STANDBY LOGFILE MEMBER
  • ALTER DATABASE CREATE DATAFILE AS
If you attempt to use any of these statements on the standby database, an error is returned. For example:
SQL> ALTER DATABASE RENAME FILE '/disk1/oracle/oradata/payroll/t_db2.log' to 'dummy'; 
alter database rename file '/disk1/oracle/oradata/payroll/t_db2.log' to 'dummy' 
* 
ERROR at line 1: 
ORA-01511: error in renaming log/data files 
ORA-01270: RENAME operation is not allowed if STANDBY_FILE_MANAGEMENT is auto
See Also:
Section 8.4.1 to learn how to add datafiles to a database

6.3 Applying Redo Data to Logical Standby Databases

Log apply services convert the data from the redo logs into SQL statements and then executes these SQL statements on the logical standby database. Because the logical standby database remains open, tables that are maintained can be used simultaneously for other tasks such as reporting, summations, and queries. Figure 6-2 shows log apply services applying redo data to a logical standby database.

Figure 6-2 Automatic Updating of a Logical Standby Database

Text description of sqlapply.gif follows.
Text description of the illustration sqlapply.gif
The logical standby database uses the following processes:
  • Remote file server (RFS)
    The remote file server process receives redo data from the primary database. The RFS process communicates with the logical standby process (LSP) to coordinate and record which files arrived.
  • Logical standby process (LSP)
    The logical standby process is the coordinator process for a set of processes that concurrently read, prepare, build, analyze, and apply completed SQL transactions from the archived redo logs. The LSP also maintains metadata in the database.
Table 6-2 summarizes the basic tasks for configuring log apply services.
Table 6-2 Task List: Configuring Log Apply Services for Logical Standby Databases
StepTaskSee ...
1
Start log apply services.
2
Ensure that redo logs are being applied.
3
Manage SQL apply operations.
In addition to providing detailed information about the tasks presented in Table 6-2, the following sections also describe how to delay the application of archived redo logs.

6.3.1 Starting and Stopping Log Apply Services

To start log apply services, start the logical standby database, and then use the following statement. (Starting a logical standby database is done in the same manner as starting a primary database.)
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;

To stop log apply services, use the following statement:
SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;

6.3.2 Ensuring That Redo Logs Are Being Applied

Redo logs are read and applied to a logical standby database when a log switch occurs, not as they arrive on the standby site. You can verify the status of archived redo log apply operations by querying the following views:
  •  V$LOGSTDBY
    Use this view to verify that the archived redo logs are being applied to the standby database. This view provides information about the processes that are reading redo data and applying archived redo logs to logical standby databases. For example, the following query shows typical output during the initialization phase:
    SQL> COLUMN STATUS FORMAT A50
    SQL> COLUMN TYPE FORMAT A12
    SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;
    TYPE           HIGH_SCN STATUS
    ------------ ---------- --------------------------------------------------
    COORDINATOR             ORA-16115: loading Log Miner dictionary data
    READER                  ORA-16127: stalled waiting for additional transact
                            ions to be applied
    BUILDER                 ORA-16117: processing
    PREPARER                ORA-16116: no work available
    
    SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;
    TYPE           HIGH_SCN STATUS
    ------------ ---------- --------------------------------------------------
    COORDINATOR             ORA-16126: loading table or sequence object number
    READER                  ORA-16116: no work available
    BUILDER                 ORA-16116: no work available
    PREPARER                ORA-16116: no work available
    
    
  •  DBA_LOGSTDBY_PROGRESS
    Use this view for information about the progress of the log apply services. This view shows the state of the LSP and information about the SQL transactions that were executed on the logical standby database. For example:
    SQL> SELECT APPLIED_SCN, NEWEST_SCN FROM DBA_LOGSTDBY_PROGRESS;
    
    APPLIED_SCN NEWEST_SCN
    ----------- ----------
         180702     180702
    
    
    When the numbers in the APPLIED_SCN and NEWEST_SCN columns are equal (as shown in the query example), it means that all of the available data in the redo log was applied. These values can be compared to the values in the FIRST_CHANGE# column in the DBA_LOGSTDBY_LOG view to see how much log information has to be applied and how much remains.
    See Also:
    Chapter 9 for information about managing a logical standby database and Chapter 14 for more information about views that are used in a Data Guard environment

6.4 Managing Archive Gaps

Data Guard offers automatic archive redo log gap detection and resolution to handle network connectivity problems that might temporarily disconnect one or more standby databases from the primary database. Once properly configured, Data Guard requires no manual intervention by the DBA to detect and resolve such gaps.
The following sections describe gap detection and resolution.

6.4.1 What Is an Archive Gap?

An archive gap is a range of archived redo logs created whenever the standby system is unable to receive the next archived redo log generated by the primary database. For example, an archive gap occurs when the network becomes unavailable and automatic archiving from the primary database to the standby database stops. When the network is available again, automatic transmission of the redo data from the primary database to the failed standby database resumes.
The missing archived redo logs are the gap. The gap is automatically detected and resolved.

6.4.2 When Is an Archive Gap Discovered?

An archive gap can occur whenever the primary database archives a log, but the log is not archived to the standby site. Every minute, the primary database polls its standby databases to see if there is a gap in the sequence of archived redo logs. The polling between the primary and standby databases is sometimes referred to as a heartbeat. The primary database polls the standby databases serially.

6.4.3 Determining If an Archive Gap Exists on a Physical Standby Database

The following sections describe how to query the appropriate views to determine which logs are missing on the standby database.
On a physical standby database
To determine if there is an archive gap on your physical standby database, query the V$ARCHIVE_GAP view as shown in the following example:
SQL> SELECT * FROM V$ARCHIVE_GAP;

    THREAD#  LOW_SEQUENCE#  HIGH_SEQUENCE#
-----------  -------------  --------------
          1              7              10

The output from the previous example indicates your physical standby database is currently missing logs from sequence 7 to sequence 10 for thread 1. After you identify the gap, issue the following SQL statement on the primary database to locate the archived redo logs on your primary database (assuming the local archive destination on the primary database is LOG_ARCHIVE_DEST_1):
SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE THREAD#=1 AND DEST_ID=1 AND

  2> SEQUENCE# BETWEEN 7 AND 10;


NAME
--------------------------------------------------------------------------------
/primary/thread1_dest/arcr_1_7.arc

/primary/thread1_dest/arcr_1_8.arc

/primary/thread1_dest/arcr_1_9.arc


Copy these logs to your physical standby database and register them using the ALTER DATABASE REGISTER LOGFILE statement on your physical standby database. For example:
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_7.arc';
SQL> ALTER DATABASE REGISTER LOGFILE
'/physical_standby1/thread1_dest/arcr_1_8.arc';
                                        :
                                        :
After you register these logs on the physical standby database, you can restart managed recovery operations.

Note:
The V$ARCHIVE_GAP fixed view on a physical standby database only returns the next gap that is currently blocking managed recovery from continuing. After resolving the identified gap and starting managed recovery, query the V$ARCHIVE_GAP fixed view again on the physical standby database to determine the next gap sequence, if there is one. Repeat this process until there are no more gaps.

On a logical standby database:
To determine if there is an archive gap, query the DBA_LOGSTDBY_LOG view on the logical standby database. For example, the following query indicates there is a gap in the sequence of archived redo logs because it displays two files for THREAD 1 on the logical standby database. (If there are no gaps, the query will show only one file for each thread.) The output shows that the highest registered file is sequence number 10, but there is a gap at the file shown as sequence number 6:
SQL> COLUMN FILE_NAME FORMAT a55
SQL> SELECT THREAD#, SEQUENCE#, FILE_NAME FROM DBA_LOGSTDBY_LOG L
  2> WHERE NEXT_CHANGE# NOT IN
  3> (SELECT FIRST_CHANGE# FROM DBA_LOGSTDBY_LOG WHERE L.THREAD# = THREAD#)
  4> ORDER BY THREAD#,SEQUENCE#;

   THREAD#  SEQUENCE# FILE_NAME
---------- ---------- -----------------------------------------------
         1          6 /disk1/oracle/dbs/log-1292880008_6.arc
         1         10 /disk1/oracle/dbs/log-1292880008_10.arc

Copy the missing logs to the logical standby system and register them using the ALTER DATABASE REGISTER LOGICAL LOGFILE statement on your logical standby database. For example:
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE /disk1/oracle/dbs/log-1292880008_10.arc;

After you register these logs on the logical standby database, you can restart log apply services.

Note:
The DBA_LOGSTDBY_LOG view on a logical standby database only returns the next gap that is currently blocking SQL apply operations from continuing. After resolving the identified gap and starting log apply services, query the DBA_LOGSTDBY_LOG view again on the logical standby database to determine the next gap sequence, if there is one. Repeat this process until there are no more gaps.

6.4.4 How Is a Gap Resolved?

For both physical and logical standby databases, Data Guard performs gap detection and resolution automatically. No extra configuration settings are required. However, for physical standby databases, you can set initialization parameters so that log apply services also automatically resolve archive gaps as they occur on a physical standby database.
The following sections describe how to set initialization parameters to facilitate gap recovery for a physical standby database, and how gap recovery is handled on a logical standby database.
On a physical standby database
You can set initialization parameters so that log apply services automatically identify and resolve archive gaps as they occur on a physical standby database.
Define the FAL_CLIENT and FAL_SERVER initialization parameters only for physical standby databases in the initialization parameter file:
ParameterFunctionSyntax
FAL_CLIENT
This parameter specifies the network service name that the FAL server should use to connect to the standby database.
Syntax
FAL_CLIENT=net_service_name
Example
FAL_CLIENT=standby1_db
FAL_SERVER
This parameter specifies the network service name that the standby database should use to connect to the FAL server.
Syntax
FAL_SERVER=net_service_name
Example
FAL_SERVER=my_primary_db, my_standby_db
The FAL server is a background Oracle process that services the incoming requests from the FAL client. In most cases, the FAL server is located on a primary database. However, it can be located on another standby database.
For log apply services to automatically identify and resolve archive gaps, you must:
  1. On the standby system, use Oracle Net Manager to configure the listener. Use the TCP/IP protocol and statically register the standby database service with the listener using the service name. This service name will serve as the FAL client.
  2. Use Oracle Net Manager to create a network service name that the standby database can use to connect to the FAL server. The network service name should resolve to a connect descriptor that uses the same protocol, host address, port, and service name that you specified when you configured the listener on the FAL server system, which is typically the primary system. If you are unsure what values to use for these parameters, use Oracle Net Manager to display the listener configuration on the FAL server system.
  3. In the initialization parameter file of the standby database, assign the network service name that you created in step 1 to the FAL_CLIENT initialization parameter, and assign the network service name that you created in step 2 to the FAL_SERVER initialization parameter.
  4. On the FAL server system, use Oracle Net Manager to create a network service name that the FAL server can use to connect to the standby database. The network service name should resolve to a connect descriptor that uses the same protocol, host address, port, and SID as the one in step 1.
Log apply services automatically detect, and the FAL server process running on the primary database attempts to resolve, any gaps that may exist when you enable managed recovery with the ALTER DATABASE RECOVER MANAGED STANDBY DATABASE statement.
See Also:
Section B.3 for a description of the manual steps and Oracle9i Net Services Administrator's Guide for information about Oracle Net
On a logical standby database
Gap recovery on a logical standby database is handled through the heartbeat mechanism. The important consideration here is that automatic gap recovery is contingent on the availability of the primary database. If the primary database is not available, as would be the case in a failover scenario, automatic gap recovery will not take place.

6.5 Monitoring Log Apply Services for Physical Standby Databases

To monitor the status of archived redo logs and obtain information on log apply services on a physical standby database, query the fixed views described in this section. You can also monitor the standby database using Data Guard Manager.
This section contains the following topics:

6.5.1 Accessing the V$MANAGED_STANDBY Fixed View

Query the physical standby database to monitor log apply and log transport services activity at the standby site.
SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS
  2> FROM V$MANAGED_STANDBY;

PROCESS STATUS       THREAD#    SEQUENCE#  BLOCK#     BLOCKS
------- ------------ ---------- ---------- ---------- ----------
RFS     ATTACHED     1          947        72         72
MRP0    APPLYING_LOG 1          946        10         72
The previous query output shows that an RFS process has completed the archiving of redo log file sequence number 947. The output also shows a managed recovery operation that is actively applying archived redo log sequence number 946. The recovery operation is currently recovering block number 10 of the 72-block archived redo log.

6.5.2 Accessing the V$ARCHIVE_DEST_STATUS Fixed View

To quickly determine the level of synchronization for the standby database, issue the following query on the physical standby 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
The previous query output shows that the standby database is two archived logs behind in applying the redo logs received from the primary database. This might indicate that a single recovery process is unable to keep up with the volume of archived redo logs being received. Using the PARALLEL option might be a solution.

6.5.3 Accessing the V$ARCHIVED_LOG Fixed View

The V$ARCHIVED_LOG fixed view on the physical standby database shows all the archived redo logs received from the primary database. This view is only useful after the standby site starts receiving logs, because before that time the view is populated by old archived log records generated from the primary control file. For example, you can execute the following SQL*Plus statement:
SQL> SELECT REGISTRAR, CREATOR, THREAD#, SEQUENCE#, FIRST_CHANGE#,
  2> NEXT_CHANGE# FROM V$ARCHIVED_LOG;

REGISTRAR CREATOR THREAD#    SEQUENCE#  FIRST_CHANGE# NEXT_CHANGE#
--------- ------- ---------- ---------- ------------- ------------
RFS       ARCH    1          945        74651         74739
RFS       ARCH    1          946        74739         74772
RFS       ARCH    1          947        74772         74774
The previous query output shows three archived redo logs received from the primary database.
See Also:

6.5.4 Accessing the V$LOG_HISTORY Fixed View

Query the V$LOG_HISTORY fixed view on the physical standby database to show all the archived redo logs that were applied:
SQL> SELECT THREAD#, SEQUENCE#, FIRST_CHANGE#, NEXT_CHANGE#
  2> FROM V$LOG_HISTORY;

THREAD#    SEQUENCE#  FIRST_CHANGE# NEXT_CHANGE#
---------- ---------- ------------- ------------
1          945        74651         74739
The previous query output shows that the most recently applied archived redo log was sequence number 945.

6.5.5 Accessing the V$DATAGUARD_STATUS Fixed View

The V$DATAGUARD_STATUS fixed view displays events that would typically be triggered by any message to the alert log or server process trace files.
The following example shows output from the V$DATAGUARD_STATUS view on a primary database:
SQL> SELECT MESSAGE FROM V$DATAGUARD_STATUS;

MESSAGE
--------------------------------------------------------------------------------

ARC0: Archival started
ARC1: Archival started
Archivelog destination LOG_ARCHIVE_DEST_2 validated for no-data-loss
recovery
Creating archive destination LOG_ARCHIVE_DEST_2: 'dest2'
ARCH: Transmitting activation ID 0
LGWR: Completed archiving log 3 thread 1 sequence 11
Creating archive destination LOG_ARCHIVE_DEST_2: 'dest2'
LGWR: Transmitting activation ID 6877c1fe
LGWR: Beginning to archive log 4 thread 1 sequence 12
ARC0: Evaluating archive   log 3 thread 1 sequence 11
ARC0: Archive destination LOG_ARCHIVE_DEST_2: Previously completed
ARC0: Beginning to archive log 3 thread 1 sequence 11
Creating archive destination LOG_ARCHIVE_DEST_1:
'/oracle/arch/arch_1_11.arc'

ARC0: Completed archiving  log 3 thread 1 sequence 11
ARC1: Transmitting activation ID 6877c1fe

15 rows selected.

The following example shows the contents of the V$DATAGUARD_STATUS view on a physical standby database:

SQL> SELECT MESSAGE FROM V$DATAGUARD_STATUS;

MESSAGE
--------------------------------------------------------------------------------

ARC0: Archival started
ARC1: Archival started
RFS: Successfully opened standby logfile 6: '/oracle/dbs/sorl2.log'

ARC1: Evaluating archive   log 6 thread 1 sequence 11
ARC1: Beginning to archive log 6 thread 1 sequence 11
Creating archive destination LOG_ARCHIVE_DEST_1:
'/oracle/arch/arch_1_11.arc'

ARC1: Completed archiving  log 6 thread 1 sequence 11
RFS: Successfully opened standby logfile 5: '/oracle/dbs/sorl1.log'

Attempt to start background Managed Standby Recovery process
Media Recovery Log /oracle/arch/arch_1_9.arc

10 rows selected.

6.6 Monitoring Log Apply Services for Logical Standby Databases

To monitor the status of archived redo logs and obtain information on log apply services on a logical standby database, query the fixed views described in this section. You can also monitor the standby database using Data Guard Manager.
This section contains the following topics:

6.6.1 Accessing the DBA_LOGSTDBY_EVENTS View

If log apply services should stop unexpectedly, the reason for the problem is shown in this view.

Note:
Errors that cause SQL apply operations to stop are always recorded in the events table (unless there is insufficient space in the system tablespace). These events are always put into the ALERT.LOG file as well, with the phrase 'LOGSTDBY event' included in the text. When querying the view, select the columns in order byEVENT_TIMECOMMIT_SCN, and CURRENT_SCN. This ordering ensures that a shutdown failure appears last in the view.

The view also contains other information, such as which DDL statements were applied and which were skipped. For example:
SQL> ALTER SESSION SET NLS_DATE_FORMAT  = 'DD-MON-YY HH24:MI:SS';
Session altered.

SQL> COLUMN STATUS FORMAT A60
SQL> SELECT EVENT_TIME, STATUS, EVENT FROM DBA_LOGSTDBY_EVENTS
  2  ORDER BY EVENT_TIME, COMMIT_SCN;

EVENT_TIME         STATUS
------------------------------------------------------------------------------
EVENT

-------------------------------------------------------------------------------
23-JUL-02 18:20:12 ORA-16111: log mining and apply setting up
23-JUL-02 18:20:12 ORA-16128: User initiated shut down successfully completed
23-JUL-02 18:20:12 ORA-16112: log mining and apply stopping
23-JUL-02 18:20:23 ORA-16111: log mining and apply setting up
23-JUL-02 18:55:12 ORA-16128: User initiated shut down successfully completed
23-JUL-02 18:57:09 ORA-16111: log mining and apply setting up
23-JUL-02 20:21:47 ORA-16204: DDL successfully applied
create table mytable (one number, two varchar(30))
23-JUL-02 20:22:55 ORA-16205: DDL skipped due to skip setting create database 
link mydblink

8 rows selected.

This query shows that log apply services were started and stopped a few times. It also shows what DDL was applied and skipped. If log apply services had stopped, the last record in the query would have shown the cause of the problem.

6.6.2 Accessing the DBA_LOGSTDBY_LOG View

The DBA_LOGSTDBY_LOG view provides dynamic information about what is happening to log apply services. This view is helpful when you are diagnosing performance problems with log apply services applying archived redo logs to the logical standby database, and it can be helpful for other problems.
For example:
SQL> SELECT FILE_NAME, SEQUENCE#, FIRST_CHANGE#, NEXT_CHANGE#,
  2> TIMESTAMP, DICT_BEGIN, DICT_END, THREAD# FROM DBA_LOGSTDBY_LOG
  3> ORDER BY SEQUENCE#;

FILE_NAME                 SEQ# FIRST_CHANGE# NEXT_CHANGE# TIMESTAM BEG END THR#
------------------------- ---- ------------- ------------ -------- --- --- ----
/oracle/dbs/hq_nyc_2.log  2           101579       101588 11:02:58 NO  NO  1
/oracle/dbs/hq_nyc_3.log  3           101588       142065 11:02:02 NO  NO  1
/oracle/dbs/hq_nyc_4.log  4           142065       142307 11:02:10 NO  NO  1
/oracle/dbs/hq_nyc_5.log  5           142307       142739 11:02:48 YES YES 1
/oracle/dbs/hq_nyc_6.log  6           142739       143973 12:02:10 NO  NO  1
/oracle/dbs/hq_nyc_7.log  7           143973       144042 01:02:11 NO  NO  1
/oracle/dbs/hq_nyc_8.log  8           144042       144051 01:02:01 NO  NO  1
/oracle/dbs/hq_nyc_9.log  9           144051       144054 01:02:16 NO  NO  1
/oracle/dbs/hq_nyc_10.log 10          144054       144057 01:02:21 NO  NO  1
/oracle/dbs/hq_nyc_11.log 11          144057       144060 01:02:26 NO  NO  1
/oracle/dbs/hq_nyc_12.log 12          144060       144089 01:02:30 NO  NO  1
/oracle/dbs/hq_nyc_13.log 13          144089       144147 01:02:41 NO  NO  1

The output from this query shows that a LogMiner dictionary build starts at log file sequence number 5. The most recent archive log file is sequence number 13 and it was received at the logical standby database at 01:02:41.

6.6.3 Accessing the DBA_LOGSTDBY_PROGRESS View

To quickly determine if all log file information was applied, issue the following query on the logical standby database:
SQL> SELECT APPLIED_SCN, NEWEST_SCN FROM D BA_LOGSTDBY_PROGRESS;

APPLIED_SCN NEWEST_SCN
----------- ----------
     211301     211357

If the APPLIED_SCN matches the NEWEST_SCN, then all available log information was applied. To determine how much progress was made through the available logs, join the DBA_LOGSTDBY_PROGRESS view with the DBA_LOGSTDBY_LOG view, as shown in the following example:
SQL> ALTER SESSION SET NLS_DATE_FORMAT  = 'DD-MON-YY HH24:MI:SS';
Session altered.

SQL> SELECT L.SEQUENCE#, L.FIRST_TIME,
  2    (CASE WHEN L.NEXT_CHANGE# < P.READ_SCN THEN 'YES'
  3          WHEN L.FIRST_CHANGE# < P.APPLIED_SCN THEN 'CURRENT'
  4          ELSE 'NO' END) APPLIED
  5  FROM DBA_LOGSTDBY_LOG L, DBA_LOGSTDBY_PROGRESS P
  6  ORDER BY SEQUENCE#;

 SEQUENCE# FIRST_TIME         APPLIED
---------- ------------------ -------
        24 23-JUL-02 18:19:05 YES
        25 23-JUL-02 18:19:48 YES
        26 23-JUL-02 18:19:51 YES
        27 23-JUL-02 18:19:54 YES
        28 23-JUL-02 18:19:59 YES
        29 23-JUL-02 18:20:03 YES
        30 23-JUL-02 18:20:13 YES
        31 23-JUL-02 18:20:18 YES
        32 23-JUL-02 18:20:21 YES
        33 23-JUL-02 18:32:11 YES
        34 23-JUL-02 18:32:19 CURRENT
        35 23-JUL-02 19:13:20 CURRENT
        36 23-JUL-02 19:13:43 CURRENT
        37 23-JUL-02 19:13:46 CURRENT
        38 23-JUL-02 19:13:50 CURRENT
        39 23-JUL-02 19:13:54 CURRENT
        40 23-JUL-02 19:14:01 CURRENT
        41 23-JUL-02 19:15:11 NO
        42 23-JUL-02 19:15:54 NO

19 rows selected.

In the previous query, the computed APPLIED column displays YESCURRENTNO. The logs with YES were completely applied and those files are no longer needed by the logical standby database. The logs withCURRENT contain information that is currently being worked on. Because logical standby applies transactions, and because transactions span logs, it is common for log apply services to be applying changes from multiple logs. For logs with NO, information from those files is not being applied. Although it is possible that the files might have been open and read.

6.6.4 Accessing the V$LOGSTDBY Fixed View

To inspect the process activity for SQL apply operations, query the V$LOGSTDBY fixed view on the logical standby database. For example:
SQL> COLUMN STATUS FORMAT A50
SQL> COLUMN TYPE FORMAT A12
SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;

TYPE           HIGH_SCN STATUS
------------ ---------- --------------------------------------------------
COORDINATOR             ORA-16117: processing
READER                  ORA-16127: stalled waiting for additional transact
                        ions to be applied

BUILDER          191896 ORA-16116: no work available
PREPARER         191902 ORA-16117: processing
ANALYZER         191820 ORA-16120: dependencies being computed for transac
                        tion at SCN 0x0000.0002ed4e

APPLIER          191209 ORA-16124: transaction 1 16 1598 is waiting on ano
                        ther transaction

APPLIER          191205 ORA-16116: no work available
APPLIER          191206 ORA-16124: transaction 1 5 1603 is waiting on anot
                        her transaction

APPLIER          191213 ORA-16117: processing
APPLIER          191212 ORA-16124: transaction 1 20 1601 is waiting on ano
                        ther transaction

APPLIER          191216 ORA-16124: transaction 1 4 1602 is waiting on anot
                        her transaction

11 rows selected.

The previous query displays one row for each process involved in reading and applying redo logs. The different processes perform different functions as described by the TYPE column. The HIGH_SCN column is a progress indicator. As long as it keeps changing, from query to query, you know progress is being made. The STATUS column gives a text description of activity.

6.6.5 Accessing the V$LOGSTDBY_STATS Fixed View

The V$LOGSTDBY_STATS fixed view provides a collection of state and statistical information for log apply services. Most options have default values, and this view displays what values are currently in use. It also provides statistical information that helps indicate progress. Issue the following query to view database state information:
SQL> COLUMN NAME FORMAT A35
SQL> COLUMN VALUE FORMAT A35
SQL> SELECT NAME, VALUE FROM V$LOGSTDBY_STATS
  2> WHERE NAME LIKE 'coordinator%' or NAME LIKE 'transactions%';

NAME                                VALUE
----------------------------------- -----------------------------------
coordinator state                   APPLYING
transactions ready                  7821
transactions applied                7802
coordinator uptime                  73

This query shows how long SQL apply operations have been running and how many transactions have been applied in that time. It also shows how many transactions are available to be applied, indicating that more work is necessary.

6.7 Setting Archive Tracing

To see the progression of the archiving of redo logs to the standby site, set the LOG_ARCHIVE_TRACE parameter in the primary and standby initialization parameter files. When you set the LOG_ARCHIVE_TRACE parameter, it causes the Oracle database server to write an audit trail to a trace file as follows:
  • On the primary database
    This causes the Oracle database server to write an audit trail of archiving process activity (ARCn and foreground processes) on the primary database in a trace file whose filename is specified in theUSER_DUMP_DEST initialization parameter.
  • On the standby database
    This causes the Oracle database server to write an audit trail of the RFS process and the ARCn process activity relating to archived redo logs on the standby database in a trace file whose filename is specified in the USER_DUMP_DEST initialization parameter.

6.7.1 Determining the Location of the Trace Files

The trace files for a database are located in the directory specified by the USER_DUMP_DEST parameter in the initialization parameter file. Connect to the primary and standby instances using SQL*Plus, and issue a SHOW statement to determine the location, for example:
SQL> SHOW PARAMETER user_dump_dest
NAME                                 TYPE    VALUE
------------------------------------ ------- ------------------------------
user_dump_dest                       string  ?/rdbms/log

6.7.2 Setting the Log Trace Parameter

The format for the archiving trace parameter is as follows, where trace_level is an integer:
LOG_ARCHIVE_TRACE=trace_level

To enable, disable, or modify the LOG_ARCHIVE_TRACE parameter in a primary database, do one of the following:
  • Shut down the primary database, modify the initialization parameter file, and restart the database.
  • Issue an ALTER SYSTEM SET LOG_ARCHIVE_TRACE=trace_level statement while the database is open or mounted.
To enable, disable, or modify the LOG_ARCHIVE_TRACE parameter for a physical standby database that is performing read-only or managed recovery operations, issue a SQL statement similar to the following:
SQL> ALTER SYSTEM SET LOG_ARCHIVE_TRACE=15;
In the previous example, setting the LOG_ARCHIVE_TRACE parameter to a value of 15 sets trace levels 1, 2, 4, and 8 as described in Section 6.7.3.
Issue the ALTER SYSTEM statement from a different standby session so that it affects trace output generated by the remote file service (RFS) and ARCn processes when the next archived log is received from the primary database. For example, enter:
SQL> ALTER SYSTEM SET LOG_ARCHIVE_TRACE=32;

6.7.3 Choosing an Integer Value

The integer values for the LOG_ARCHIVE_TRACE parameter represent levels of tracing data. In general, the higher the level, the more detailed the information. The following integer levels are available:
LevelMeaning
0
Disables archived redo log tracing (default setting)
1
Tracks archiving of redo log file
2
Tracks archival status per archived redo log destination
4
Tracks archival operational phase
8
Tracks archived redo log destination activity
16
Tracks detailed archived redo log destination activity
32
Tracks archived redo log destination parameter modifications
64
Tracks ARCn process state activity
128
Tracks FAL server process activity
256
Supported in a future release
512
Tracks asynchronous LGWR activity
1024
Tracks the RFS physical client
2048
Tracks the ARCn or RFS heartbeat
You can combine tracing levels by setting the value of the LOG_ARCHIVE_TRACE parameter to the sum of the individual levels. For example, setting the parameter to 6 generates level 2 and level 4 trace output.
The following are examples of the ARC0 trace data generated on the primary site by the archiving of redo log 387 to two different destinations: the service standby1 and the local directory /oracle/dbs.

Note:
The level numbers do not appear in the actual trace output; they are shown here for clarification only.

Level   Corresponding entry content (sample) 
-----   -------------------------------- 
( 1)    ARC0: Begin archiving log# 1 seq# 387 thrd# 1 
( 4)    ARC0: VALIDATE 
( 4)    ARC0: PREPARE 
( 4)    ARC0: INITIALIZE 
( 4)    ARC0: SPOOL 
( 8)    ARC0: Creating archive destination 2 : 'standby1' 
(16)    ARC0:  Issuing standby Create archive destination at 'standby1' 
( 8)    ARC0: Creating archive destination 1 : '/oracle/dbs/d1arc1_387.log' 
(16)    ARC0:  Archiving block 1 count 1 to : 'standby1' 
(16)    ARC0:  Issuing standby Archive of block 1 count 1 to 'standby1' 
(16)    ARC0:  Archiving block 1 count 1 to :  '/oracle/dbs/d1arc1_387.log' 
( 8)    ARC0: Closing archive destination 2  : standby1 
(16)    ARC0:  Issuing standby Close archive destination at 'standby1' 
( 8)    ARC0: Closing archive destination 1  :  /oracle/dbs/d1arc1_387.log 
( 4)    ARC0: FINISH 
( 2)    ARC0: Archival success destination 2 : 'standby1' 
( 2)    ARC0: Archival success destination 1 : '/oracle/dbs/d1arc1_387.log' 
( 4)    ARC0: COMPLETE, all destinations archived 
(16)    ARC0: ArchivedLog entry added: /oracle/dbs/d1arc1_387.log 
(16)    ARC0: ArchivedLog entry added: standby1 
( 4)    ARC0: ARCHIVED 
( 1)    ARC0: Completed archiving log# 1 seq# 387 thrd# 1 
 
(32)  Propagating archive 0 destination version 0 to version 2 
         Propagating archive 0 state version 0 to version 2 
         Propagating archive 1 destination version 0 to version 2 
         Propagating archive 1 state version 0 to version 2 
         Propagating archive 2 destination version 0 to version 1 
         Propagating archive 2 state version 0 to version 1 
         Propagating archive 3 destination version 0 to version 1 
         Propagating archive 3 state version 0 to version 1 
         Propagating archive 4 destination version 0 to version 1 
         Propagating archive 4 state version 0 to version 1 
 
(64) ARCH: changing ARC0 KCRRNOARCH->KCRRSCHED 
        ARCH: STARTING ARCH PROCESSES 
        ARCH: changing ARC0 KCRRSCHED->KCRRSTART 
        ARCH: invoking ARC0 
        ARC0: changing ARC0 KCRRSTART->KCRRACTIVE 
        ARCH: Initializing ARC0 
        ARCH: ARC0 invoked 
        ARCH: STARTING ARCH PROCESSES COMPLETE 
        ARC0 started with pid=8 
        ARC0: Archival started
The following is the trace data generated by the RFS process on the standby site as it receives archived log 387 in directory /stby and applies it to the standby database:

level    trace output (sample) 
----    ------------------ 
( 4)      RFS: Startup received from ARCH pid 9272 
( 4)      RFS: Notifier 
( 4)      RFS: Attaching to standby instance 
( 1)      RFS: Begin archive log# 2 seq# 387 thrd# 1 
(32)      Propagating archive 5 destination version 0 to version 2 
(32)      Propagating archive 5 state version 0 to version 1 
( 8)      RFS: Creating archive destination file: /stby/parc1_387.log 
(16)      RFS:  Archiving block 1 count 11 
( 1)      RFS: Completed archive log# 2 seq# 387 thrd# 1 
( 8)      RFS: Closing archive destination file: /stby/parc1_387.log 
(16)      RFS: ArchivedLog entry added: /stby/parc1_387.log 
( 1)      RFS: Archivelog seq# 387 thrd# 1 available 04/02/99 09:40:53 
( 4)      RFS: Detaching from standby instance 
( 4)      RFS: Shutdown received from ARCH pid 9272

RMAN常用命令

8.4 RMAN 命令知多少


  RMAN 作为一个专业的备份工具,它几乎考虑到了备份及恢复过程中可能遇到的各种操作,因此它也提供了各种各样的命令来为这些操作提供便利。

8.4.1 显示RMAN默认配置——SHOW命令

  在RMAN中有一系列的默认配置,这些配置决定了备份和恢复时的一些默认选项(此节内容枯燥,眼神不好的同学请自觉跳过),DBA可以通过 SHOW 命令来显示当前的配置参数。例如:
    RMAN>  SHOW ALL;
    RMAN configuration parameters are:
    CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
    CONFIGURE BACKUP OPTIMIZATION OFF; # default
    CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
    CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO  ' %F ' ; # default
    CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
    CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
    CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
    CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT   'F:\ORACLE\BACKUP\BAK_%U ' ;
    CONFIGURE MAXSETSIZE TO UNLIMITED; # default
    CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
    CONFIGURE ENCRYPTION ALGORITHM  ' AES128 ' ; # default
    CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
    CONFIGURE SNAPSHOT CONTROLFILE NAME TO  'F:\ORACLE\PRODUCT\10.2.0\DB_2\DATABASE\SNCFJSSBOOK.ORA' ; # default
    RMAN>
  这其中的每一项配置都对应了不同的功能,关于这些配置的具体功能和使用方式,后面的小节会有详细的介绍。
    提示:配置项后面加了# default的表示该项为初始配置,未被修改过。
  SHOW 命令的使用也相当灵活,其后加上不同类型的配置参数,就可以显示不同类型的配置,例如:
    RMAN>  SHOW CONTROLFILE AUTOBACKUP;
    RMAN configuration parameters are:
    CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default

8.4.2   列出备份信息——LIST命令

  LIST 命令用来查看通过RMAN生成的备份集、备份镜像、归档文件等,这个命令使用也比较简单,用LIST+相应关键字即可,例如:
  • 列出数据库中所有的备份信息:
    RMAN> LIST BACKUP;
  • 列出所有备份的控制文件信息:
    RMAN> LIST BACKUP OF CONTROLFILE;
  • 列出指定数据文件的备份信息:
    RMAN> LIST BACKUP OF DATAFILE  ' F:\ORACLE\ORADATA\JSSBOOK\SCOTT_TBS01.DBF ' ;
  或
    RMAN> LIST BACKUP OF DATAFILE 5;
  注:DATAFILE序号可以通过动态性能视图 V$DATAFILE 或数据字典 DBA_DATA_FILES 中查询。
  • 列出所有备份的归档文件信息:
    RMAN> LIST BACKUP OF ARCHIVELOG ALL;
  • 列出指定表空间的备份信息:
    RMAN> LIST COPY OF TABLESPACE  ' SYSTEM ' ;
  • 列出某个设备上的所有信息:
    RMAN> LIST DEVICE TYPE DISK BACKUP;
  • 列出数据库当前所有归档:
    RMAN> LIST ARCHIVELOG ALL;
  • 列出所有无效备份:
    RMAN> LIST EXPIRED BACKUP;

8.4.3   删除备份——DELETE命令

  用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RMAN资料库(RMAN Repository)中生成RMAN备份记录,默认情况下RMAN备份记录会被存放在目标数据库的控制文件中,如果配置了恢复目录(Recovery  C atalog ),那么该备份记录也会被存放到恢复目录中。
  RMAN 中的DELETE命令就是用来删除记录(某些情况下并非删除记录,而是打上删除标记),以及这些记录关联的物理备份片段。
  • 删除过期备份。当使用RMAN命令执行备份操作时,RMAN会根据备份冗余策略确定备份是否过期。
    RMAN>  DELETE OBSOLETE;
  • 删除无效备份。首先执行 CROSSCHECK 命令核对备份集,如果发现备份无效(比如备份对应的数据文件损坏或丢失),RMAN会将该备份集标记为EXPIRED状态。要删除相应的备份记录,可以执行 DELETE EXPIRED BACKUP 命令:
    RMAN>  DELETE EXPIRED BACKUP;
  • 删除EXPIRED副本,如下所示:
    RMAN>  DELETE EXPIRED COPY;
  • 删除特定备份集,如下所示:
    RMAN>  DELETE BACKUPSET 19;
  • 删除特定备份片,如下所示:
    RMAN>  DELETE BACKUPPIECE  ' d:\backup\DEMO_19.bak ' ;
  • 删除所有备份集,如下所示:
    RMAN>  DELETE BACKUP;
  • 删除特定映像副本,如下所示:
    RMAN>  DELETE DATAFILE COPY  ' d:\backup\DEMO_19.bak ' ;
  • 删除所有映像副本,如下所示:
    RMAN>  DELETE COPY;
  • 在备份后删除输入对象,如下所示:
    RMAN>  BACKUP ARCHIVELOG ALL DELETE INPUT;
    RMAN>  DELETE BACKUPSET 22 FORMAT  =  'd:\backup\%u.bak'  DELETE INPUT;   
提示:什么是RMAN资料库(RMAN Repository)?
这是一个逻辑概念,指RMAN备份恢复需要用到的数据信息,如备份集路径、归档文件路径等。如果使用了恢复目录,则这部分数据保存于恢复目录中,否则只会保存在目标数据库的控制文件中。
=================================================


8.4.4 报表显示——REPORT命令

  REPORT 命令主要是用于当前备份信息的分析,如哪些备份已经过期,哪些文件该备份,哪些备份不可用,哪些备份可以删除之类的。
  REPORT 命令特别提供了一个SCHEMA关键字,可以用来查看数据库的模式信息(注意此模式非用户的模式哟),比如某个时间段的数据库结构,不过,使用这些功能的前提就是必须首先拥有足够的备份,不然使用REPORT命令得出的结果恐怕也满足不了你的需求啊。
  • 查看7天前数据库的模式:
    RMAN> REPORT SCHEMA AT TIME  ' SYSDATE-7 ' ;
  注意,查看模式信息必须连接到catalog数据库。
  • 查看所有需要备份的文件:
    RMAN> REPORT NEED BACKUP; 
  • 查看指定表空间是否需要备份:
    RMAN> REPORT NEED BACKUP TABLESPACE SYSTEM;
  • 查看过期备份:
    RMAN> REPORT OBSOLETE;

8.4.5 执行检查——CROSSCHECK命令

  CROSSCHECK 命令用来检查备份或归档物理文件的状态,如果物理文件存在,并且控制文件(或恢复目录)中有匹配记录,则标记该对象的状态为 AVAILABLE (有效),如果文件已经不存在了,则标记该对象状态为 EXPIRED (无效)。
  CROSSCHECK 命令并不会主动删除文件(也确实没有这个功能),它只是修改控制文件中对应记录的状态标志,因此如果想删除那些 EXPIRED 的记录,还是得手动通过 DELETE EXPIRED 命令进行。
  检查所有归档文件:
    RMAN> CROSSCHECK ARCHIVELOG ALL;
    提示:
    当操作系统环境变量NLS_LANG指定为中文SIMPLIFIED CHINESE_CHINA时,执行CROSSCHECK命令检查归档,如果结果显示“对归档日志的验证失败”,但你又确定该文件存在,别着急,这其实是Oracle 10g版本中的一个bug,验证归档文件显示的结果是反着的,如果显示验证失败说明验证是成功的,反倒是提示验证成功的话你就要小心了,说明验证失败了。 这不是CROSSCHECK命令自身的问题,而是Oracle中英文翻译的问题,设置NLS_LANG为AMERICAN_AMERICA,在英文环境下检查显示一切正常。
  检查所有备份集:
    RMAN> CROSSCHECK BACKUP;

8.4.6 修改状态——CHANGE命令

  CHANGE 命令可以用来修改备份文件或归档文件的状态,不是指物理文件,而是这些文件在控制文件(或恢复目录)中对应记录的状态,状态有两种: AVAILABLE (可用)和 UNAVAILABLE (不可用)。
  例如,修改指定备份集状态为 UNAVAILABLE :
    RMAN> CHANGE BACKUPSET  n  UNAVAILABLE;
  注意,n 为备份集序号,指定的备份集必须确实存在,不然执行会报错。
  修改指定表空间的备份集为 UNAVAILABLE :
    RMAN> CHANGE BACKUP OF TABLESPACE USERS UNAVAILABLE;
  修改指定归档文件状态为 UNAVAILABLE :
    RMAN>  CHANGE ARCHIVELOG LOGSEQ =n  UNAVAILABLE;
  提示,这里的n为归档文件序号,可以通过 LIST ARCHIVELOG ALL 或查询 V$ARCHIVED_LOG 获取。当然你也可以指定归档文件详细路径。
  如果将指定对象状态修改为可用,执行上述命令时将关键字 UNAVAILABLE 改为 AVAILABLE 即可,这里不做演示了。
  另外,与CROSSCHECK命令不同,CHANGE命令附带了 DELETE 子句,配合使用能够在修改记录状态的同时直接删除物理文件,功能那是相当彪悍,例如,删除某个归档文件:
    RMAN>  CHANGE ARCHIVELOG LOGSEQ =n  DELETE ;
  又见到n,这个n是指啥俺先不说,让你猜,猜对了俺就告诉你。

8.4.7 综述

  前面介绍了很多命令(即使介绍的几个也没有完全展开,只介绍了该命令的一些常用功能),其实RMAN中的命令远不止这几个(最最重要的BACKUP命令和RESTORE命令都没介绍哪,没错,俺是成心的),可调用参数也远不止这些。你是不是已经觉着命令太多,而且每个命令又有太多调用参数,完全记不住?老实说,俺也记不全,不过俺有超级必杀技,命令再多也不怕。悄悄告诉你,俺的秘技就是完全不用记,别倒别倒,俺不准备教你学太极,俺刚才的话还没说完。俺的意思是说,记不住不要紧,只要注意看RMAN的提示信息就好了。
  比如想查看已经备份的归档,只记得要用LIST命令查看,后面应该加什么参数全忘了,没关系,那就先执行LIST命令好了:
    RMAN> LIST;
    RMAN-01009: syntax error: found ";": expecting one of: " all, archivelog, backup, backuppiece, backupset, backed, completed, copy, controlfilecopy, datafilecopy, device, expired, global, incarnation, like, proxy, recoverable, script, tag "
  你看,返回了一堆的信息,提示你语法错误,只能支持上述加粗显示的那些关键字。
  根据提示信息,隐约记得应该是BACKUP关键字,那就敲上BACKUP试试看:
    RMAN> LIST BACKUP OF;
    RMAN-01009: syntax error: found ";": expecting one of: " archivelog, controlfile, database, datafile, spfile, tablespace "
  哈哈,又报错了啊, en ,提示越来越清楚了,加参数 ARCHIVELOG 再试试:
    RMAN> LIST BACKUP OF ARCHIVELOG ;
    RMAN-01009: syntax error: found ";": expecting one of: " all, from, high, like, logseq, low, scn, sequence, time, until "
  OK ,基本明了,我们的目的是要查看所有备份的归档,最后再加参数ALL就好了:
    RMAN> LIST BACKUP OF ARCHIVELOG ALL;
    ...
  结果显示出来了吧,目标实现,竣工!
  如果你连RMAN中有哪些命令都忘记了,没关系,随便输入个字母再按回车键试试:
    RMAN-01009: syntax error: found "identifier": expecting one of: "allocate, alter, backup, beginline, blockrecover, catalog, change, connect, copy, convert, create, crosscheck, configure, duplicate, debug, delete, drop, exit, endinline, flashback, host, {, library, list, mount, open, print, quit, recover, register, release, replace, report, renormalize, reset, restore, resync, rman, run, rpctest, set, setlimit, sql, switch, spool, startup, shutdown, send, show, test, transport, upgrade, unregister, validate"
  虽然又报出了RMAN-01009错误,但是你看,RMAN中支持的命令是不是也都列出来了呢?这个示例告诉我们,出错也不全是坏事哟。嘿嘿,自己躲墙角偷偷乐去吧,旁人俺都不告诉他的。
  不过如果次次输入都报错就显得太不专业了,因此偷偷用就好,如果你的工作时刻被领导关注着,那俺还是建议你务必要牢记一些常用命令。

Saturday, September 5, 2015

Troubleshooting DataGuard Environment

Helping in the OTN  forums – Data Guard (OTN) , They used to post without proper information which is related to Data Guard. I often face help requests without  any usefull information, regarding to a problem. And this situation happens again and again.”
So, I’d like to offer two scripts, supposed to be run at primary and standby nodes, to help OPs gather necessary information
Questions specific to DataGuard includes “Physical standby”, “Logical Standby” , “DG Broker”, “DataGuard with RAC”.
These scripts help in the case of a Physical Standby configuration and basic information which is applicable for other environment too (Logical)
Generated log files will help us to detect and troubleshoot any errors and misconfigurations as soon as possible
Run Below scripts from SYS user from Both Primary & Standby databases.
Primary Script:-
spool dg_Primary_output.log
set feedback off
set trimspool on
set line 500
set pagesize 50
column name for a30
column display_value for a30
column ID format 99
column "SRLs" format 99
column active format 99
col type format a4
column ID format 99
column "SRLs" format 99
column active format 99
col type format a4
col PROTECTION_MODE for a20
col RECOVERY_MODE for a20
col db_mode for a15
SELECT name, display_value FROM v$parameter WHERE name IN ('db_name','db_unique_name','log_archive_config','log_archive_dest_2','log_archive_dest_state_2','fal_client','fal_server','standby_file_management','standby_archive_dest','db_file_name_convert','log_file_name_convert','remote_login_passwordfile','local_listener','dg_broker_start','dg_broker_config_file1','dg_broker_config_file2','log_archive_max_processes') order by name;
col name for a10
col DATABASE_ROLE for a10
SELECT name,db_unique_name,protection_mode,DATABASE_ROLE,OPEN_MODE,switchover_status from v$database;
select thread#,max(sequence#) from v$archived_log group by thread#;
col severity for a15
col message for a70
col timestamp for a20
select severity,error_code,to_char(timestamp,'DD-MON-YYYY HH24:MI:SS') "timestamp" , message from v$dataguard_status where dest_id=2;
select ds.dest_id id
, ad.status
, ds.database_mode db_mode
, ad.archiver type
, ds.recovery_mode
, ds.protection_mode
, ds.standby_logfile_count "SRLs"
, ds.standby_logfile_active active
, ds.archived_seq#
from v$archive_dest_status ds
, v$archive_dest ad
where ds.dest_id = ad.dest_id
and ad.status != 'INACTIVE'
order by
ds.dest_id;
column FILE_TYPE format a20
col name format a60
select    name
,    floor(space_limit / 1024 / 1024) "Size MB"
,    ceil(space_used  / 1024 / 1024) "Used MB"
from    v$recovery_file_dest
order by name;
spool off
This script will generate dg_Primary_output.log file where user is connected to SQLPlus from shell.
Standby Script:-
spool dg_standby_output.log
set feedback off
set trimspool on
set line 500
set pagesize 50
set linesize 200
column name for a30
column display_value for a30
col value for a10
col PROTECTION_MODE for a15
col DATABASE_Role for a15
SELECT name, display_value FROM v$parameter WHERE name IN ('db_name','db_unique_name','log_archive_config','log_archive_dest_2','log_archive_dest_state_2','fal_client','fal_server','standby_file_management','standby_archive_dest','db_file_name_convert','log_file_name_convert','remote_login_passwordfile','local_listener','dg_broker_start','dg_broker_config_file1','dg_broker_config_file2','log_archive_max_processes') order by name;
col name for a10
col DATABASE_ROLE for a10
SELECT name,db_unique_name,protection_mode,DATABASE_ROLE,OPEN_MODE from v$database;
select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;
select process, status,thread#,sequence# from v$managed_standby;
SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"
FROM
(SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,
(SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL
WHERE ARCH.THREAD# = APPL.THREAD# ORDER BY 1;
col name for a30 
select * from v$dataguard_stats; 
select * from v$archive_gap; 
col name format a60 
select name,floor(space_limit / 1024 / 1024) "Size MB" ,ceil(space_used  / 1024 / 1024) "Used MB" from    v$recovery_file_dest order by name; 
spool off

This script will generate dg_standby_output.log file where user is connected to SQLPlus from shell. Further there would be changes in this script according to requirement. :) Any comments always welcome.

Oracle RAC Cache Fusion

Oracle Tips by Rohit GuptaAugust 12, 2011
Tips from the Trenches by Rohit Gupta
This paper is by no means an exhaustive discussion on RAC or its architecture. The focus here is only on the concept called CACHE FUSION which is core to the functioning of a RAC setup. The intention is that after reading the paper, readers should be well acquainted with CACHE FUSION and how it works to resolve the scenarios which could be contentious in a normal multi-node multi-user setup.  
Introduction  
Some logical questions in case of a RAC database would be around the shared and common components. For example, do the nodes share storage? Do the nodes share memory? How do the nodes communicate? Since this is not a RAC study guide, answering all such questions is out of scope for this article. But one question we are definitely trying to address here is the shared memory part. Though each instance has a local buffer cache, CACHE FUSION causes sharing of cache and hence resolves the problems like concurrency etc. Needless to say, the sharing is completely transparent to the end users.  
First things first - What is Cache Fusion?  
Whoever knows the basics of RAC should very well be aware of the fact that CACHE FUSION is one of the most important and interesting concepts in a RAC setup. As the name suggests, CACHE FUSION is the amalgamation of cache from each node/instance participating in the RAC, but it is not any physically secured memory component which can be configured unlike the usual buffer cache (or other SGA components) which is local to each node/instance.  
We know that every instance of the RAC database has its own local buffer cache which performs the usual cache functionality for that instance. Now there could be occasions when a transaction/user on instance A needs to access a data block which is being owned/locked by the other instance B. In such cases, the instance A will request instance B for that data block and hence accesses the block through the interconnect mechanism. This concept is known as CACHE FUSION where one instance can work on or access a data block in other instance?s cache via the high speed interconnect.  
Cache Fusion architecture helps resolve each possible type of contentions that could be thought of in a multi-node RAC setup. We will look at them in detail in coming sections but first let us understand few very important terms/concepts which will be useful in understanding the contentions which we are going to discuss in later sections.
 Global Cache Service  
Global Cache Service (GCS) is the heart of Cache Fusion concept. It is through GCS that data integrity in RAC is maintained when more than one instance need a particular data block. Instances look up to the GCS for fulfilling their data block needs.
 GCS is responsible for:
  1. Tracking the data block
  2.  Accepting the data block requests from instances
  3. Informing the holding instance to release the lock on the data block or ship a CR image
  4. Coordinating the shipping of data blocks as needed between the instance through the interconnect
  5. Informing the instances to keep or discard PIs  
More about the above functions will be clear from the following discussion on contention. Please note that GCS is available in the form of the background process called LMS.
Past Image  
The concept of Past Image is very specific to RAC setup. Consider an instance holding exclusive lock on a data block for updates. If some other instance in the RAC needs the block, the holding instance can send the block to the requesting instance (instead of writing it to disk) by keeping a PI (Past Image) of the block in its buffer cache. Basically, PI is the copy of the data block before the block is written to the disk.
  •  There can be more than one PI of the block at a time across the instances. In case there is some instance crash/failure in the RAC and a recovery is required, Oracle is able to re-construct the block using these Past Images from all the instances.
  •  When a block is written to the disk, all Past Images of that block across the instances are discarded. GCS informs all the instances to do this. At this time, the redo logs containing the redo for that data block can also be overwritten because they are no longer needed for recovery.
Consistent Read
A consistent read is needed when a particular block is being accessed/modified by transaction T1 and at the same time another transaction T2 tries to access/read the block. If T1 has not been committed, T2 needs a consistent read (consistent to the non-modified state of the database) copy of the block to move ahead. A CR copy is created using the UNDO data for that block.   A sample series of steps for a CR in a normal setup would be:
  1. Process tries to read a data block
  2. Finds an active transaction in the block
  3. Then checks the UNDO segment to see if the transaction has been committed or not
  4. If the transaction has been committed, it creates the REDO records and reads the block
  5. If the transaction has not been committed, it creates a CR block for itself using the UNDO/ROLLBACK information.
  6. Creating a CR image in RAC is a bit different and can come with some I/O overheads. This is because the UNDO could be spread across instances and hence to build a CR copy of the block, the instance might has to visit UNDO segments on other instances and hence perform certain extra I/O
Possible contentions in a RAC setup and How CACHE FUSION helps resolve them  
As mentioned above, CACHE FUSION helps resolve all the possible contentions that could happen between instances in a RAC setup.   There are 3 possible contentions in a RAC setup which we are going to discuss in detail here with a mention of cache fusion where ever applicable.
Our discussion thus far should help understand the following discussion on contentions and their resolutions better.
  1.  Read/Read contention:  Read-Read contention might not be a problem at all because the table/row will be in a shared lock mode for both transactions and none of them is trying an exclusive lock anyways.
  2.  Read/Write contention:   This one is interesting. 

    Here is more about this contention and how the concept of cache fusion helps resolve this contention
  3. A data block is in the buffer cache of instance A and is being updated. An exclusive lock has been acquired on it.
  4. After some time instance B is interested in reading that same data block and hence sends a request to GCS. So far so good ? Read/Write contention has been induced
  5. GCS checks the availability of that data block and finds that instance A has acquired an exclusive lock. Hence, GCS asks instance A to release the block for instance B.
  6. Now there are two options ? either instance A releases the lock on that block (if it no longer needs it) and lets instance B read the block from the disk OR instance A creates a CR image of the block in its own buffer cache and ships it to the requesting instance via interconnect
  7. The holding instance notifies the GCS accordingly (if the lock has been released or the CR image has been shipped)
  8. Creation of CR image, shipping it to the requesting instance and involvement of GCS is where CACHE FUSION comes into play
  1. Write/Write contention:  
This is the case where both instance A as well as B are trying to acquire an exclusive lock on the data block. A data block is in the buffer cache of instance A and is being updated. An exclusive lock has been acquired on it
  1. Instance B send the data block request to the GCS
  2. GCS checks the availability of that data block and finds that instance A has acquired an exclusive lock. Hence, GCS asks instance A to release the block for instance B
  3. There are 2 options - either instance A releases the lock on that block (if it no longer needs it) and lets instance B read the block from the disk OR instance A creates a PI image of the block in its own buffer cache, makes the redo entries and ships the block to the requesting instance via interconnect
  4. Holding instance also notifies the GCS that lock has been released and a PI has been preserved
  5. Instance B now acquires the exclusive lock on that block and continues with its normal processing. At this point GCS records that data block is now with instance B
  6. The whole mechanism of resolving this contention with the due involvement of GCS is attributed to the CACHE FUSION.
PI image VS CR image  
Let us just halt and understand some basic stuff - Wondering why CR image used in Read-Write contention and PI image used in Write-Write contention? What is the difference?  
  1.  CR image was shipped to avoid Read-Write type of contention because the requesting instance doesn?t wants to perform a write operation and hence won?t need an exclusive lock on the block. Thus for a read operation, the CR image of the block would suffice. Whereas for Write-Write contention, the requesting instance also needs to acquire an exclusive lock on the data block. So to acquire the lock for write operations, it would need the actual block and not the CR image. The holding instance hence sends the actual block but is liable to keep the PI of the block until the block has been written to the disk. So if there is any instance failure or crash, Oracle is able to build the block using the PI from across the RAC instances (there could be more than on PI of a data block before the block has actually been written to the disk). Once the block is written to the disk, it won?t need a recovery in case of a crash and hence associated PIs can be discarded.
  2.  Another difference of course is that the CR image is to be shipped to the requesting instance where as the PI has to be kept by the holding instance after shipping the actual block.  
What about UNDO?  
This discussion is not about UNDO management in RAC but here is a brief about UNDO in a RAC scenario. UNDO is generated separately on each instance just similar to a standalone database.  Each instance has its own UNDO tablespace. The UNDO data of all instances is used by holding instance to build CR image in case of contention
*******************************************************************************************
If data were never changed, life would be easier. Each node in the cluster would just read the data block from disk. Sadly, things become more difficult when we have to deal with transactions that modify data in the database. Since this in an Oracle database, we live in a world where writers never block readers, which is a very good thing. A transaction modifying a row in a table is not allowed to block another session that needs to read that row. Yet the session reading the row is not allowed to see the other transaction?s changes until those changes are committed.
In a single instance database, Oracle generates a consistent read, an image of the data block before the transaction started. Oracle uses the information in the Undo tablespace to generate the consistent read image. When Oracle 8i introduced Cache Fusion, the only block transfers across the cluster interconnect were to transfer consistent read images from the node that changed the block to the node that needed to read the block. Oracle 8i?s Cache Fusion alleviated read/write contention issues for Oracle RAC. However, write/write contention still required disk pinging. Oracle 9i?s Cache Fusion improved write/write block contention. If one node modified a block and another instance needed to modify the same block, instead of writing the dirty buffer to disk, the dirty block is transferred to the requesting node through the cluster interconnect.

In order to facilitate Cache Fusion, we still need the Buffer Cache, the Shared Pool and the Undo tablespace just like a single-instance database. However, for Oracle RAC, we need the Buffer Caches on all instances to appear to be global across the cluster.

Hence, extra coordination is needed in the cluster to make a collection of instances work together. For starters, we need a Global Resource Directory (GRD) to be able to keep track of the resources in the cluster.  There is no true concept of a master node in Oracle RAC. Instead, each instance in the cluster becomes the resource masterfor a subset of resources. The Global Cache Services (GCS) are responsible for facilitating the transfer of blocks from one instance to another. A single-instance database relies on enqueues (locks) to protect two processes from simultaneously modifying the same row. Similarly, we need enqueues in Oracle RAC but since the Buffer Cache is now global, the enqueues on the resources must be global as well.

It should be no surprise that the Global Enqueue Services (GES) is responsible for managing locks across the cluster. As a side note, GES was previously called the Distributed Lock Manager (DLM). When Oracle introduced their first cluster on DEC VAX systems, the clustered database used VAX?s cluster lock manager but it was not designed for the demands of a transactional database and did not scale well. Oracle designed the DLM to have a scalable global lock manager. The DLM still persists in many publications.

The processes running to support an Oracle RAC instance include:

?         LMS:  This process is GCS. This process used to be called the Lock Manager Server.

?         LMON:  The Lock Monitor. This process is the GES master process.
?         LMD:  The Lock Manager Daemon. This process manages incoming lock requests. 
?         LCK0: The instance enqueue process. This process manages lock requests for library cache objects.