The techniques that you can use to create a PDB.
1.coping
a.copying files from the seed
b.cloning a pdb(locally,remotely(from a pdb or from a non-cdb)
2.plugging in
a.plugging in an unplugged pdb
b.plugging in a non-cdb as a pdb
一.Using the seed pdb to creating a pdb.
1.my database have to pdbs including:PDBEMREP and PDB$SEED
SYS@EMREP>select pdb_id,pdb_name,dbid,status from dba_pdbs; PDB_ID PDB_NAME DBID STATUS ---------- ---------------------------------------- ---------- ------------------ 3 PDBEMREP 3183988881 NORMAL 2 PDB$SEED 4121219803 NORMAL
2.In SQL*Plus, ensure that the current container is the root
SYS@EMREP>SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL; SYS_CONTEXT('USERENV','CON_NAME') ------------------------------------------------------------------- CDB$ROOT
3.Run the CREATE PLUGGABLE DATABASE statement, and specify a local administrator for the PDB. Specify other clauses when they are required.
a.create pdbs datafile directory mkdir -p /u02/oradata/pdbs/trsenpdb b.runing create pdb sql on root container. CREATE PLUGGABLE DATABASE trsenpdb ADMIN USER trsenadmin IDENTIFIED BY oracle STORAGE (MAXSIZE 2G MAX_SHARED_TEMP_SIZE 100M) DEFAULT TABLESPACE trsen DATAFILE '/u02/oradata/pdbs/trsenpdb/trsen01.dbf' SIZE 50M AUTOEXTEND ON PATH_PREFIX = '/u02/oradata/pdbs/trsenpdb/' FILE_NAME_CONVERT = ('/u02/oradata/trsen/pdbseed/', '/u02/oradata/pdbs/trsenpdb/'); c.After you create the PDB, it is in mounted mode, and its status is NEW. SYS@EMREP>select name,open_mode,status from dba_pdbs p ,v$pdbs s where p.con_id=s.con_id; NAME OPEN_MODE STATUS ---------------------------------------- -------------------- ------------------ PDB$SEED READ ONLY NORMAL PDBEMREP READ WRITE NORMAL TRSENPDB MOUNTED NEW
4.Open the trsenpdb in read/write mode.
SYS@EMREP>ALTER PLUGGABLE DATABASE trsenpdb OPEN READ WRITE; Pluggable database altered. SYS@EMREP>select name,open_mode,status from dba_pdbs p ,v$pdbs s where p.con_id=s.con_id; NAME OPEN_MODE STATUS ---------------------------------------- -------------------- ------------------ PDB$SEED READ ONLY NORMAL PDBEMREP READ WRITE NORMAL TRSENPDB READ WRITE NORMAL
二.Creating a PDB by Cloning an Existing PDB or Non-CDB
This technique clones a source PDB or non-CDB and plugs the clone into the CDB.
To use this technique, you must include a FROM clause that specifies the source.
The source is the existing PDB or non-CDB that is copied. The target PDB is the clone of the source.
The source can be a PDB in the local CDB, a PDB in a remote CDB, or a non-CDB.
When the source is a PDB in a remote CDB or non-CDB, you must specify a database link to the remote CDB or non-CDB in the FROM clause.
The CREATE PLUGGABLE DATABASE statement copies the files associated with the source to a new location and associates the files with the target PDB.
we will clone trsenpdb to clonpdb.we using the "create pluggable databaase …. from …" technique.
1.we will view all service information
SYS@EMREP>select name,pdb from v$services; NAME PDB ---------------------------------------- ------------------------------------------------------------ trsenpdb.com TRSENPDB pdbemrep.com PDBEMREP EMREPXDB CDB$ROOT handpay.com CDB$ROOT SYS$BACKGROUND CDB$ROOT SYS$USERS CDB$ROOT
2.create datafile directory and create clonepdb pdbs.
if the trsenpdb is remote or non-CDB,then create database link for trsenpdb. We can using the "create pluggable database xxx from xx@db_link …" statement.
mkdir -p /u02/oradata/pdbs/clonepdb CREATE PLUGGABLE DATABASE clonepdb FROM trsenpdb PATH_PREFIX = '/u02/oradata/pdbs/clonepdb' FILE_NAME_CONVERT = ('/u02/oradata/pdbs/trsenpdb/', '/u02/oradata/pdbs/clonepdb') SERVICE_NAME_CONVERT = ('trsenpdb.com','clonepdb') NOLOGGING; 3.view the pdbs's informations; SYS@EMREP>select name,open_mode,status from dba_pdbs p ,v$pdbs s where p.con_id=s.con_id; NAME OPEN_MODE STATUS ---------------------------------------- -------------------- ------------------ PDB$SEED READ ONLY NORMAL PDBEMREP READ WRITE NORMAL TRSENPDB READ WRITE NORMAL CLONEPDB MOUNTED NEW SYS@EMREP>select name,pdb from v$services; NAME PDB ---------------------------------------- ------------------------------------------------------------ clonepdb.com CLONEPDB trsenpdb.com TRSENPDB pdbemrep.com PDBEMREP EMREPXDB CDB$ROOT handpay.com CDB$ROOT SYS$BACKGROUND CDB$ROOT SYS$USERS CDB$ROOT SYS@EMREP>ALTER PLUGGABLE DATABASE clonepdb open read write; Pluggable database altered. SYS@EMREP>select name,open_mode,status from dba_pdbs p ,v$pdbs s where p.con_id=s.con_id; NAME OPEN_MODE STATUS ---------------------------------------- -------------------- ------------------ PDB$SEED READ ONLY NORMAL PDBEMREP READ WRITE NORMAL TRSENPDB READ WRITE NORMAL CLONEPDB READ WRITE NORMAL
三.Creating a PDB by Plugging an Unplugged PDB into a CDB
This technique uses the XML metadata file that describes the PDB and the files associated with the PDB to plug it into the CDB.
The trsenpdb on emrep container , we will use XML file pluggable to CDB2.
1. to generate an XML file named trsenpdb.xml in the /u02/oradata/pdbs directory
SYS@EMREP>BEGIN DBMS_PDB.DESCRIBE( pdb_descr_file => '/u02/oradata/pdbs/trsenpdb.xml', pdb_name => 'TRSENPDB'); END; / 2 3 4 5 6 PL/SQL procedure successfully completed.
2.check pdbs compatibility.if output is YES
SET SERVEROUTPUT ON DECLARE compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/u02/oradata/pdbs/trsenpdb.xml', pdb_name => 'TRSENPDB') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); END; /
3.close PDB trsenpdb and then unplug it
SYS@EMREP>alter session set container=trsenpdb; Session altered. SYS@EMREP>shutdown immediate; Pluggable Database closed. SYS@EMREP>ALTER PLUGGABLE DATABASE trsenpdb UNPLUG INTO '/u02/oradata/pdbs/trsenpdb.xml'; Pluggable database altered.
4.Run the CREATE PLUGGABLE DATABASE statement, and specify the XML file in the USING clause and Open the new PDB in read/write mode.
SYS@CDB1>CREATE PLUGGABLE DATABASE trsenpdb USING '/u02/oradata/pdbs/trsenpdb.xml' NOCOPY TEMPFILE REUSE; Pluggable database created. SYS@CDB1>ALTER PLUGGABLE DATABASE trsenpdb open read write Pluggable database altered. SYS@CDB1>select name,open_mode,status from dba_pdbs p ,v$pdbs s where p.con_id=s.con_id; NAME OPEN_MODE STATUS ---------------------------------------- -------------------- ------------------ PDBTEST READ WRITE NORMAL PDB$SEED READ ONLY NORMAL TRSENPDB READ WRITE NORMAL