Friday, October 4, 2013

12c CLONE PDBS online

 In oracle release 12.1.0.1,  we can now clone PDBS on the same container. While this is really easy and good enough for most of the database, it  requires shutting down PDBs and opening in READ ONLY mode. So the question is, " what to do if we need to Clone a PDB, but do not want to shutdown the PDB ?"

The solution is simple and includes the following steps.

1) Duplicate the PDB in a container to a auxiliary CDB .
2) unplug the PDB from auxiliary CDB.
3) Plug-in the PDB with the CLONE MOVE or CLONE COPY clause to move/copy the PDB and change the name of the PDB at the same time.
4) You can now destroy the  auxiliary CDB .(optional)

Some detail steps below.

1) Duplicate the PDB in a container to a ancillary CDB .

   To make a Duplicate copy of a CDB with specific PDBs, the steps are similar to regular RMAN DUPLICATE clause, with the addition of PDB name lists. To duplicate the DB, the database NEED NOT be in archivelog mode.

 the steps include 
  a)  Edit listener.ora to add auxiliary CDB in SID_LIST_LISTENER.

       THis is a mandatory step even if you opt to use port 1521 and depend on dynamic registration.
       The reason is that RMAN command will first shutdown  and restart the auxiliary instance. 
       Note:  If the source container CDB1 in my case is not in SID_LIST_LISTENER, it is because CDB1 is automatically registered and RMAN will not restart it.

    LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = dup)
      (ORACLE_HOME = /u01/app/oracle/product/12.1.0/dbhome_1)
      (SID_NAME = dup)
    )
  )



 b) add entry in tnsnames.ora for source and auxiliary  CDBs.

     This again is a mandatory step as rman connects to the auxiliary db using the connect string after it shuts the db internally.

dup =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dup)(UR=A)
    )
  )

c) create a sample pfile for DUP database..
    connect to the source database CDB1 and create a editable pfile;
    sql> conn  / as sysdba
            create pfile='/tmp/initdup.ora' from spfile;

   edit and replace all CDB1 with DUP. also change the name for controlfile to avoid override errors.

 *.audit_file_dest='/u01/app/oracle/admin/dup/adump'
*.audit_trail='db'
*.compatible='12.1.0.0.0'
*.control_files='/u01/app/oracle/oradata/dup/controdup1.ctl','/u01/app/oracle/fast_recovery_area/dup/controdup2.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_files=800
*.db_name='dup'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4800m
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dup)'
*.enable_pluggable_database=true
*.memory_target=400m
*.open_cursors=300
*.processes=300
*.remote_login_passwordfile='EXCLUSIVE'
*.temp_undo_enabled=FALSE
*.undo_tablespace='UNDOTBS1'

 then move the edited file to $ORACLE_HOME/dbs directory.

 mv /tmp/initdup.ora $ORACLE_HOME/dbs/.

d)  Add password file for auxillary database/
     CD $ORACLE_HOME/dbs

     export ORACLE_SID=dup
     orapwd file=$ORACLE_HOME/orapwdup password=oracle entries=10

  
 d) connect to RMAN and run the DUPLICATE COMMAND.

  
  • To duplicate the PDB pdb1 from cdb1 to CDB cdb2, use the following command:
    DUPLICATE TARGET DATABASE TO cdb2 PLUGGABLE DATABASE pdb1;
    
  • To duplicate the PDBs pdb1pdb3, and pdb4 from database cdb1 to cdb2, use the following command:
    DUPLICATE TARGET DATABASE TO cdb2 PLUGGABLE DATABASE pdb1,pdb3,pdb4;
    

E.G.
 $>rman target sys@cdb1 AUXILIARY sys@dup

Recovery Manager: Release 12.1.0.1.0 - Production on Tue Oct 1 16:57:29 2013

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

target database Password:
connected to target database: CDB1 (DBID=792037445)
auxiliary database Password:
connected to auxiliary database: DUP (not mounted)


RMAN>

 run
{
SET NEWNAME FOR DATABASE TO '/u01/app/oracle/oradata/%U';
DUPLICATE TARGET DATABASE TO dup PLUGGABLE DATABASE PDB_1 FROM ACTIVE DATABASE NOFILENAMECHECK;

}
    

2) unplug the PDB.

  We can now unplug the PDB from the duplicate database .

  alter pluggable database pdb_1 unplug into '/u01/app/oracle/oradata/pdb_1.xml';

3) Plug-in the PDB with the CLONE MOVE  or CLONE COPY clause to move or copy the PDB and change the name of the PDB at the same time.
Now, this PDB can be plugged back to the original CDB.
This way you can clone PDBs without closing any PDBs. The original PDB  pdb1 can be online all the while. The clone of pdb1 is called pdb_1_dup.
SQL> create pluggable database pdb_1_dup
        AS CLONE using '/u01/app/oracle/oradata/pdb_1.xml'
        COPY
        FILE_NAME_CONVERT=('/u01/app/oracle/oradata/','/u01/app/oracle/oradata/cdb1/pdb_1_dup')
SQL> /

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                 OPEN MODE  RESTRICTED
---------- ------------------------------ ----------      ----------
     2       PDB$SEED                       READ ONLY          NO
     3       PDB1                               READ WRITE       NO
     4       PDB2                               MOUNTED
     5       PDB_2                             MOUNTED
     6       PDB_1                             READ WRITE        NO
     7       PDB_4                             MOUNTED
     8       PDB_3                             MOUNTED
     9       PDB_5                             MOUNTED
     10       PDB_1_DUP                    MOUNTED
SQL>
SQL> 

No comments:

Post a Comment

Feedback welcome