Cloning Oracle ASM Database with KFED

There could be a requirement to create frequent clone of the databases for doing some kind of testing. There are multiple options for cloning, for example: use physical backup, logical backup (conventional export or datapump), CTAS (create table as select).

Let’s say the database size we need to clone is 20G. All these options will serve the purpose, but will take good amount of time. So another option is to duplicate the database at the storage level, which is much faster than these earlier mentioned approaches. We can use utilities provided by storage vendors example: EMC SnapView and RecoverPoint or NetApp SnapManager.

In an environment, where we have ASM as primary storage for databases, we can use Oracle provided utility ‘kfed’ to clone the database. I’ve tried this approach and it works well for creating test & QA databases.

I’ve used 2 LUN’s to demonstrate this approach.  First LUN for source database and second LUN for target.

LUN 1 – /dev/rdsk/c4t50060E800564F774d41s6
LUN 2 – /dev/rdsk/c4t50060E800564F774d30s6 

STEP 1 – Create a external DG on the first LUN
==================================
SQL> create diskgroup ktest external redundancy disk  ‘/dev/rdsk/c4t50060e800564f774d41s6’
/

STEP 2 – Create source database on DG
============================
-bash-3.00$ dbca -silent -createDatabase -templateName mytemplate.dbc -gdbName DB708 -sid DB708  -SysPassword oracle -SystemPassword oracle -emConfiguration NONE -storageType ASM -asmSysPassword oracle -diskGroupName KTEST  -recoveryGroupName  KTEST
Copying database files
1% complete
3% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
77% complete
88% complete
100% complete
Look at the log file “/oracle/cfgtoollogs/dbca/DB708/DB708.log” for further details.

STEP 3 – Shutdown the source database
============================
This step will make sure that the database is in consistent stage and we don’t need to do any kind of recovery.
-bash-3.00$ export ORACLE_SID=DB708
-bash-3.00$ /oracle/ora11/bin/sqlplus ‘/ as sysdba’

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Jun 11 19:02:06 2010

Copyright (c) 1982, 2008, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown normal
Database closed.
Database dismounted.
ORACLE instance shut down.

STEP 4 – Copy the ASM disk header from the source LUN
=========================================

This will create a text file with header information

-bash-3.00$ kfed read /dev/rdsk/c4t50060E800564F774d41s6 > header_41

STEP 5 – Duplicate the disk using OS dd command
====================================

bash-3.00# dd if=/dev/rdsk/c4t50060E800564F774d41s6 of=/dev/rdsk/c4t50060E800564F774d30s6 bs=1024k
10226+1 records in
10226+1 records out

STEP 6 – Change the ASM header dump file
===============================

In our case ASM header dump file is  header_41.

Change following entries to required diskgroup name

kfdhdb.grpname:                   XTEST ; 0x048: length=5

STEP 7 – Replace the ASM header of taget LUN
==================================

-bash-3.00$ kfed merge /dev/rdsk/c4t50060E800564F774d30s6  text=header_41

STEP 8 – Check the ASM header of taget LUN
==================================

-bash-3.00$ kfed read  /dev/rdsk/c4t50060E800564F774d30s6  | more
kfbh.endian:                          0 ; 0x000: 0x00
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj:              2147483648 ; 0x008: TYPE=0x8 NUMB=0x0
kfbh.check:                   697920340 ; 0x00c: 0x29996b54
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:         ORCLDISK ; 0x000: length=8
kfdhdb.driver.reserved[0]:            0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]:            0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                168820736 ; 0x020: 0x0a100000
kfdhdb.dsknum:                        0 ; 0x024: 0x0000
kfdhdb.grptyp:                        1 ; 0x026: KFDGTP_EXTERNAL
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname:              KTEST_0000 ; 0x028: length=10
kfdhdb.grpname:                   XTEST ; 0x048: length=5
kfdhdb.fgname:               KTEST_0000 ; 0x068: length=10

STEP 9 – Check if ASM can read the LUN header
===================================
SQL>select name, state,total_mb, free_mb  from v$asm_diskgroup
/

NAME                           STATE         TOTAL_MB    FREE_MB
—————————— ———– ———- ———-
KTEST                          MOUNTED          10226       8489
XTEST                          DISMOUNTED           0          0
This output shows that 2 DG’s are created, one of them is not online though.

STEP 10 – Mount ASM diskgroup
========================

SQL> alter diskgroup XTEST mount
/

Diskgroup altered.
SQL>select name, state,total_mb, free_mb  from v$asm_diskgroup
/

NAME                           STATE         TOTAL_MB    FREE_MB
—————————— ———– ———- ———-
KTEST                          MOUNTED          10226       8489
XTEST                          MOUNTED          10226       8489

STEP 11 – Verify the DG contents using asmcmd
==================================

-bash-3.00$ asmcmd -p
ASMCMD [+] > ls -al
State    Type    Rebal  Name
MOUNTED  EXTERN  N      KTEST/
MOUNTED  EXTERN  N      XTEST/

ASMCMD [+] > cd xtest

ASMCMD [+xtest] > ls -al
Type  Redund  Striped  Time             Sys  Name
                                        Y    DB708/
ASMCMD [+xtest] > cd DB708
ASMCMD [+xtest/DB708] > ls -al
Type           Redund  Striped  Time             Sys  Name
                                                 Y    CONTROLFILE/
                                                 Y    DATAFILE/
                                                 Y    ONLINELOG/
                                                 Y    PARAMETERFILE/
                                                 Y    TEMPFILE/
                                                 N    spfileDB708.ora => +XTEST/DB708/PARAMETERFILE/spfile.269.721421619
ASMCMD [+xtest/DB708] > cd DATAFILE

ASMCMD [+xtest/DB708/DATAFILE] > ls -al
Type      Redund  Striped  Time             Sys  Name
DATAFILE  UNPROT  COARSE   JUN 11 19:00:00  Y    none => SYSAUX.257.721421117
DATAFILE  UNPROT  COARSE   JUN 11 19:00:00  Y    none => SYSTEM.256.721421117
DATAFILE  UNPROT  COARSE   JUN 11 19:00:00  Y    none => UNDOTBS1.258.721421117
DATAFILE  UNPROT  COARSE   JUN 11 19:00:00  Y    none => USERS.259.721421117

STEP 12 – Replace the changes in  pfile
===========================

Replace KTEST to XTEST in pfile
DB708.__db_cache_size=419430400
DB708.__java_pool_size=16777216
DB708.__large_pool_size=16777216
DB708.__oracle_base=’/oracle’#ORACLE_BASE set from environment
DB708.__pga_aggregate_target=520093696
DB708.__sga_target=754974720
DB708.__shared_io_pool_size=0
DB708.__shared_pool_size=251658240
DB708.__streams_pool_size=0
*.audit_file_dest=’/oracle/admin/DB708/adump’
*.audit_trail=’db’
*.compatible=’11.1.0.0.0′
*.control_files=’+XTEST/db708/controlfile/current.261.721421369′,’+XTEST/db708/controlfile/current.260.721421369′
*.db_block_size=8192
*.db_create_file_dest=’+XTEST’
*.db_domain=”
*.db_name=’DB708′
*.db_recovery_file_dest=’+XTEST’
*.db_recovery_file_dest_size=2147483648
*.diagnostic_dest=’/oracle’
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DB708XDB)’
*.log_archive_format=’%t_%s_%r.dbf’
*.memory_target=1267728384
*.open_cursors=300
*.parallel_max_servers=0
*.parallel_min_servers=0
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.undo_tablespace=’UNDOTBS1′
SQL> startup mount
ORACLE instance started.

Total System Global Area 1269743616 bytes
Fixed Size                  2102128 bytes
Variable Size             805309584 bytes
Database Buffers          419430400 bytes
Redo Buffers               42901504 bytes
Database mounted.

SQL> select name from v$datafile union  select name from v$tempfile
/

NAME
——————————————————————————–
+KTEST/db708/datafile/system.256.721421117
+KTEST/db708/datafile/sysaux.257.721421117
+KTEST/db708/datafile/undotbs1.258.721421117
+KTEST/db708/datafile/users.259.721421117
+KTEST/db708/tempfile/temp.268.721421429

SQL> select member from v$logfile
/

MEMBER
——————————————————————————–
+KTEST/db708/onlinelog/group_3.266.721421373
+KTEST/db708/onlinelog/group_3.267.721421373
+KTEST/db708/onlinelog/group_2.264.721421371
+KTEST/db708/onlinelog/group_2.265.721421373
+KTEST/db708/onlinelog/group_1.262.721421371
+KTEST/db708/onlinelog/group_1.263.721421371

STEP 13 – Rename the data files  & open the database
======================================

SQL>alter database rename file ‘+KTEST/db708/datafile/system.256.721421117’ to ‘+XTEST/db708/datafile/system.256.721421117’
/

SQL>alter database rename file ‘+KTEST/db708/datafile/sysaux.257.721421117’ to ‘+XTEST/db708/datafile/sysaux.257.721421117’
/

SQL>alter database rename file ‘+KTEST/db708/datafile/undotbs1.258.721421117’ to ‘+XTEST/db708/datafile/undotbs1.258.721421117’
/

SQL>alter database rename file ‘+KTEST/db708/datafile/users.259.721421117’ to ‘+XTEST/db708/datafile/users.259.721421117’
/

SQL>alter database rename file ‘+KTEST/db708/tempfile/temp.268.721421429’ to ‘+XTEST/db708/tempfile/temp.268.721421429’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_3.266.721421373’ to ‘+XTEST/db708/onlinelog/group_3.266.721421373’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_3.267.721421373’ to ‘+XTEST/db708/onlinelog/group_3.267.721421373’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_2.264.721421371’ to ‘+XTEST/db708/onlinelog/group_2.264.721421371’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_2.265.721421373’ to ‘+XTEST/db708/onlinelog/group_2.265.721421373’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_1.262.721421371’ to ‘+XTEST/db708/onlinelog/group_1.262.721421371’
/

SQL>alter database rename file ‘+KTEST/db708/onlinelog/group_1.263.721421371’ to  ‘+XTEST/db708/onlinelog/group_1.263.721421371′
/
SQL> alter database open
/

Database altered.

STEP 14 – Validate physical corruption using RMAN
=====================================

-bash-3.00$ rman target /

Recovery Manager: Release 11.1.0.7.0 – Production on Fri Jun 11 19:55:57 2010

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

connected to target database: DB708 (DBID=2745746232)

RMAN> validate database;

Starting validate at 11-JUN-10
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=124 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00001 name=+XTEST/db708/datafile/system.256.721421117
input datafile file number=00002 name=+XTEST/db708/datafile/sysaux.257.721421117
input datafile file number=00003 name=+XTEST/db708/datafile/undotbs1.258.721421117
input datafile file number=00004 name=+XTEST/db708/datafile/users.259.721421117
channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
1    OK     0              12254        90880           800369
  File Name: +XTEST/db708/datafile/system.256.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              63809
  Index      0              11360
  Other      0              3457

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
2    OK     0              26749        70400           800369
  File Name: +XTEST/db708/datafile/sysaux.257.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              8285
  Index      0              7774
  Other      0              27592

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
3    OK     0              59           3200            800369
  File Name: +XTEST/db708/datafile/undotbs1.258.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              0
  Index      0              0
  Other      0              3141

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
4    OK     0              478          640             779064
  File Name: +XTEST/db708/datafile/users.259.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              15
  Index      0              2
  Other      0              145

channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
including current control file for validation
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type    Status Blocks Failing Blocks Examined
———— —— ————– —————
Control File OK     0              594
Finished validate at 11-JUN-10

STEP 15 – Validate logical corruption using RMAN
====================================
RMAN> validate check logical database;

Starting validate at 11-JUN-10
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00001 name=+XTEST/db708/datafile/system.256.721421117
input datafile file number=00002 name=+XTEST/db708/datafile/sysaux.257.721421117
input datafile file number=00003 name=+XTEST/db708/datafile/undotbs1.258.721421117
input datafile file number=00004 name=+XTEST/db708/datafile/users.259.721421117
channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
1    OK     0              12254        90880           800369
  File Name: +XTEST/db708/datafile/system.256.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              63809
  Index      0              11360
  Other      0              3457

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
2    OK     0              26749        70400           800369
  File Name: +XTEST/db708/datafile/sysaux.257.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              8285
  Index      0              7774
  Other      0              27592

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
3    OK     0              59           3200            800369
  File Name: +XTEST/db708/datafile/undotbs1.258.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              0
  Index      0              0
  Other      0              3141

File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
—- —— ————– ———— ————— ———-
4    OK     0              478          640             779064
  File Name: +XTEST/db708/datafile/users.259.721421117
  Block Type Blocks Failing Blocks Processed
  ———- ————– —————-
  Data       0              15
  Index      0              2
  Other      0              145

channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
including current control file for validation
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Control File and SPFILE
===============================
File Type    Status Blocks Failing Blocks Examined
———— —— ————– —————
Control File OK     0              594
Finished validate at 11-JUN-10

STEP 16 – Rename the database using nid
==============================
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1269743616 bytes
Fixed Size                  2102128 bytes
Variable Size             805309584 bytes
Database Buffers          419430400 bytes
Redo Buffers               42901504 bytes
Database mounted.
-bash-3.00$ nid TARGET=sys/password DBNAME=CLONE1

DBNEWID: Release 11.1.0.7.0 – Production on Fri Jun 11 20:03:28 2010

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

Connected to database DB708 (DBID=2745746232)

Connected to server version 11.1.0

Control Files in database:
    +XTEST/db708/controlfile/current.261.721421369
    +XTEST/db708/controlfile/current.260.721421369

Change database ID and database name DB708 to CLONE1? (Y/[N]) => Y

Proceeding with operation
Changing database ID from 2745746232 to 3251328720
Changing database name from DB708 to CLONE1
    Control File +XTEST/db708/controlfile/current.261.721421369 – modified
    Control File +XTEST/db708/controlfile/current.260.721421369 – modified
    Datafile +XTEST/db708/datafile/system.256.72142111 – dbid changed, wrote new name
    Datafile +XTEST/db708/datafile/sysaux.257.72142111 – dbid changed, wrote new name
    Datafile +XTEST/db708/datafile/undotbs1.258.72142111 – dbid changed, wrote new name
    Datafile +XTEST/db708/datafile/users.259.72142111 – dbid changed, wrote new name
    Datafile +XTEST/db708/tempfile/temp.268.72142142 – dbid changed, wrote new name
    Control File +XTEST/db708/controlfile/current.261.721421369 – dbid changed, wrote new name
    Control File +XTEST/db708/controlfile/current.260.721421369 – dbid changed, wrote new name
    Instance shut down

Database name changed to CLONE1.
Modify parameter file and generate a new password file before restarting.
Database ID for database CLONE1 changed to 3251328720.
All previous backups and archived redo logs for this database are unusable.
Database is not aware of previous backups and archived logs in Recovery Area.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID – Completed succesfully.

STEP 17 – Change the parameter file to reflect the name of the new database
======================================================

CLONE1.__db_cache_size=419430400
CLONE1.__java_pool_size=16777216
CLONE1.__large_pool_size=16777216
CLONE1.__oracle_base=’/oracle’#ORACLE_BASE set from environment
CLONE1.__pga_aggregate_target=520093696
CLONE1.__sga_target=754974720
CLONE1.__shared_io_pool_size=0
CLONE1.__shared_pool_size=251658240
CLONE1.__streams_pool_size=0
*.audit_file_dest=’/oracle/admin/CLONE1/adump’
*.audit_trail=’db’
*.compatible=’11.1.0.0.0′
*.control_files=’+XTEST/db708/controlfile/current.261.721421369′,’+XTEST/db708/controlfile/current.260.721421369′
*.db_block_size=8192
*.db_create_file_dest=’+XTEST’
*.db_domain=”
*.db_name=’CLONE1′
*.db_recovery_file_dest=’+XTEST’
*.db_recovery_file_dest_size=2147483648
*.diagnostic_dest=’/oracle’
*.dispatchers='(PROTOCOL=TCP) (SERVICE=CLONE1XDB)’
*.log_archive_format=’%t_%s_%r.dbf’
*.memory_target=1267728384
*.open_cursors=300
*.parallel_max_servers=0
*.parallel_min_servers=0
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.undo_tablespace=’UNDOTBS1′

STEP 18 – Create new password file
=========================

-bash-3.00$ orapwd file=orapwCLONE1 password=oracle entries=10 force=y

-bash-3.00$ ls -lrt | grep orapwCLONE1
-rw-r—–   1 ora11    oinstall    2560 Jun 11 20:11 orapwCLONE1

STEP 19 – Create required directories
===========================

for ex audit_file_dest=’/oracle/admin/CLONE1/adump’

mkdir -p /oracle/admin/CLONE1/adump

STEP 20 – Startup the database & open using resetlogs
=======================================
SQL> startup mount
ORACLE instance started.

Total System Global Area 1269743616 bytes
Fixed Size                  2102128 bytes
Variable Size             805309584 bytes
Database Buffers          419430400 bytes
Redo Buffers               42901504 bytes
Database mounted.
SQL> alter database open resetlogs
/

Database altered.

STEP 21 – Validate the database parameters
================================

SQL> show parameter name

NAME                                 TYPE        VALUE
———————————— ———– ——————————
db_file_name_convert                 string
db_name                              string      CLONE1
db_unique_name                       string      CLONE1
global_names                         boolean     FALSE
instance_name                        string      CLONE1
lock_name_space                      string
log_file_name_convert                string
service_names                        string      CLONE1

Advertisements
This entry was posted in Oracle Automatic Storage Management, Oracle Database Cloning and tagged . Bookmark the permalink.

6 Responses to Cloning Oracle ASM Database with KFED

  1. Jack Pettas says:

    This is a great post and may be one to be followed up to see what happens

    A mate e-mailed this link the other day and I am eagerly waiting your next blog post. Continue on the quality work.

  2. anil says:

    Hi,

    You post is great .

    Pl. keep posting more such stuff.

    thanks
    anil

  3. santosh loke says:

    very good!

  4. Raps says:

    Could please let me know in which step you created XTEST diskgroup ? If it is before running kfed command , then how did you create the XTEST disk group ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s