0% found this document useful (0 votes)
22 views40 pages

UKOUG_JulianFrey_Database_cloning_in_a_Multitenant_environment

The document discusses database cloning in a multitenant environment, focusing on methods for cloning databases both before and after Oracle 12c. It outlines various techniques such as RMAN duplicate, Data Pump, and snapshot copies, along with their specific requirements and procedures. Additionally, it highlights the differences in cloning capabilities between versions and the use of pluggable databases (PDBs) in the cloning process.

Uploaded by

shuvo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views40 pages

UKOUG_JulianFrey_Database_cloning_in_a_Multitenant_environment

The document discusses database cloning in a multitenant environment, focusing on methods for cloning databases both before and after Oracle 12c. It outlines various techniques such as RMAN duplicate, Data Pump, and snapshot copies, along with their specific requirements and procedures. Additionally, it highlights the differences in cloning capabilities between versions and the use of pluggable databases (PDBs) in the cloning process.

Uploaded by

shuvo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Database cloning in a

Multitenant environment
UKOUG 2019
Julian Frey
Julian Frey
Oracle Database Consultant

[email protected]
https://database.edorex.ch
https://www.julianfrey.ch
@JulianFreyCH
Agenda
• Why cloning
• Cloning < 12c
• Cloning >= 12c

http://lego-galactica.blogspot.com/2009/09/star-wars-clone-army-to-invade-earth.html
Why cloning
• Integration Tests

• Application Tests

• Performance Tests

• BUG Reproduction/Analysis

• Application Development

• Database Upgrade Tests


Different requirements

Only Data Modify Data

Only Metadata Modify and Partial Data

Partial Data
Full Copy

Refreshable
More Data
Cloning < 12c

• Copy on Write Technologie


• clonedb/clone.pl
• RMAN duplicate
• Datapump
• Goldengate
• DB Links
• 3rt Party Tools
Cloning < 12c (RMAN Duplicate)
rman> DUPLICATE TARGET DATABASE TO CLONE
UNTIL TIME «TO_DATE(‘2019-11-14 18:00:00’,’YYYY-MM-DD HH24:MI:SS’)»
SPFILE
SET db_name=‘CLONE’
SET db_file_name_convert=‘/u02/oradata/target/’,’/u02/oradata/clone’
BACKUP LOCATION ‘/backup/target’
NOFILENAMECHECK;

rman> DUPLICATE DATABASE TO CLONE


FROM ACTIVE DATABASE
SPFILE
NOFILENAMECHECK;
Cloning < 12 (COW)
• Oracle 11g Release 2
• Copy on Write Technologie
• clonedb/clone.pl
Cloning < 12c (Cold Duplicate)
1. Database in Archivelog Mode
2. SQL> ALTER DATABASE BEGIN BACKUP;

3. Snapshot on Storage
4. SQL> ALTER DATABASE END BACKUP;

5. Recover Database
6. Open Database
Cloning < 12c (Datapump)
1. Export Database
2. oracle@dbsv01: expdp system/manager@TDB01 \
FULL=YES\
FLASHBACK_TIME=systimestamp \
DIRECTORY=CLONE_DIR \
LOGFILE=LOG_DIR:export_full_14.11.19.log

3. Import and (Cleanup or TABLE_EXISTS_ACTION) – Many more options


4. oracle@dbsv02: impdp system/manager@TDB02 \
SCHEMAS=APP_SCHEMA \
DIRECTORY=CLONE_DIR \
TABLE_EXISTS_ACTION=REPLACE \
LOGFILE=LOG_DIR:import_APP_SCHEMA_21.02.19.log
Cloning >= 12c
• NON-CDB Architecture no new Features
• >=19c three PDBs are allowed without Multitenant Licence
• PDB Architecture:
• All <12c features are working (RMAN, Cold Backup, COW, Datapump)
• Cold Backup different
• Create pluggable database …
• Refreshable copy
• PDB Snapshot Copy
• PDB Snapshot Carousel
RMAN Duplicate of PDBs
• Subject to certain restrictions on clauses
• NORESUME
DB_FILE_NAME_CONVERT
• SECTION_SIZE
• USING COMPRESSED BACKUP Set
• Some further restrictions to the duplicate
• Only cloning to Primary Databases
• Only full PDB clones are supported
• Only PDB -> PDB and not CDB -> PDB cloning is supported
• TDE encrypted PDBs are not supported
RMAN Duplicate
RMAN> CONNECT TARGET sys/<PWD>@TARGET_CDB
RMAN> CONNECT AUXILIARY sys/<PWD>@AUX_CDB
RMAN> DUPLICATE PLUGGABLE DATABASE <SOURCE_PDB> AS <TARGET_PDB_NAME>
TO <AUX_CDB> FROM ACTIVE DATABASE ;
Starting Duplicate PDB at 12.11.2019 18:09:37
using channel ORA_AUX_DISK_1
current log archived
duplicating Online logs to Oracle Managed File (OMF) location
duplicating Datafiles to Oracle Managed File (OMF) location
.
.
.
Performing import of metadata...
Finished Duplicate PDB at 12.11.2019 18:10:07
RMAN>
Cloning >= 12c (Cold Backup/Snapshot) (1)
• “Open Source PDB read only”
• Use dbms_pdb.describe to create the xml file
• Copy Datafiles (e.g. Filesystem Snapshot) to new location
• Edit XML File to new Name and new Location
• Create pluggable database with using clause
Cloning >= 12c (Cold Backup/Snapshot) (2)
SQL> alter pluggable database begin backup;

Pluggable database altered.

SQL> exec dbms_pdb.describe('/home/oracle/pdbsrc.xml','PDBSRC');

PL/SQL procedure successfully completed.

SQL> host cp –rp /u02/oradata/TDB01/pdbsrc /u02/oradata/TDB01/pdbtgt

SQL> alter pluggable database end backup;

Pluggable database altered.


Cloning >= 12c (Cold Backup/Snapshot) (3)
SQL> host sed 's/PDBSRC/PDBTGT/g; s/pdbsrc/pdbtgt/g' pdbsrc.xml > pdbtgt.xml
SQL> CREATE PLUGGABLE DATABASE PDBTGT
AS CLONE USING '/home/oracle/pdbtgt.xml' NOCOPY
TEMPFILE REUSE;
CREATE PLUGGABLE DATABASE PDBTGT
*
ERROR at line 1:
ORA-65368: unable to open the pluggable database due to errors during recovery
ORA-65089: pluggable database is not clean
ORA-01113: file 41 needs media recovery
ORA-01110: data file 41: '/u02/oradata/TDB01/pdbtgt/undotbs01.dbf'
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBSRC READ WRITE NO
5 PDBTGT MOUNTED
Cloning >= 12c (Cold Backup/Snapshot) (4)
[email protected]:~/ [TDB01] rman target /

connected to target database: TDB01 (DBID=2948586735)


RMAN> recover pluggable database PDBTGT;
Starting recover at 18.02.2019 21:10:12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=142 device type=DISK
datafile 40 not processed because file is offline
datafile 41 not processed because file is offline
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 26.10.2019 21:10:14
RMAN>
Cloning >= 12c (Cold Backup/Snapshot) (5)
SQL> alter pluggable database PDBTGT open;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBSRC READ WRITE NO
5 PDBTGT READ WRITE NO
Cloning >= 12c (Cold Backup/Snapshot)
without errors
• Create temporary pluggable database from source
• Open pluggable database read only
• Use dbms_pdb.describe to create the xml file
• Copy datafiles of temporary pluggable database to a new directory
• Edit XML File to the location of the copied datafiles
• Create pluggable database as clone using xml
• 19c without multitenant option possible
• With Snapshots the temporary copy can not be droped
Create pluggable database
• PDB creation is ALWAYS a clone (without source it is PDB$SEED)
• Many options are available
Create pluggable database from SEED
Create pluggable database from SEED
SQL> CREATE PLUGGABLE DATABASE UKOUG_SRC ADMIN USER PDB_ADMIN
IDENTIFIED BY WECOME1;

Pluggable database created.


Elapsed: 00:00:15.74
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 UKOUG_SRC MOUNTED NO
SQL> alter pluggable database UKOUG_src open;

Pluggable database altered.


Elapsed: 00:00:02.90
Create pluggable database: PDB Clone
• Source PDB must not be closed
• The User which issues the clone must have the create Pluggable Database privilege
• If the source is in NON Archivelog MODE it must be in READ ONLY MODE
• Many Options for the clone:
• Storage clause
• NO DATA clause
• Service name convert clause
• Standby clause
• Parallel clause
• and more…
Create pluggable database: PDB Clone
SQL> create pluggable database pdbtgt5 from pdbsrc;

Pluggable database created.

SQL> select PDB_NAME,CLONED_FROM_PDB_NAME,OPERATION from


DBA_PDB_HISTORY;

PDB_NAME CLONED_FROM_PDB_NAME OPERATION


--------------------- ------------------------- ----------
PDBTGT5 PDBSRC CLONE
Alertlog of PDB Clone
2019-11-05T18:07:54.752225+01:00
CREATE PLUGGABLE DATABASE UKOUG_SRC ADMIN USER PDB_ADMIN IDENTIFIED BY *
2019-11-05T18:07:55.596525+01:00
PDB$SEED(2): AUDSYS.AUD$UNIFIED (SQL_TEXT) - CLOB populated
2019-11-05T18:08:09.639504+01:00
UKOUG_SRC(3):Endian type of dictionary set to little
****************************************************************
Pluggable Database UKOUG_SRC with pdb id - 3 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
local undo-1, localundoscn-0x00000000000000f0
****************************************************************
UKOUG_SRC(3):Autotune of undo retention is turned on.
UKOUG_SRC(3):Undo initialization recovery: err:0 start: 176142 end: 176144 diff: 2 ms (0.0
seconds)
UKOUG_SRC(3):[3875] Successfully onlined Undo Tablespace 2.
UKOUG_SRC(3):Undo initialization online undo segments: err:0 start: 176144 end: 176171
diff: 27 ms (0.0 seconds)
UKOUG_SRC(3):Undo initialization finished serial:0 start:176142 end:176173 diff:31 ms (0.0
seconds)
UKOUG_SRC(3):Database Characterset for UKOUG_SRC is AL32UTF8
UKOUG_SRC(3):JIT: pid 3875 requesting stop
UKOUG_SRC(3):Buffer Cache flush started: 3
UKOUG_SRC(3):Buffer Cache flush finished: 3
Completed: CREATE PLUGGABLE DATABASE UKOUG_SRC ADMIN USER PDB_ADMIN IDENTIFIED BY *
Alertlog of PDB OPEN
2019-11-05T18:09:57.330887+01:00
alter pluggable database UKOUG_src open
UKOUG_SRC(3):Autotune of undo retention is turned on.
2019-11-05T18:09:57.624027+01:00
UKOUG_SRC(3):Endian type of dictionary set to little
UKOUG_SRC(3):Undo initialization recovery: err:0 start: 283674 end: 283677 diff: 3 ms (0.0 seconds)
UKOUG_SRC(3):[3875] Successfully onlined Undo Tablespace 2.
UKOUG_SRC(3):Undo initialization online undo segments: err:0 start: 283677 end: 283757 diff: 80 ms (0.1
seconds)
UKOUG_SRC(3):Undo initialization finished serial:0 start:283674 end:283761 diff:87 ms (0.1 seconds)
UKOUG_SRC(3):Deleting old file#2 from file$
UKOUG_SRC(3):Deleting old file#4 from file$
UKOUG_SRC(3):Deleting old file#6 from file$
UKOUG_SRC(3):Adding new file#20 to file$(old file#2). fopr-1, newblks-26880, oldblks-26880
UKOUG_SRC(3):Adding new file#21 to file$(old file#4). fopr-1, newblks-21120, oldblks-21120
UKOUG_SRC(3):Adding new file#22 to file$(old file#6). fopr-1, newblks-28160, oldblks-7680
UKOUG_SRC(3):Successfully created internal service UKOUG_SRC at open
****************************************************************
Post plug operations are now complete.
Pluggable database UKOUG_SRC with pdb id - 3 is now marked as NEW.
****************************************************************
UKOUG_SRC(3):Database Characterset for UKOUG_SRC is AL32UTF8
2019-11-05T18:10:00.028335+01:00
UKOUG_SRC(3):Opening pdb with no Resource Manager plan active
UKOUG_SRC(3):joxcsys_required_dirobj_exists: directory object exists with required path
/u01/app/oracle/product/19.3/dbhome_1/javavm/admin/, pid 3875 cid 3
Pluggable database UKOUG_SRC opened read write
Completed: alter pluggable database UKOUG_src open
Create pluggable database from source
snapshot copy
SQL> create pluggable database pdbtgt from pdbsrc create_file_dest=‘…'
snapshot copy;
SQL> select PDB_NAME,PDB_GUID,CLONED_FROM_PDB_NAME,OPERATION from
DBA_PDB_HISTORY;

PDB_NAME PDB_GUID CLONED_FROM_PDB OPERATION


--------------- -------------------------------- --------------- ---------
-
PDBSRC 82032F209B8408E1E053390AA8C06D48 PDB$SEED CREATE
PDBTGT 82308565C2D60566E053390AA8C01C6F PDBSRC CLONE

SQL> host du -sh …/*


164G ./pdbsrc
8.6G ./pdbtgt
Create pluggable database from snapshot
• Exadata/ODA/OCI feature
• Not equal to snapshot copy command
• Create Snapshots of PDB (19c allows sparse copies)
• Creates a temporary pluggable database
• Oracle unplugs the temporary pluggable database into xml
• The temporary pluggable database will be dropped
• Oracle Creates a ZIP File containing all datafiles and the xml file
Content of DB Snapshot
SQL> ALTER PLUGGABLE DATABASE SNAPSHOT UKOUG;
SQL> SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------

8 SNAP_844695344_1000800203 MOUNTED

SQL> host unzip -l snap_844695344_3023917.pdb
Archive: snap_844695344_3023917.pdb
Length Date Time Name
--------- ---------- ----- ----
304087040 02-20-2019 08:03 o1_mf_system_g6wm9w1z_.dbf
393216000 02-20-2019 08:03 o1_mf_sysaux_g6wm9w20_.dbf
424673280 02-20-2019 08:03 o1_mf_undotbs1_g6wm9w21_.dbf
7063 02-20-2019 08:04
/u02/oradata/TDB01/snap_844695344_3023917.xml
--------- -------
1121983383 4 files
Create PDB from snapshot
SQL> CREATE PLUGGABLE DATABASE PDBUKOUG FROM pdbsrc USING SNAPSHOT
UKOUG;

Pluggable database created.

SQL>
Snapshot Carousel
Create pluggable database NO DATA
• Tablespaces will be created
• Tablespaces will be empty
• Tables will be empty
• All objects will be created
• Restrictions:
• Only possible PDB -> PDB
• No Clustered Tables
• No Advanced Queuing (AQ)
• No Index Oganized Tables
• No Abstract Data Type Colums
• Can be used to create a temporary Clone and unplug this clone
Create pluggable database NO DATA
SQL> CREATE PLUGGABLE DATABASE UKOUG_NO_DATA FROM UKOUG_SOURCE NO
DATA;

SQL> select con_id, name, open_mode, total_size/1e9 from v$pdbs;

CON_ID NAME OPEN_MODE TOTAL_SIZE/1E9


---------- ------------------------------ ---------- --------------
2 PDB$SEED READ ONLY .64487424
3 UKOUG_SOURCE READ WRITE 13.5266304
6 UKOUG_NO_DATA READ WRITE 3.22227405
Create pluggable database from DB_LINK
• Only same version is possible (19c -> 19c)
• Different RU is possible (example follows)
• DB Link must exist either to CDB or to PDB
• DB Link User must have some privileges
• Source and Target must have the same endian
• Target CDB must have at least the same features as the source CDB
• Source PDB must be open
• Archivelog Mode and local undo must be enabled on the source PDB
User and DB LINK creation
SRC:
SQL> alter session set container=UKOUG_SRC_DB_LINK;
Session altered.

SQL> create user clone_user identified by welcome1;


User created.

SQL> grant create session, create pluggable database to


clone_user;
Grant succeeded.

TGT:
SQL> CREATE DATABASE LINK clone_link connect to CLONE_USER
identified by welcome1 using 'CLONE_DB';
Create pluggable database from DB_LINK
SQL> CREATE PLUGGABLE DATABASE UKOUG_TGT_DB_LINK FROM
UKOUG_small@clone_link;

Pluggable database created.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE RESTRICTED


---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
4 UKOUG_TGT_DB_LINK MOUNTED

SQL> alter pluggable database UKOUG_tgt_db_link open;

Warning: PDB altered with errors.


Create pluggable database from DB_LINK
UKOUG_TGT_DB_LINK(4):***************************************************************
UKOUG_TGT_DB_LINK(4):WARNING: Pluggable Database UKOUG_TGT_DB_LINK with pdb id - 4 is
UKOUG_TGT_DB_LINK(4): altered with errors or warnings. Please look into
UKOUG_TGT_DB_LINK(4): PDB_PLUG_IN_VIOLATIONS view for more details.
UKOUG_TGT_DB_LINK(4):***************************************************************

SQL> SELECT MESSAGE FROM PDB_PLUG_IN_VIOLATIONS;


UKOUG_TGT_DB_LINK
SQL Patch
'19.5.0.0.0 Release_Update 1909091805' is installed in the CDB but '19.3.0.0.0
Release_Update 1904101227' is installed in the PDB
Conclusion requirements
DATAPUMP DATAPUMP

Only Data Modify Data

DATAPUMP, PDB CLONE DATAPUMP

Only Metadata Modify and Partial Data

DATAPUMP, PDB
DATAPUMP, (PDB CLONE)
CLONE,RMAN

Partial Data
Full Copy

PDB CLONE ???DATAPUMP???

Refreshable
More Data
PDB Clone in Dataguard environment

Be careful and TEST your case !


Questions?

You might also like