Friday, November 1, 2013

RMAN & Golden Gate : how rman can be used to instantiate a database which will be kept in sync later using Golden Gate


NOTE : THE BELOW IS From Istvan Stahl's Blog and NOT from me. Thanks Istvan Stahl. For  more info visit Istvan Stahl's blog : http://istvanstahl.wordpress.com/category/golden-gate/
===============================================================
OK. Let’s do some blogging :)
In my first blog entry I’ll cover how rman can be used to instantiate a database which will be kept in sync later using Golden Gate.
Prerequisites:
- source database (10.2.0.5) called:  source (everything in ASM, this adds one more challenge to configure Golden Gate)
- on the same host we are going to create the target database, and setup the golden gate replication from a particular SCN
The steps for this tutorial:
1. Create you source database using dbca  (make sure you have ASM instance and listener on 1521 port ready).
:
:
4.  Configure the source database

5. Create a simple demo schema in the source database (the column “text” is clob just to try if replication of log columns is working as well)

6. Backup your source database
7. Configure source GG

8. Now let’s create the target database using RMAN
First backup the newly created archive logs of the source database, and create a pfile.

9. Configure GG for the target database

10. Now start the source extratct and the target replicat

I hope you succeeded as well :) If not please leave a comment.

Monday, June 17, 2013

RMAN Recovery Scenarios (Incomplete)

Performing Time/ Sequence Based

Problem
You want to restore your database to a previous date and time.

Solution
You can restore your database to a previous time in one of two ways:
• Specify the time as part of the restore and recover commands. (until time)
• Use the set until time command, and then issue unqualified restore and recover
commands. (set until time)


RMAN> connect target /
RMAN> startup mount;
RMAN> restore database until time                                                [until sequence 50;]
2> "to_date('05-oct-2006 14:00:00', 'dd-mon-rrrr hh24:mi:ss')";
RMAN> recover database until time
2> "to_date('05-oct-2006 14:00:00', 'dd-mon-rrrr hh24:mi:ss')";
RMAN> alter database open resetlogs;
Database altered

NOTE :
You can also specify the time by using the set until time command. This command and
the subsequent restore and recover must be executed from within a run{} block:
RMAN> connect target /
RMAN> startup mount;
RMAN> run{                                                                                   [set until sequence 125;]
RMAN> set until time "to_date('05-oct-2006 14:00:00', 'dd-mon-rrrr hh24:mi:ss')";
RMAN> restore database;
RMAN> recover database;
RMAN> }
RMAN> alter database open resetlogs;
Database altered

Thursday, June 13, 2013

RMAN Recovery Scenarios (Complete)

Previewing Backups Needed for Restore:

Normal more:  
RMAN> restore tablespace system preview;
RMAN> restore database preview;
RMAN> restore database from tag TAG20060927T183743 preview;
RMAN> restore datafile 1, 2, 3, 4 preview;
RMAN> restore archivelog all preview;
RMAN> restore archivelog from time 'sysdate - 1' preview;
RMAN> restore archivelog from scn 3243256 preview;
RMAN> restore archivelog from sequence 29 preview;

Summary more: 
RMAN> restore database preview summary;


Block Corruption:

A DB block gets corrupted, when an invalid data is written to it and committed. Oracle throws a Block Corruption error only when it tries to access the block for some purpose.

Physical corruption:   The block itself is not recognized.
Logical corruption:    The contents of the block is logically inconsistent.

Verify the availability and integrity of backup pieces, before RESTORE operation:

  • You can use either the restore ... validate or validate command
  • You can additionally specify the check logical clause to instruct RMAN to check for logical corruption
restore ... validate:
RMAN> restore database validate;
RMAN> restore database from tag MON_BCK validate;
RMAN> restore datafile 1 validate;
RMAN> restore archivelog all validate;
RMAN> restore controlfile validate;
RMAN> restore tablespace users validate;

validate:
RMAN> validate backupset 193;


RMAN’s behavior of searching sequentially back through backups until a good backup is found is
called restore failover.



Performing Database level recovery:

All database files lost. Online redolog files are there - Perform complete recovery.
Performing DB-Level Recovery:

RMAN> connect target /
RMAN> startup mount; ----> using current controlfile
RMAN> restore database;   
RMAN> recover database;
RMAN> alter database open;


RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup; -----> using FRA autobackup controlfile
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;
RMAN> alter database open resetlogs;

--------------

Performing Tablespace-Level Recovery:

Offline-tablespace:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore tablespace user_data, user_index;
RMAN> recover tablespace user_data, user_index;
RMAN> alter database open;

Online-tablespace:

RMAN> connect target /
RMAN> sql 'alter tablespace data_ts offline immediate';
RMAN> restore tablespace data_ts;
RMAN> recover tablespace data_ts;
RMAN> sql 'alter tablespace data_ts online';


----------

Performing Datafile-Level Recovery:

Offline-Datafile:

RMAN> connect target /
RMAN> startup mount;
RMAN> restore datafile '/ora01/brdstn/system_01.dbf';
RMAN> recover datafile '/ora01/brdstn/system_01.dbf';
RMAN> alter database open;

Online-Datafile:

RMAN> connect target /
RMAN> sql 'alter database datafile 3, 4 offline';
RMAN> restore datafile 3, 4;
RMAN> recover datafile 3, 4;
RMAN> sql 'alter database datafile 3, 4 online';

[OR]

RMAN> sql "alter database datafile ''/ora01/BRDSTN/data_ts01.dbf'' offline";
RMAN> restore datafile '/ora01/BRDSTN/data_ts01.dbf';
RMAN> recover datafile '/ora01/BRDSTN/data_ts01.dbf';
RMAN> sql "alter datafile ''/ora01/BRDSTN/data_ts01.dbf'' online";



Restoring Datafiles to Nondefault Locations (SRSR = Setnewname, Restore, Switch, Recover)
-----------------------------------------------------------------------------------------------------------------------

DB is OFFLINE:
==============

RMAN> connect target /
RMAN> startup mount;
RMAN> run{
2> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
3> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
4> restore tablespace data_ts;
5> switch datafile all; # Updates repository with new datafile location.    [switch datafile 4 also ok]
6> recover tablespace data_ts;
7> alter database open;
8> }


DB is ONLINE:
==============

RMAN> run{
2> sql 'alter database datafile 4, 5 offline';
3> set newname for datafile 4 to '/ora01/BRDSTN/data_ts01.dbf';
4> set newname for datafile 5 to '/ora01/BRDSTN/data_ts02.dbf';
5> restore datafile 4, 5;
5> switch datafile all; # Updates repository with new datafile location.
6> recover datafile 4, 5;
7> sql 'alter database datafile 4, 5 online';
8> }


[OR]

RMAN> run{
2> sql "alter database datafile ''/ora02/BRDSTN/data_ts01.dbf'' offline';
3> set newname for datafile '/ora02/BRDSTN/data_ts01.dbf'
4> to '/ora01/BRDSTN/data_ts01.dbf';
5> restore datafile '/ora02/BRDSTN/data_ts01.dbf';
6> switch datafile all; # Updates repository with new datafile location.
7> recover datafile '/ora01/BRDSTN/data_ts01.dbf';
8> sql "alter database datafile ''/ora01/BRDSTN/data_ts01.dbf'' online";
9> }

Performing Block-Level Recovery

  • Block-level corruption is rare and is usually caused by some sort of I/O error.
  • RMAN will automatically detect corruption in blocks whenever a backup or backupvalidate command is issued.
  • Your database must be in archivelog mode for performing block-level recoveries

When RMAN detects corrupt blocks, it writes an error to the trace files/alert.log file and also populates the V$DATABASE_BLOCK_CORRUPTION view. You can instruct RMAN to recover the
blocks listed as corrupt in that view as follows:

You can instruct RMAN to recover blocks in two ways:
• Use the corruption list clause.
• Specify individual datafiles and blocks.


RMAN> blockrecover corruption list; -----> 10g 
[OR]
RMAN> recover corruption list;  ----> 11g

The other way to recover blocks is to specify particular datafiles and blocks. Here are several
examples:
RMAN> recover datafile 5 block 24;
RMAN> recover datafile 7 block 22 datafile 8 block 43;
RMAN> recover datafile 5 block 24 from tag=tues_backup;
RMAN> recover datafile 6 block 89 restore until sequence 546;
RMAN> recover datafile 5 block 32 restore until 'sysdate-1';
RMAN> recover datafile 5 block 65 restore until scn 23453;






Monday, June 10, 2013

RMAN Recovery Scenarios

Restoring Control file:
     | 1. Using FRA

When "Autobackup ON" enabled:
RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from autobackup;

     Control file location when Autobackup Enabled:
     \<FRA>\<target database SID>\autobackup\YYYY_MM_DD\<backup piece file>


When "Autobackup OFF" enabled:
RMAN> connect target /
RMAN> startup nomount;
RMAN> restore controlfile from
2> 'C:\FRA\DB1\backupset\2006_09_23\01_mf_ncnnf_TAG20060923T02kc1vgsh.bck';

     Control file location when Autobackup is NOT Enabled:
    \<FRA>\<target database SID>\backupset\YYYY_MM_DD\<backup piece file>


     | 2. Using RC

RMAN> connect target /
RMAN> connect catalog rcat/rcat@recov
RMAN> startup nomount;
RMAN> list backup of controlfile;   ------------------------> To  view the list of control files

RMAN> restore controlfile;

--------------------------------------------------------------------------------------------------------------

Using Autobackup, with RMAN Backup Piece in the Default Location:
RMAN> set dbid 2601506593;
RMAN> restore controlfile from autobackup;

Using Autobackup, with RMAN Backup Piece in a Nondefault Location:
RMAN> set dbid 2601506594;
RMAN> set controlfile autobackup format for device type disk to 'C:\ODUMP\%F';
RMAN> restore controlfile from autobackup;

Not Using Autobackup, with RMAN Backup Piece in the Default Location
RMAN> restore controlfile from '/ora01/app/oracle/product/10.2.0/dbs/1hhu0gn1_1_1';

Not Using Autobackup, with RMAN Backup Piece in Nondefault Location
RMAN> configure channel device type disk format '/orabackups/%d%U.bus';

RMAN> restore controlfile from '/orabackups/BRDSTN1lhu0oi_1_1.bus';

----------------------------------------------------------------------------------------------------------------

Sunday, June 9, 2013

RMAN Scripting

You can use the cmdfile command-line option to call a command file while calling RMAN
from the Unix shell prompt

$ rman target=/ catalog=u/p@catalog cmdfile=cmd.rman


1:-----------------
You can call a stored script using the script parameter on the command line, as shown
here:
$ rman target=/ catalog=u/p@catalog script stored_script


2:-----------------
You can store scripts in a catalog and call them from the RMAN command prompt, as shown
here:
RMAN> run { execute script stored_script; }


3:-----------------
To execute the global script, you call that script with the clause global before it, as shown in
the following RMAN command:
RMAN> run { execute global script delete_arc_logs; }


Tuesday, June 4, 2013

RMAN Backup scenarios

Always BEST to set: configure controlfile autobackup to on;
                                                                        --------
7-1. Specifying Image Copy or Backup Set Output
RMAN> backup as backupset
database;

RMAN> backup as backupset
device type sbt
database;

RMAN> backup as copy
database;

RMAN> backup
database
format= '/u01/backup_%U ';

RMAN> backup
database
format '+dgroup1';                               --à for ASM

RMAN> backup
database
tag 'weekly_backup';


7-2. Backing Up the Control File
RMAN> configure controlfile autobackup on; 
[OR]
RMAN> backup current controlfile;
RMAN> backup tablespace users include current controlfile;


7-3. Backing Up the Server Parameter File
RMAN> backup spfile;


7-4. Backing Up Datafiles
RMAN> backup  as copy datafile 1,2,3,4
format '/u01/app/oracle/rman/%d_%U.bus';


7-5. Backing Up Tablespaces

RMAN> backup tablespace users, tools;

RMAN> backup tablespace system format '/ora01/prod1/%d_%U.bus';

RMAN> backup as copy tablespace users;

RMAN> backup incremental level 1 tablespace example;



7-6.Making a Whole-Database Backup


RMAN> backup database;                -->    Datafile + Controlfile + SPFile


RMAN> SQL "alter system archive log current"; -à to archive all the redo log generated during the
above backup was going on…


7-7. Backing Up Archived Redo Logs

RMAN> backup archivelog all;

RMAN> backup device type sbt
archivelog like '/disk%arc%'
delete all input;


RMAN> backup database plus archivelog
The above command does the below sequence of steps:

1. Run the alter system archive log current command.
2. Run the backup archivelog all command.
3. Back up the rest of the datafiles specified by the backup database command.
4. Run the alter system archive log current command.
5. Back up the new archive logs generated during the backup operation.


7-8. Backing Up Everything [ datafile+controlfile+archived log file+spfile]
RMAN> configure controlfile autobackup on;
+
RMAN> backup database plus archivelog;

7-9. Incremental backup:
RMAN> list backup by file;
RMAN> backup incremental level 0 database;
RMAN> backup incremental level 1 database;
RMAN> backup incremental level 1 cumulative database;
You can’t perform an incremental copy of a control file, archived redo log, or backup set.


7-19.Making a Compressed Backup   [binary compressed backup]

RMAN> backup
as compressed backupset
database plus archivelog;


7-20. Parallelizing Backups

run
{
allocate channel ch1 device type sbt
parms 'env=(ob_device_1=testtape1)';        
allocate channel ch2 device type sbt
parms 'env=(ob_device_2=testtape12';
backup
database channel ch1
archivelog all channel ch2;
}

OB_DEVICE[_n] --->  parameter to define which tape drives can be used for backups.



PARALLESISM :
RMAN> configure device type disk parallelism 4;
+
run
{
allocate channel d1 device type disk format '/u01/%d_backups/%U';
allocate channel d2 device type disk format '/u02/%d_backups/%U';
allocate channel d3 device type disk format '/u03/%d_backups/%U';
allocate channel d4 device type disk format '/u04/%d_backups/%U';
backup database;
}

If you want to configure persistent backup parallelism

1. First specify the degree of parallelism for the device type you want:
    configure device type disk parallelism 4;
2. Secondly, configure channels:
    configure channel 1 device type disk format '/u01/%d_backups/%U';
    configure channel 2 device type disk format '/u02/%d_backups/%U';
    configure channel 3 device type disk format '/u03/%d_backups/%U';
    configure channel 4 device type disk format '/u04/%d_backups/%U';

Sunday, June 2, 2013

RMAN 'backup database plus archivelog'

When you use the backup database plus archivelogcommand to back up archive logs as part of another backup, RMAN will perform the following operations in the sequence listed here: .
1. Run the alter system archive log currentcommand.
 2.Run the backup archivelog allcommand.
 3.Back up the rest of the datafiles specified by the backup databasecommand
4.Run the alter system archive log currentcommand.
5.Back up the new archive logs generated during the backup operation. The sequence of operations listed here means that RMAN will have all the necessary archived redo log information that it’ll need down the road if it has to perform a complete recovery of the database. ■NoteThe backup dathe entire database and all the archived redo logs as well as the current control file in a single command.See the next recipe for details

Saturday, June 1, 2013

RMAN snapshot control file

RMAN requires a consistent view of the control file under two circumstances:

• When resynchronizing with the recovery catalog
• When making a backup of the control file

To achieve these two goals, RMAN creates a temporary backup copy of the control file
called the snapshot control file, which enables RMAN to resynchronize with the recovery catalog
or back up the control file, using a read-consistent version of the control file. The default
location and name of the snapshot control file is operating system dependent. On Windows
XP, the default location is ORACLE_HOME/database, and the default name of the snapshot
control file is of the form SNCF<database name>.ORA. On Unix the default directory


Note :

Oracle allows only one RMAN session to access the snapshot control file at a time. This ensures that multiple RMAN sessions do not concurrently write and read from the snapshot control file.



CHANNEL ALLOCATION IN RMAN:

By default, RMAN comes with a single disk channel preconfigured, starting with the Oracle9i
release of the database. So, if you’re backing up to a disk, you don’t have to manually allocate
a channel. However, if you’re backing up to tape, you must either configure an automatic
channel for the tape device or manually allocate a tape (sbt) channel as part of the backup
commands you issue.

run {
allocate channel c1 device type sbt;
backup database;

}

Friday, May 31, 2013

Difference between full backup & level 0 incremental backup | Differential backup & cumulative backup

A level 0 incremental backup is physically identical to a full backup. The only difference is that the level 0 backup is recorded as an incremental backup in the RMAN repository, so it can be used as the parent for a level 1 backup.A full backup can never be part incremental backup strategy i.e it cannot be the parent for a subsequent incremental backup.

----------

Differential backup, which backs up all blocks changed after the recent incremental backup at level 1 or 0

Cumulative backup, which backs up all blocks changed after the most recent incremental backup at level 0

Note : Cumulative backups are preferable to differential backups when recovery time is more important than disk space, because during recovery each differential backup must be applied in succession. Use cumulative incremental backups instead of differential, if enough disk space is available to store cumulative incremental backups.

ORA-01555 can be avoided by following precautions:

ORA-01555 can be avoided by following precautions:

1. Database should be in Automatic Undo Management mode.
2. Use a large optimal value for undo_retention.
3. Use a large optimal size of rollback segment (undo) size.
4. Should avoid to fetch (select / cursors) between commits.
5. Should Commit less often at the time of long running query, to reduce Undo Segment slot reuse.
6. Try to run long running queries on off peak hours, when there is less DML transactions on database.

Oracle row type vs PostgreSQL record

The Oracle row type concept can be accomplished with the record type in PostgreSQL. Example: Oracle: CURSOR travel_cur IS  SELECT  c.travel_...