Thursday, December 11, 2014

Oracle Database restore from backup using Duplicate RMAN.

Assumptions

There is a full backup level0 with control file and spfile in +DATA/ocdb/rmandata, it can be any location not necessarily ASM

Restoring backup onto database ocdb, db_name=ocdb
Backup belongs to OCDB database.
Incarnation is set to correct one.

STEP1

Startup new instance with following



db_name=ocdb
CONTROL_FILES='+DATA','+RECO'
db_create_file_dest='+DATA'
DB_CREATE_ONLINE_LOG_DEST_1='+RECO'
DB_CREATE_ONLINE_LOG_DEST_2='+RECO'
DB_RECOVERY_FILE_DEST='+RECO'


startup nomount pfile='/tmp/init.ora'




STEP2

Run following to restore database untill time from old backup.

connect auxiliary  /
run
 {
 ALLOCATE AUXILIARY CHANNEL ch1 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch2 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch3 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch4 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch5 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch6 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch7 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch8 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch9 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch10 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch11 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch12 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch13 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch14 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch15 DEVICE TYPE disk;
 ALLOCATE AUXILIARY CHANNEL ch16 DEVICE TYPE disk;
 DUPLICATE DATABASE TO ocdb
 BACKUP LOCATION '+DATA/ocdb/rmandata'
  until time "to_date ('15-10-2014 21:00:00', 'DD-MM-YYYY HH24:MI:SS')"
  NOFILENAMECHECK;
}

Active Duplicate using RMAN.

Two big disadvantages of the ACTIVE database duplication method are:

    Negative performance impact on the source database.
    High network traffic on the connection between the source and target databases.



STEP1

On TARGET database server.

change following parameters in init parameter file specific to target database

alter system set db_name=targetdb scope=spfile;
alter system set cluster_database=false scope=spfile;
alter system set db_create_file_dest='+DATA';
alter system set db_create_online_log_dest_1='+REDO';
alter system set db_create_online_log_dest_2='+REDO';


startup nomount pfile='/tmp/init.ora'

STEP2

On TARGET database server,change listener.ora make sure ORACLE_HOME is there in the file.

SID_LIST_LISTENER =
  (SID_LIST =
    )
    (SID_DESC =
      (SID_NAME = targetdb1)
      (ORACLE_HOME = /apps/oracle/product/11.2.0/db_1)
      (GLOBAL_DBNAME = targetdb)
    )
  )

and do lsnrctl status, lsnrctl reload


STEP3

Add following entries to both tnsnames.ora files on both SOURCE and TARGET

SOURCE =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = sourceserv)(PORT = 1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = source)
      )
    )
  
  target =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = targetserv)(PORT = 1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = target)
      )
  )
 
   
 
STEP4

Create password file on both SOURCE and TARGET
If the password file already exists on source just copy it to TARGET $ORACLE_HOME/dbs


STEP5

Test connectivity to both SOURCE and TARGET from both servers using TNS entries created in STEP3 and
make sure it works


sqlplus sys/sys@target as sysdba
sqlplus sys/sys@source as sysdba



STEP6

On Auxillary host(TARGET) start RMAN and run DUPLICATE

Here very important auxillary connection is TARGET and connection target is SOURCE



$export ORACLE_SID=HRPRD1

$rman target sys/sys@SOURCE auxiliary sys/sys@TARGET
RMAN>run{
         DUPLICATE target DATABASE TO TARGET------> (the first target is the connection target and the second is db name of target database.)
         FROM ACTIVE DATABASE;
        }

Wednesday, December 3, 2014

View data in a datafile.

SQL> create tablespace testts datafile '/tmp/testts_01.dbf' size 1M;

SQL> create table mythbuster1 (col1 varchar2(200)) tablespace testts;


Insert a row:


SQL> insert into mythbuster1 values (‘ORIGINAL_VALUE’);
SQL> Commit; 
 
 
 
$ strings /tmp/testts_01.dbf
}|{z
-N?pD112D2
TESTTS
 1j)
 w>!
ORIGINAL_VALUE
 
 
 
Wait event.
 
The server process then identifies the block the row exists in. After 
the database instance just came up the buffer cache is empty and the 
block will not be found. Therefore the server process issues a read call
 from the datafile for that specific block. The block is read from the 
disk to the buffer cache.
Until the loading of the block from the disk 
to the buffer cache is complete, 
the session waits with the event – db file scattered read
 
 
Two Task Architecture 
 
 There are two tasks – the 
user task that a regular user has written and the server task that 
performs the database operations. This is an important concept 
established during the early foundations of the Oracle database to 
protect the database from errant code in the user task introduced either
 maliciously or inadvertently.
 
usertask=user processes=Java program, a Pro*C code, SQL*Plus process
server task=server processes=oracleinstance