Tuesday, 2 April 2013

11G RMAN BACKUP BASED CLONING


Source(TARGET) instance information:
Instance name=DLINK
hostname=mydbt4db2
datafile location=/u03/oradata/DLINK, /u02/oradata/DLINK
Redolog file location=/u03/oradata/DLINK
Archive log file location=/u02/oradata/arch

Auxiliary instance (RLINK) information:

Instance name=RLINK
hostname=mydbt4db4
datafile location=/u03/oradata/RLINK, /u02/oradata/RLINK
Redolog file location=/u03/oradata/RLINK
Archive log file location=/u02/oradata/arch_RLINK

1) Create required directory structure at auxiliary side

[oracle@mydbt4db4 admin]$ mkdir -p /u02/oradata/RLINK
[oracle@mydbt4db4 admin]$ mkdir -p /u03/oradata/RLINK
[oracle@mydbt4db4 admin]$ mkdir -p /u02/oradata/arch_RLINK

2) Define ORACLE_SID and other required settings for auxiliary instance

[oracle@mydbt4db4 ~]$ vi .bash_profile
[oracle@mydbt4db4 ~]$ pwd
/home/oracle
[oracle@mydbt4db4 ~]$ . .bash_profile
[oracle@mydbt4db4 ~]$ echo $ORACLE_SID
RLINK
[oracle@mydbt4db4 ~]$

3) Creating initialization Parameter file for the Auxiliary instance(RLINK)


[oracle@mydbt4db4 dbs]$ vi initTLINK.ora
[oracle@mydbt4db4 dbs]$ cat initTLINK.ora
db_name='RLINK'
memory_target=200M
db_block_size=8192
control_files ='/u02/oradata/RLINK/control1.ctl','/u03/oradata/RLINK/control2.ctl'
compatible ='11.2.0'
log_archive_dest=/u02/oradata/arch_RLINK
log_file_name_convert='/u03/oradata/DLINK','/u03/oradata/RLINK'
db_file_name_convert='/u03/oradata/DLINK','/u03/oradata/RLINK','/u02/oradata/DLINK','/u02/oradata/RLINK'

4) Create password file at auxiliary side(TLINK)

[oracle@mydbt4db4 ~]$ cd $ORACLE_HOME/dbs
[oracle@mydbt4db4 dbs]$ orapwd file=orapw$ORACLE_SID password=sys force=y
[oracle@mydbt4db4 dbs]$ ls -ltr orapwR*
-rw-r----- 1 oracle oinstall 1536 Nov 26 16:55 orapwRLINK
[oracle@mydbt4db4 dbs]$


5) Take a backup of the database Source

RMAN> backup database plus archivelog;


Starting backup at 26-NOV-12
current log archived
configuration for DISK channel 2 is ignored
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
.
.
.
.
Starting Control File and SPFILE Autobackup at 26-NOV-12
piece handle=/u02/oradata/rman_bkp/c-2903807241-20121126-00 comment=NONE
Finished Control File and SPFILE Autobackup at 26-NOV-12


6)  Prepare for duplicate by starting the auxiliary instance

[oracle@mydbt4db4 rman_bkp]$  sqlplus '/as sysdba'

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 26 08:41:59 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
.
7) Copy the backupsets from source to your auxiliary server

If the duplicate is going to happen on different server, move the backup pieces to a new server using commands like ftp,scp etc

[oracle@mydbt4db2 rman_bkp]$ scp *  oracle@192.168.3.19:/u02/oradata/RMAN_BKP


8) Connect to the auxiliary instance from RMAN and perform the rman duplicate as follows

rman auxiliary /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 26 20:41:32 2012

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

connected to auxiliary database: RLINK (not mounted)

RMAN>  DUPLICATE DATABASE TO 'RLINK'
2> BACKUP LOCATION '/u02/oradata/RMAN_BKP';

Starting Duplicate Db at 26-NOV-12

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
.
.
.
.
.
executing Memory Script
contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 26-NOV-12

Active duplication cloning using RMAN in 11G


You can create a duplicate database using the RMAN duplicate command. The duplicate database has a different DBID from the source database and functions entirely independently. Starting from 11g you can do duplicate database in 2 ways.
1. Active database duplication
2. Backup-based duplication
Active database duplication copies the live target database over the network to the auxiliary destination and then creates the duplicate database. Only difference is that you don't need to have the pre-existing RMAN backups and copies. The duplication work is performed by an auxiliary channel. This channel corresponds to a server session on the auxiliary instance on the auxiliary host.
As part of the duplicating operation, RMAN automates the following steps: 

1. Creates a control file for the duplicate database 
2. Restarts the auxiliary instance and mounts the duplicate control file 
3. Creates the duplicate datafiles and recovers them with incremental backups and archived redo logs. 
4. Opens the duplicate database with the RESETLOGS option 
For the active database duplication, RMAN does one extra step .i.e. copy the target database datafiles over the network to the auxiliary instance
Source(TARGET) instance information:
Instance name=DLINK
hostname=mydbt4db2
datafile location=/u03/oradata/DLINK, /u02/oradata/DLINK
Redolog file location=/u03/oradata/DLINK
Archive log file location=/u02/oradata/arch

Auxiliary instance information:

Instance name=TLINK
hostname=mydbt4db4
datafile location=/u03/oradata/TLINK, /u02/oradata/TLINK
Redolog file location=/u03/oradata/TLINK
Archive log file location=/u02/oradata/arch_TLINK

Note: Before proceeding with active duplication ,rman should be fully configured on
Source side with or without catalog database.

1 )Define ORACLE_SID and other required settings for auxiliary instnace

[oracle@mydbt4db4 ~]$ vi .bash_profile
[oracle@mydbt4db4 ~]$ . .bash_profile
[oracle@mydbt4db4 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/dbhome_1
[oracle@mydbt4db4 ~]$ echo $ORACLE_SID
TLINK
[oracle@mydbt4db4 ~]$ echo $TNS_ADMIN
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin
[oracle@mydbt4db4 ~]$

1.b)Create required directory structure at auxiliary side

[oracle@mydbt4db4 admin]$ mkdir -p /u02/oradata/TLINK
[oracle@mydbt4db4 admin]$ mkdir -p /u03/oradata/TLINK
[oracle@mydbt4db4 admin]$ mkdir -p /u02/oradata/arch_TLINK


2)  Creating initialization Parameter file for the Auxiliary instance(TLINK)


[oracle@mydbt4db4 dbs]$ cd $ORACLE_HOME/dbs
[oracle@mydbt4db4 dbs]$ vi initTLINK.ora
[oracle@mydbt4db4 dbs]$ more initTLINK.ora
db_name='TLINK'
memory_target=200M
db_block_size=8192
control_files ='/u02/oradata/TLINK/control1.ctl','/u03/oradata/TLINK/control2.ctl'
compatible ='11.2.0'
log_archive_dest=/u02/oradata/arch_TLINK
log_file_name_convert='/u03/oradata/DLINK','/u03/oradata/TLINK'
db_file_name_convert='/u03/oradata/DLINK','/u03/oradata/TLINK','/u02/oradata/DLINK','/u02/oradata/TLINK'

3) Create password file at auxiliary side(TLINK)
[oracle@mydbt4db4 ~]$ cd $ORACLE_HOME/dbs
[oracle@mydbt4db4 dbs]$ orapwd file=orapw$ORACLE_SID password=sys force=y
[oracle@mydbt4db4 dbs]$ ls -ltr orapw*
-rw-r----- 1 oracle oinstall 1536 Nov 26 13:44 orapwTLINK

4) Start auxiliary instance

 [oracle@mydbt4db4 dbs]$ sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 26 13:50:00 2012
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

5) Configure listener at auxiliary side

[oracle@mydbt4db4 dbs]$ cd $TNS_ADMIN
[oracle@mydbt4db4 admin]$ vi listener.ora
[oracle@mydbt4db4 admin]$ more listener.ora
TLINK =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = mydbt4db4.redLINKtech.com)(PORT = 1526))
    )
  )

SID_LIST_TLINK =
  (SID_LIST =
    (SID_DESC =
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = TLINK)
    )
  )

[oracle@mydbt4db4 admin]$ lsnrctl start TLINK

6) Configure listener at TARGET(source) side

[oracle@mydbt4db2 admin]$ cd $TNS_ADMIN
[oracle@mydbt4db2 admin]$ vi listener.ora
[oracle@mydbt4db2 admin]$ more listener.ora
DLINK =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = mydbt4db2.redLINKtech.com)(PORT = 1525))
    )
  )

SID_LIST_DLINK =
  (SID_LIST =
    (SID_DESC =
      (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = DLINK)
    )
  )
[oracle@mydbt4db2 admin]$ lsnrctl start DLINK


7)Create password file at TARGET(DLINK) side

[oracle@mydbt4db2 admin]$ cd $ORACLE_HOME/dbs
[oracle@mydbt4db2 dbs]$ orapwd file=orapw$ORACLE_SID password=sys force=y
[oracle@mydbt4db2 dbs]$ ls -ltr orapw*
-rw-r----- 1 oracle oinstall 1536 Nov 26 02:29 orapwDLINK
[oracle@mydbt4db2 dbs]$

8) Configure tns alias at auxiliary(TLINK) to connect TARGET database(DLINK).

[oracle@mydbt4db4 admin]$ cd $TNS_ADMIN
[oracle@mydbt4db4 admin]$ vi tnsnames.ora
[oracle@mydbt4db4 admin]$ more tnsnames.ora
to_dLINK=
        (DESCRIPTION=
                (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db2.redLINKtech.com)(PORT=1525))
            (CONNECT_DATA=
                (SID=DLINK)
            )
        )

to_tLINK=
        (DESCRIPTION=
                (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db4.redLINKtech.com)(PORT=1526))
            (CONNECT_DATA=
                (SID=TLINK)
            )
        )
[oracle@mydbt4db4 admin]$ tnsping to_dLINK
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 26-NOV-2012 14:15:40
Copyright (c) 1997, 2009, Oracle.  All rights reserved.
Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db2.redLINKtech.com)(PORT=1525)) (CONNECT_DATA= (SID=DLINK)))
OK (70 msec)

[oracle@mydbt4db4 admin]$ tnsping to_tLINK

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 26-NOV-2012 14:15:51
Copyright (c) 1997, 2009, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db4.redLINKtech.com)(PORT=1526)) (CONNECT_DATA= (SID=TLINK)))
OK (50 msec)

9) Configure tns alias at Target(DLINK) to connect auxiliary  instance (TLINK).

[oracle@mydbt4db2 admin]$ cd $TNS_ADMIN
[oracle@mydbt4db2 admin]$
[oracle@mydbt4db2 admin]$ vi tnsnames.ora
[oracle@mydbt4db2 admin]$ more tnsnames.ora
to_tLINK=
        (DESCRIPTION=
                (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db4.redLINKtech.com)(PORT=1526))
            (CONNECT_DATA=
                (SID=TLINK)
            )
        )
[oracle@mydbt4db2 admin]$ tnsping to_tLINK

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 26-NOV-2012 02:27:09

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=mydbt4db4.redLINKtech.com)(PORT=1526)) (CONNECT_DATA= (SID=TLINK)))
OK (180 msec)
[oracle@mydbt4db2 admin]$
10. Start RMAN and Connect to the Database Instances
Start RMAN and connect to the source database as TARGET, the duplicate database instance as AUXILIARY, and, if applicable, the recovery catalog database. You can start the RMAN client on any host so long as it can connect to all of the database instances. If the auxiliary instance requires a text-based initialization parameter file, then this file must exist on the same host that runs the RMAN client application.
In this bulletin we are doing duplicate database from the auxiliary server. Look at the example :

[oracle@mydbt4db4 admin]$ rman

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 26 14:53:24 2012

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

RMAN> connect target sys/sys@to_dLINK

connected to target database: DLINK (DBID=2903807241)

RMAN> connect auxiliary sys/sys@to_tLINK

connected to auxiliary database: TLINK (not mounted)

11)  Run the DUPLICATE database command
The simplest case is to use active database duplication to duplicate the database to a different host and use the different directory structure. Look at the example :

RMAN> DUPLICATE TARGET DATABASE
2> to 'TLINK'
3> FROM ACTIVE DATABASE;

Starting Duplicate Db at 26-NOV-12
using target database control file instead of recovery catalog
configuration for DISK channel 2 is ignored
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=96 device type=DISK

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script
.
.
.
.
contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 26-NOV-12

RMAN>

TRANSPORTABLE TABLESPACES in oracle 11G


Source machine;
We will transport tablespaces using EXP and EXPDP commands. So we need our database up and running

SQL> startup;
ORACLE instance started.
Database opened.

SQL> create tablespace tts datafile '/u02/oradata/rmanprod/tts.dbf' size 50M;
Tablespace created.

SQL> create user tts identified by tts default tablespace

SQL> create user ttsuser identified by ttsuser default tablespace tts;
User created.

SQL> grant connect,resource to ttsuser;
Grant succeeded.

SQL> conn ttsuser/ttsuser
Connected.

SQL> create table a(a number);
Table created.

SQL> insert into a values(1);
1 row created.
Commit;

SQL> exec dbms_tts.TRANSPORT_SET_CHECK('TTS');
BEGIN dbms_tts.TRANSPORT_SET_CHECK('TTS'); END;

*
ERROR at line 1:
ORA-25153: Temporary Tablespace is Empty
ORA-06512: at line 1

Note :- If you get ORA-25153 error then you need to assign a default temporary tablespace to database.

SQL> alter database default temporary tablespace tempts;

SQL> exec dbms_tts.TRANSPORT_SET_CHECK('TTS');
PL/SQL procedure successfully completed.

SQL> select * from transport_set_violations;
no rows selected

I f you get any output other than  ‘no rows selected’ then we cannot export tablespace , we need to go through that output and we should take appropriate actions.

SQL> alter tablespace tts read only;
Tablespace altered.

SQL>exit.

[oracle@vmrshoret4db5 ~]$ exp file=tts_exp.dmp log=tts_exp.log TRANSPORT_TABLESPACE=Y TABLESPACES='TTS'
Export terminated successfully without warnings.
Now copy dumpfile and datafile to destination using scp command.

[oracle@vmrshoret4db5 ~]$ scp tts_exp.dmp oracle@192.168.3.18:/$HOME
[oracle@vmrshoret4db5 rmanprod]$ scp tts.dbf oracle@192.168.3.18:/u03/oradata/mls/

Now keep tablespace in read write mode

SQL> alter tablespace tts read write;
Tablespace altered. 

In destination
SQL> startup;
ORACLE instance started.

SQL> create user ttsuser identified by ttsuser;
User created.

[oracle@vmrshoret4db3 ~]$ imp file=tts_exp.dmp log=tts.log datafiles='/u03/oradata/mls/tts.dbf' TRANSPORT_TABLESPACE=Y TABLESPACES=TTS
Import terminated successfully without warnings.

SQL> select file_name from dba_data_files;
FILE_NAME
-----------------------------------------------------------
/u03/oradata/mls/system01.dbf
/u03/oradata/mls/sysaux01.dbf
/u03/oradata/mls/undotbs01.dbf
/u03/oradata/mls/tempts1.dbf
/u03/oradata/mls/tts.dbf

SQL> select plugged_in,tablespace_name from dba_tablespaces;
PLU         TABLESPACE_NAME
---            ------------------------------
NO          SYSTEM
NO          SYSAUX
NO          UNDOTBS1
NO          TEMPTS1
YES          TTS

Note:-If plugged_in value is yes then that tablespace is transported tablespace.

SQL> conn ttsuser/ttsuser;
Connected.

SQL> select * from a;


 Transportable tablespace for different datablock size(db block size) click on below link
http://learnappsdbaskills.blogspot.in/2013/07/transportable-tablespace-for-different.html