jeudi 3 novembre 2011

Oracle11g: How to create a Recovery Catalog for RMAN



Prerequisites

1) Database must be in archivelog
To perform backup through rman, the database must be in archivelog mode:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount;
ORACLE instance started.

Total System Global Area 1238732800 bytes
Fixed Size                  1336204 bytes
Variable Size             788532340 bytes
Database Buffers          436207616 bytes
Redo Buffers               12656640 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.
SQL> alter database open;

Database altered.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     193
Next log sequence to archive   195
Current log sequence           195

As we can see, the archive destination references the USE_DB_RECOVERY_FILE_DEST value. To identify the real location where the archivelog will be written we can display the value of the DB_RECOVERY_FILE_DEST init parameter:
SQL> show parameter DB_RECOVERY_FILE_DEST;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /database/TEST/flash_recovery_
                                                 area
db_recovery_file_dest_size           big integer 3852M


2) Configure severals destinations of archive log files

It is recommanded to configure more than one archive log file destination because if only one is configured, the database may frozen if the unique destination is full.

Local and remote destination are configured through the LOG_ARCHIVE_DEST_n paraemeters where n is in range [1..31].
For each LOG_ARCHIVE_DEST_n parameter there is a LOG_ARCHIVE_DEST_STATE_n parameter which indicates if the destination is enabled or not. By default the destination is enabled.

The LOG_ARCHIVE_DEST_n parameter may contain :
a) a local destination : LOG_ARCHIVE_DEST_n='LOCATION=/disk1/arch'
b) a remote destination through a net service name : LOG_ARCHIVE_DEST_n='SERVICE=remote_service'
The service name must be defined in the tnsnames.ora configuration file.

A destination may be declared MANDATORY or OPTIONAL. If a destination marked as MANDATORY fails, then the archiving process fails and the database frozen whatever the value defined in the LOG_ARCHIVE_MIN_SUCCEED_DEST. We can conclude that a the LOG_ARCHIVE_MIN_SUCCEED_DEST is ignored when a MANDATORY destination fails.

remark: Under the Oracle Database Standard Edition, only two archive log destinations are available : LOG_ARCHIVE_DEST & LOG_ARCHIVE_DUPLEX_DEST. Under Enterprise Edition, Oracle recommands LOG_ARCHIVE_DEST_n.

remark: The view V$ARCHIVE_DEST contains all information about archivelog destinations.

3) Ensuring success for archiving log files

When having severals archivelog destinations, it is usefull to define the minimum number of destination that must succeed in order to consider that the archiving process is successful. This is done through the LOG_ARCHIVE_MIN_SUCCEED_DEST parameter.
By default this parameter is setted to 1.

4) Defining a conservation strategies for backups

It is necessary to define a period of time during which it is possible to repair the database from backups. This strategy could be based on
a) a recovery window of n days
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF <days> DAYS;
b) or a number of backups to keep available.
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY <copies>;

remark: If you don't use a rman catalog, then the retention policy (recovery window or redundancy) must be less than the value of the CONTROL_FILE_RECORD_KEEP_TIME. The default value for CONTROL_FILE_RECORD_KEEP_TIME is 7 days.

remark: If you use a rman catalog, then ensure that the value of the CONTROL_FILE_RECORD_KEEP_TIME parameter is more then the time between 2 catalog resynchronizations. Resynchronizations are performed when you create a new backup or when you use the RESYNC CATALOG command.

remark: If you desactivate the retention policy then backups are keeped by rman as long as defined by the CONTROL_FILE_RECORD_KEEP_TIME parameter. To desactivate the retention policy :
RMAN> CONFIGURE RETENTION POLICY TO NONE;


5) Configure deletion policy for archivelog files

It is possible to configure a deletion policy for archivelog file as well as backupset or image copies.
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO {CLEAR | TO {APPLIED ON [ALL] STANDBY |
  BACKED UP integer TIMES TO DEVICE TYPE deviceSpecifier |
  NONE | SHIPPED TO [ALL] STANDBY}
  [ {APPLIED ON [ALL] STANDBY | BACKED UP integer TIMES TO DEVICE TYPE deviceSpecifier |
  NONE | SHIPPED TO [ALL] STANDBY}]...}
The extended syntax allows for configurations where logs are eligible for deletion only after being applied to, or transferred to, one or more standby database destinations.

Creating a recovery catalog for RMAN

The RMAN data are always stored in the control file but they can be duplicated to a distinct database called Recovery Catalog in order to enhance historization of backups (remember that the control file record backups for a fixed period defined through CONTROL_FILE_RECORD_KEEP_TIME parameter).

1) Create a database using dbca (for example)

2) Create a tablespace used by the catalog owner
    a) Create the directory on filesystem where will be located the tablespace (Not necessary if the database is manged through OMF)
$> mkdir /database/TEST/rcat
    b) Create the tablespace used by the catalog
SQL> CREATE TABLESPACE rcat_ts datafile '/database/TEST/rcat/rcat01.dbf' size 15M;
Tablespace created.
Each database registered inside an RMAN catalog require generally 15MB of free space.

3) Create the database owner of the RMAN catalog
SQL> CREATE USER rcatowner IDENTIFIED BY rcatowner
    TEMPORARY TABLESPACE TEMP
    DEFAULT TABLESPACE rcat_ts
    QUOTA UNLIMITED ON rcat_ts;

User created.
Grant the RECOVERY_CATALOG_OWNER role to the rcatowner user;
SQL> GRANT RECOVERY_CATALOG_OWNER to rcatowner;

Grant succeeded.
The RECOVERY_CALATOG_OWNER grants the following system priviledges:
SQL> select * from dba_sys_privs where grantee='RECOVERY_CATALOG_OWNER';

GRANTEE                        PRIVILEGE                                ADM
------------------------------ ---------------------------------------- ---
RECOVERY_CATALOG_OWNER         CREATE SYNONYM                           NO
RECOVERY_CATALOG_OWNER         CREATE CLUSTER                           NO
RECOVERY_CATALOG_OWNER         ALTER SESSION                            NO
RECOVERY_CATALOG_OWNER         CREATE DATABASE LINK                     NO
RECOVERY_CATALOG_OWNER         CREATE PROCEDURE                         NO
RECOVERY_CATALOG_OWNER         CREATE SEQUENCE                          NO
RECOVERY_CATALOG_OWNER         CREATE TABLE                             NO
RECOVERY_CATALOG_OWNER         CREATE SESSION                           NO
RECOVERY_CATALOG_OWNER         CREATE TYPE                              NO
RECOVERY_CATALOG_OWNER         CREATE VIEW                              NO
RECOVERY_CATALOG_OWNER         CREATE TRIGGER                           NO

11 rows selected.

4) Connect to the instance and create the RMAN catalog
$> rman
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Nov 8 11:14:57 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

RMAN> connect CATALOG rcatowner/rcatowner

connected to recovery catalog database

RMAN> CREATE CATALOG;

recovery catalog created
5) Register a database inside the RMAN catalog
Connect both to the database instance and the rman catalog.
$> export ORACLE_SID=TEST
$> rman TARGET / CATALOG rcatowner/rcatowner
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Nov 8 11:31:42 2011

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: TEST (DBID=2058702964)
connected to recovery catalog database
Register all information in relation to the targetted database inside the rman catalog
RMAN> REGISTER DATABASE;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

remark: To unregister a database from the recovery catalog, use UNREGISTER DATABASE;

6) Configure the retention policy
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete