Oracle Database 12c New Features

Showing posts with label clone PDB. Show all posts
Showing posts with label clone PDB. Show all posts

Create PDB from existing PDB (Clone PDB)

1. Connect to CDB as root

[oracle@ora12cn1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Sun Dec 1 19:12:07 2013

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL>

2. Make the source pluggable database READ ONLY Mode.

SQL> alter pluggable database pdb3 close;

Pluggable database altered.

SQL> alter pluggable database pdb3 open read only;

Pluggable database altered.

3. Create the directory for the clone datafiles.

[grid@ora12cn1 ~]$ asmcmd
ASMCMD> pwd
+
ASMCMD> cd DATA
ASMCMD> ls
ASM/
ORA12C/
ora12c-scan/
orapwasm
pdb$seed_sysaux01.dbf
pdb$seed_system01.dbf
pdb2/
pdb3/
pdbseed_temp01.dbf
ASMCMD> mkdir pdb3_clone
ASMCMD>

4. Identify the data files and the temp files of the sources, to learn the directory structure

SQL> select file_name from cdb_pdbs p, cdb_data_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3';

FILE_NAME
----------------------------------------
+DATA/pdb3/system01.dbf
+DATA/pdb3/sysaux01.dbf

SQL> select file_name from cdb_pdbs p, cdb_temp_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3';

FILE_NAME
----------------------------------------
+DATA/pdb3/temp01.dbf

SQL>

5. Issue CREATE PLUGGABLE DATABASE command

SQL> CREATE PLUGGABLE DATABASE pdb3_clone FROM pdb3
  2  FILE_NAME_CONVERT=('+DATA/pdb3', '+DATA/pdb3_clone')
  3  PATH_PREFIX = '+DATA/pdb3_clone';

Pluggable database created.

SQL>

6. Check the result

SQL> alter pluggable database pdb3_clone open;

Pluggable database altered.

SQL>

SQL> select file_name from cdb_pdbs p, cdb_data_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3_CLONE';

FILE_NAME
----------------------------------------
+DATA/pdb3_clone/system01.dbf
+DATA/pdb3_clone/sysaux01.dbf

SQL> select file_name from cdb_pdbs p, cdb_temp_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3_CLONE';

FILE_NAME
----------------------------------------
+DATA/pdb3_clone/temp01.dbf

SQL>!
[grid@ora12cn2 ~]$ lsnrctl services
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 01-DEC-2013 20:42:34
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "ora12c" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "ora12cXDB" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: ora12cn2, pid: 3475>
         (ADDRESS=(PROTOCOL=tcp)(HOST=ora12cn2.localdomain)(PORT=50151))
Service "pdb2" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "pdb3" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "pdb3_clone" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
The command completed successfully 

7. Add connection string to $ORACLE_HOME/network/admin/tnsnames.ora or $GRID_HOME/network/admin/tnsnames.ora

PDB3_CLONE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c-scan)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pdb3_clone)
    )
  )

Create PDB from existing PDB (Clone PDB)

1. Connect to CDB as root

[oracle@ora12cn1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.1.0 Production on Sun Dec 1 19:12:07 2013

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL>

2. Make the source pluggable database READ ONLY Mode.

SQL> alter pluggable database pdb3 close;

Pluggable database altered.

SQL> alter pluggable database pdb3 open read only;

Pluggable database altered.

3. Create the directory for the clone datafiles.

[grid@ora12cn1 ~]$ asmcmd
ASMCMD> pwd
+
ASMCMD> cd DATA
ASMCMD> ls
ASM/
ORA12C/
ora12c-scan/
orapwasm
pdb$seed_sysaux01.dbf
pdb$seed_system01.dbf
pdb2/
pdb3/
pdbseed_temp01.dbf
ASMCMD> mkdir pdb3_clone
ASMCMD>

4. Identify the data files and the temp files of the sources, to learn the directory structure

SQL> select file_name from cdb_pdbs p, cdb_data_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3';

FILE_NAME
----------------------------------------
+DATA/pdb3/system01.dbf
+DATA/pdb3/sysaux01.dbf

SQL> select file_name from cdb_pdbs p, cdb_temp_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3';

FILE_NAME
----------------------------------------
+DATA/pdb3/temp01.dbf

SQL>

5. Issue CREATE PLUGGABLE DATABASE command

SQL> CREATE PLUGGABLE DATABASE pdb3_clone FROM pdb3
  2  FILE_NAME_CONVERT=('+DATA/pdb3', '+DATA/pdb3_clone')
  3  PATH_PREFIX = '+DATA/pdb3_clone';

Pluggable database created.

SQL>

6. Check the result

SQL> alter pluggable database pdb3_clone open;

Pluggable database altered.

SQL>

SQL> select file_name from cdb_pdbs p, cdb_data_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3_CLONE';

FILE_NAME
----------------------------------------
+DATA/pdb3_clone/system01.dbf
+DATA/pdb3_clone/sysaux01.dbf

SQL> select file_name from cdb_pdbs p, cdb_temp_files f
  2  where p.pdb_id=f.con_id
  3  and p.pdb_name = 'PDB3_CLONE';

FILE_NAME
----------------------------------------
+DATA/pdb3_clone/temp01.dbf

SQL>!
[grid@ora12cn2 ~]$ lsnrctl services
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 01-DEC-2013 20:42:34
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
Services Summary...
Service "+ASM" has 1 instance(s).
  Instance "+ASM2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "ora12c" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "ora12cXDB" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "D000" established:0 refused:0 current:0 max:1022 state:ready
         DISPATCHER <machine: ora12cn2, pid: 3475>
         (ADDRESS=(PROTOCOL=tcp)(HOST=ora12cn2.localdomain)(PORT=50151))
Service "pdb2" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "pdb3" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
Service "pdb3_clone" has 1 instance(s).
  Instance "ora12c2", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:0 refused:0 state:ready
         LOCAL SERVER
The command completed successfully 

7. Add connection string to $ORACLE_HOME/network/admin/tnsnames.ora or $GRID_HOME/network/admin/tnsnames.ora

PDB3_CLONE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora12c-scan)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pdb3_clone)
    )
  )