Monday 13 June 2016

Create/Configuring the Recovery Catalog Database


Allocate space for the recovery catalog. Consider:
– Number of databases supported by the recovery catalog
– Number of archived redo log files and backups recorded
– Use of RMAN stored scripts





Connect to the database where recovery catalog needs to be created and execute following Commands.

sqlplus sys as sysdba


Create a tablespace for the recovery catalog, which becomes the default tablespace for the recovery catalog owner.

CREATE TABLESPACE rmanbkup datafile '/home/oracle/product/11.2.0/dbhome_1/oradata/ow12c/rmanbkup.dbf' SIZE 75M autoextend ON NEXT 2M MAXSIZE UNLIMITED;


Create the recovery catalog owner.


CREATE USER rmanbkup IDENTIFIED BY oracle
 TEMPORARY TABLESPACE temp
 DEFAULT TABLESPACE rmanbkup
 QUOTA UNLIMITED ON rmanbkup ;

Grant the RECOVERY_CATALOG_OWNER role

GRANT recovery_catalog_owner TO rmanbkup;

Connect to the recovery catalog database as the catalog owner and create catalog.

[oracle@rhel6 ~/Desktop]$ rman catalog rmanbkup/oracle@ow12c

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 27 16:17:18 2016

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

connected to recovery catalog database

RMAN> CREATE CATALOG;

recovery catalog created

RMAN>  exit;


Now connect to catalog with target database to register database to recovery catalog 


RMAN performs the following actions:

• Creates rows in the recovery catalog tables for the target database
• Copies data from the target database control file to the recovery catalog tables
• Synchronizes the recovery catalog with the control file


[oracle@rhel6 oradata]$ rman target sys/oracle@ow11g catalog rmanbkup/oracle@ow12c

Recovery Manager: Release 11.2.0.3.0 - Production on Mon Jun 13 13:00:11 2016

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

connected to target database: OW11G (DBID=1397584131)
connected to recovery catalog database

RMAN> base: OW11G (DBID=1397584131)

connected to recovery catalog database


RMAN> REGISTER DATABASE;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete


Manually Resynchronizing the Recovery Catalog

RMAN> resync catalog;




To Unregistering a Target Database from the Recovery Catalog

• This removes information about the target database from the recovery catalog.
• Use this when you no longer want the target database to be defined in the recovery catalog.


$ rman target sys/oracle@ow11g catalog rmanbkup/oracle@ow12c

RMAN> UNREGISTER DATABASE;

database name is "OW11G" and DBID is 1397584131

Do you really want to unregister the database (enter YES or NO)? yes
database unregistered from the recovery catalog



Cataloging Additional Backup Files

Examples of cataloging a control file, data file, archived redo log file, and backup piece follow:

RMAN> CATALOG CONTROLFILECOPY
'/disk1/controlfile_bkup/2009_01_01/control01.ctl';
RMAN> CATALOG DATAFILECOPY
'/disk1/datafile_bkup/2009_01_01/users01.dbf';
RMAN> CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.log',
'/disk1/arch_logs/archive1_732.log';
RMAN> CATALOG BACKUPPIECE '/disk1/backups/backup_820.bkp';



You can catalog all files in the currently enabled Flash Recovery Area as follows:
RMAN> CATALOG RECOVERY AREA NOPROMPT;


START WITH Option
Use the START WITH option to catalog all files found in the directory tree specified. Provide a
prefix that indicates the directory and possibly a file prefix to look for. You cannot use wildcards;
this is only a prefix.


All types of backup files that are found in the specified directory and subdirectories are cataloged.
Suppose you have several backup files in the /tmp/arch_logs directory. The following
command catalogs all of them:

RMAN> CATALOG START WITH '/tmp/arch_logs/';

Suppose you want to be sure to catalog only those files in the /tmp directory whose file names start
with the string bset. The following accomplishes that:

RMAN> CATALOG START WITH '/tmp/bset';

This command also catalogs any backup files that are found in directory trees that begin with
/tmp/bset.

The CATALOG command can be used without being connected to a recovery catalog.



Sunday 12 June 2016

Oracle Dataguard Switch Over and Failover

Role Transitions/Switch-over  Involving Physical Standby Databases
------------------------------------------------------------

To check the switchover status of database issue the following commands on primary database

SQL>select switchover_status from v$database;

A value of TO STANDBY or SESSIONS ACTIVE indicates that the primary database can be
switched to the standby role.

SQL>alter database commit to switchover to physical standby with session shutdown;
then
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;

Above commands with create a new marker archived log which be applied on standby database a signal that the
standby is ready to work as primary database. you can confirm it by following commands on standby database.

SQL>select switchover_status from v$database;

If you received the switchover status of commands as "TO_PRIMARY" then its mean marker archived log has been received and  your database
is ready to change the status to primary.

Now issue the following command  on standby to change the status of standby database to primary.

SQL>ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

SQL>shutdown immediate;
SQL>startup;

Now enjoy your new primary database.

following command on current standby DB .

 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;

select sequence#,applied from v$archived_log order by 1;


Performing a Failover to a Physical Standby Database
=====================================================
1-check V$ARCHIVE_GAP  view for any gap. If there is gap manually copy the archives and register in standby.

 select * from v$archive_gap;

2- ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
               repeat for all missing archived files until gap resloved.

3- Change the physical standby status step by step by following commands.

Stop Redo Apply
---------------
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

Incase of error execute below statement otherwise skip it
SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
------


-----------check status and switchover to primary
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE ;


SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
SQL> ALTER DATABASE OPEN;

Open Standby Database for reporting Purpose

In this post we will perform different operations on standby like  Switch over ,Fail Over  ,Open standby database for reporting purpose,check standby database status.

Step-I Create standby control file.
SQL>alter database create standby controlfile as 'D:\docs\data\control.ctl';

move primary db and redo file plus standby control.clt file, password  and spfile.

On standby

1. make copy of standby control file
2. modify pfile with stand by parameters from oranet2
3 startup mount database with this pfile.
create spfile from pfile
alter database open

For Real Time apply.
-------------------
sqlplus / as sysdba

SQL>Startup mount

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;


Step-II Change the status of standby database in recover mode in background mode by the following commands.

SQL>alter database recover managed standby database disconnect;



Step-III To check the status of standby database issue the following command for applied
             archived logs.

SQL>select max(sequence#) from v$archived_log where applied='YES';
SQL>select sequence#,applied from v$archived_log order by 1;

Step-IV Stop Managed recovery on standby / Open for reporting.

SQL>alter database recover managed standby database cancel;
SQL>alter database open;

===============To again start stanby process ===============
shutdown immediate;
startup mount
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect;