Friday, September 29, 2017

Active Database Duplication (non-ASM to non-ASM on separate hosts)

Target (source) Host: Red Hat Enterprise Linux Server release 7.2 (Maipo)
Destination Host: CentOS Linux release 7.3.1611 (Core)
DB: 11.2.0.4.0
Target DB Name: maliyye
Destination DB Name: alfamal

Steps 1,2,9,10,12 will be executed from target (source) host.
Steps 3,4,5,6,7,8,11,13,14,15 will be executed from destination host.

1. Create a service for new database(alfamal) in tnsnames.ora file in target host.

[oracle@db admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

maliyye =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 112.100.11.25)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME = maliyye)
)
  )

stby =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 112.100.11.26)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME = stby)
)
  )

alfamal =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 112.100.11.31)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME =alfamal)
)
  )

2. Edit listener.ora file on target host.

   [oracle@db admin]$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521))
  (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
  )

SID_LIST_LISTENER=
  (SID_LIST=
(SID_DESC=
  (GLOBAL_DBNAME=alfamal)
  (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
  (SID_NAME=alfamal)
)
  )

ADR_BASE_LISTENER = /u01/app/oracle

And the restart listener: lsnrctl stop, lsnrctl start
  
3. Install only database software on destination host and create listener with netca.

4. Edit listener file on destination host as
[oracle@alfa admin]$ cat listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = TCP)(HOST = alfa)(PORT = 1521))
  (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
  )

SID_LIST_LISTENER=
  (SID_LIST=
(SID_DESC=
  (GLOBAL_DBNAME=alfamal)
  (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
  (SID_NAME=alfamal)
)
  )

ADR_BASE_LISTENER = /u01/app/oracle
And the restart listener: lsnrctl stop, lsnrctl start
5. Create a service for new database(alfamal) on destination host
[oracle@alfa admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

maliyye =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 112.100.11.25)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME = maliyye)
)
  )

alfamal =
  (DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 112.100.11.31)(PORT = 1521))
)
(CONNECT_DATA =
  (SERVICE_NAME =alfamal)
)
  )

6. Add a line in the file /etc/oratab to reflect the new database instance on destination host

   alfamal:/u01/app/oracle/product/11.2.0/dbhome_1:N
   
7. Set environment variables for duplicated database on destination host as 

   [oracle11g@orcl11g oracle]$ . oraenv
   ORACLE_SID = [maliyye] ? alfamal
   The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 is /u01/app/oracle

8. Create folders in destination host for duplicated database 

   [oracle@alfa ~]$ mkdir -p /u01/app/oracle/oradata
   [oracle@alfa ~]$ mkdir -p /u01/app/oracle/fast_recovery_area
   [oracle@alfa ~]$ mkdir -p /u01/app/oracle/admin/alfamal/adump
   [oracle@alfa ~]$ mkdir -p /u01/app/oracle/admin/alfamal/dpdump


9. Create pfile from target (source) database.

   SQL> create pfile='$ORACLE_HOME/dbs/initsource.ora' from spfile;
   File created.   
   
   
10. Copy the initialization parameter file from the target (source) database to destination database

   oracle11g@orcl11g oracle]$ cp $ORACLE_HOME/dbs/initsource.ora
                                                     /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initalfamal.ora
11. Edit the pfile initalfamal.ora as:

        *.audit_file_dest='/u01/app/oracle/admin/alfamal/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/alfamal/control01.ctl','/u01/app/oracle/fast_recovery_area/alfamal/control02.ctl'
*.db_block_size=8112
*.db_domain=''
*.db_name='alfamal'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=83687091200
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers=''
*.log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST'
*.log_archive_max_processes=5
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.db_create_file_dest='/u01/app/oracle/oradata'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
db_file_name_convert=("/u01/app/oracle/oradata/maliyye","/u01/app/oracle/oradata/alfamal")
log_file_name_convert=("/u01/app/oracle/oradata/maliyye","/u01/app/oracle/oradata/alfamal")


12. Copy the password file from target to destination host as well

       oracle11g@db~]$ cp $ORACLE_HOME/dbs/orapwmaliyye
                      $ORACLE_HOME/dbs/orapwalfamal

13. Startup the destination database in nomount mode using modified parameter file and create spfile from it. 

   SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initalfamal.ora';
   ORACLE instance started.

   Total System Global Area 2388422656 bytes
   Fixed Size            2215664 bytes
   Variable Size           1342177552 bytes
   Database Buffers  1023410176 bytes
   Redo Buffers         20611264 bytes
   SQL> sho parameter db_name
   NAME              TYPE       VALUE
   -----------------  ----------- -----------------------
   db_name           string     alfamal
   SQL> create spfile from pfile;
   File created.


14. Connect to target and auxiliary instance then duplicate database.
      Note: We have to connect auxiliary(destination) database with TNS name. If not duplication will fail. 
   
   [oracle@alfa admin]$ rman target sys/maliyye12@maliyye auxiliary=sys/maliyye12@alfamal
Recovery Manager: Release 11.2.0.4.0 - Production on Fri Sep 29 11:43:11 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: MALIYYE (DBID=2910117303)
connected to auxiliary database: ALFAMAL (not mounted)

RMAN> duplicate target database to ALFAMAL from active database;

Starting Duplicate Db at 29-SEP-17
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=66 device type=DISK

contents of Memory Script:
{
   sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     254738432 bytes

Fixed Size                     2252176 bytes
Variable Size                180355696 bytes
Database Buffers              67108864 bytes
Redo Buffers                   5021696 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
''MALIYYE'' comment=
''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name = 
''ALFAMAL'' comment=
''Modified by RMAN duplicate'' scope=spfile";
   shutdown clone immediate;
   startup clone force nomount
   backup as copy current controlfile auxiliary format  '/u01/app/oracle/oradata/alfamal/control01.ctl';
   restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/alfamal/control02.ctl' from 
'/u01/app/oracle/oradata/alfamal/control01.ctl';
   alter clone database mount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''MALIYYE'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''ALFAMAL'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area     254738432 bytes

Fixed Size                     2252176 bytes
Variable Size                180355696 bytes
Database Buffers              67108864 bytes
Redo Buffers                   5021696 bytes

Starting backup at 29-SEP-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=4 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_maliyye.f tag=TAG20170929T114514 RECID=2 STAMP=955971914
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 29-SEP-17

Starting restore at 29-SEP-17
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=66 device type=DISK

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 29-SEP-17

database mounted

contents of Memory Script:
{
   set newname for datafile  1 to 
"/u01/app/oracle/oradata/alfamal/system01.dbf";
   set newname for datafile  2 to 
"/u01/app/oracle/oradata/alfamal/sysaux01.dbf";
   set newname for datafile  3 to 
"/u01/app/oracle/oradata/alfamal/undotbs01.dbf";
   set newname for datafile  4 to 
"/u01/app/oracle/oradata/alfamal/users01.dbf";
   set newname for datafile  5 to 
"/u01/app/oracle/oradata/alfamal/index1";
   backup as copy reuse
   datafile  1 auxiliary format 
"/u01/app/oracle/oradata/alfamal/system01.dbf"   datafile 
2 auxiliary format 
"/u01/app/oracle/oradata/alfamal/sysaux01.dbf"   datafile 
3 auxiliary format 
"/u01/app/oracle/oradata/alfamal/undotbs01.dbf"   datafile 
4 auxiliary format 
"/u01/app/oracle/oradata/alfamal/users01.dbf"   datafile 
5 auxiliary format 
"/u01/app/oracle/oradata/alfamal/index1"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 29-SEP-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/maliyye/sysaux01.dbf
output file name=/u01/app/oracle/oradata/alfamal/sysaux01.dbf tag=TAG20170929T114521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/maliyye/system01.dbf
output file name=/u01/app/oracle/oradata/alfamal/system01.dbf tag=TAG20170929T114521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/maliyye/users01.dbf
output file name=/u01/app/oracle/oradata/alfamal/users01.dbf tag=TAG20170929T114521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/maliyye/index1
output file name=/u01/app/oracle/oradata/alfamal/index1 tag=TAG20170929T114521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/maliyye/undotbs01.dbf
output file name=/u01/app/oracle/oradata/alfamal/undotbs01.dbf tag=TAG20170929T114521
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 29-SEP-17

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/u01/app/oracle/fast_recovery_area/MALIYYE/archivelog/2017_09_29/o1_mf_1_205_dwvv1jtj_.arc" auxiliary format 
"/u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_%u_.arc"   ;
   catalog clone recovery area;
   switch clone datafile all;
}
executing Memory Script

Starting backup at 29-SEP-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=205 RECID=396 STAMP=955971968
output file name=/u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_16sfluc1_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 29-SEP-17

searching for all files in the recovery area

List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_16sfluc1_.arc
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_16sfluc1_.arc

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=955971967 file name=/u01/app/oracle/oradata/alfamal/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=955971967 file name=/u01/app/oracle/oradata/alfamal/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=955971967 file name=/u01/app/oracle/oradata/alfamal/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=955971967 file name=/u01/app/oracle/oradata/alfamal/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=955971967 file name=/u01/app/oracle/oradata/alfamal/index1

contents of Memory Script:
{
   set until scn  5557210;
   recover
   clone database
delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 29-SEP-17
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 205 is already on disk as file /u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_16sfluc1_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ALFAMAL/archivelog/2017_09_29/o1_mf_1_205_16sfluc1_.arc thread=1 sequence=205
media recovery complete, elapsed time: 00:00:01
Finished recover at 29-SEP-17
Oracle instance started

Total System Global Area     254738432 bytes

Fixed Size                     2252176 bytes
Variable Size                180355696 bytes
Database Buffers              67108864 bytes
Redo Buffers                   5021696 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name = 
''ALFAMAL'' comment=
''Reset to original value by RMAN'' scope=spfile";
   sql clone "alter system reset  db_unique_name scope=spfile";
   shutdown clone immediate;
   startup clone nomount;
}
executing Memory Script

sql statement: alter system set  db_name =  ''ALFAMAL'' comment= ''Reset to original value by RMAN'' scope=spfile

sql statement: alter system reset  db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area     254738432 bytes

Fixed Size                     2252176 bytes
Variable Size                180355696 bytes
Database Buffers              67108864 bytes
Redo Buffers                   5021696 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ALFAMAL" RESETLOGS ARCHIVELOG 
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
LOGFILE
  GROUP   1 ( '/u01/app/oracle/oradata/alfamal/redo01.log' ) SIZE 50 M  REUSE,
  GROUP   2 ( '/u01/app/oracle/oradata/alfamal/redo02.log' ) SIZE 50 M  REUSE,
  GROUP   3 ( '/u01/app/oracle/oradata/alfamal/redo03.log' ) SIZE 50 M  REUSE
DATAFILE
  '/u01/app/oracle/oradata/alfamal/system01.dbf'
CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for tempfile  1 to 
"/u01/app/oracle/oradata/alfamal/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/alfamal/sysaux01.dbf", 
"/u01/app/oracle/oradata/alfamal/undotbs01.dbf", 
"/u01/app/oracle/oradata/alfamal/users01.dbf", 
"/u01/app/oracle/oradata/alfamal/index1";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/alfamal/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/alfamal/sysaux01.dbf RECID=1 STAMP=955971980
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/alfamal/undotbs01.dbf RECID=2 STAMP=955971980
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/alfamal/users01.dbf RECID=3 STAMP=955971980
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/alfamal/index1 RECID=4 STAMP=955971980

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=955971980 file name=/u01/app/oracle/oradata/alfamal/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=955971980 file name=/u01/app/oracle/oradata/alfamal/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=955971980 file name=/u01/app/oracle/oradata/alfamal/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=955971980 file name=/u01/app/oracle/oradata/alfamal/index1
Reenabling controlfile options for auxiliary database
Executing: alter database force logging

contents of Memory Script:
{
   Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 29-SEP-17

RMAN> 

15. Test the duplicated database.

[oracle@alfa ~]$ sqlplus /  as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 29 17:17:52 2017
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select status from v$instance;
STATUS
------------
OPEN

SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/alfamal/control01.ctl
/u01/app/oracle/fast_recovery_area/alfamal/control02.ctl

SQL> select member from  v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/alfamal/redo03.log
/u01/app/oracle/oradata/alfamal/redo02.log
/u01/app/oracle/oradata/alfamal/redo01.log

SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/alfamal/system01.dbf
/u01/app/oracle/oradata/alfamal/sysaux01.dbf
/u01/app/oracle/oradata/alfamal/undotbs01.dbf
/u01/app/oracle/oradata/alfamal/users01.dbf
/u01/app/oracle/oradata/alfamal/index1

No comments:

Post a Comment