- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Type | Note |
---|---|
Create a PDB by using the seed | Use the create_pdb_from_seed clause to create a PDB by using the seed in the multitenant container database (CDB) as a template. The files associated with the seed are copied to a new location and the copied files are then associated with the new PDB. |
Create a PDB by cloning an existing PDB or non-CDB (local or remote databases via DBLink) | Use the create_pdb_clone clause to create a PDB by copying an existing PDB or non-CDB and then plugging the copy into the CDB. The files associated with the existing PDB or non-CDB are copied to a new location and the copied files are associated with the new PDB. |
Create a PDB by plugging an unplugged PDB into a CDB/td> | Use the create_pdb_from_xml clause to plug an unplugged PDB or a non-CDB into a CDB, using an XML metadata file. |
Create a PDB by using the seed as a template
CREATE PLUGGABLE DATABASE PDB ADMIN USER Admin IDENTIFIED BY oracle FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/pdbseed/','/u01/app/oracle/oradata/PDB/') STORAGE (MAXSIZE 2G) PATH_PREFIX = '/u01/app/oracle/oradata/PDB/';
SQL> !mkdir /u01/app/oracle/oradata/cdb/pdb1 SQL> create pluggable database pdb1 admin user pdb1_admin identified by oracle roles=(CONNECT) create_file_dest='/u01/app/oracle/oradata/cdb/pdb1'; Pluggable database created. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ WRITE 4 PDB1 MOUNTED SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ WRITE 4 PDB1 READ WRITE
SQL> CREATE PLUGGABLE DATABASE pdb1 ADMIN USER pdb1_adm IDENTIFIED BY oracle ROLES=(DBA) DEFAULT TABLESPACE test DATAFILE '/u01/app/oracle/oradata/cdb/pdb1/test01.dbf' SIZE 5M AUTOEXTEND ON file_name_convert=('/u01/app/oracle/oradata/cdb/pdbseed/','/u01/app/oracle/oradata/cdb/pdb1/'); Pluggable database created. SQL> col pdb_name for a10 SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS ---------- --------- PDB NORMAL PDB$SEED NORMAL PDB1 NEW SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ ONLY 4 PDB1 MOUNTED SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS ---------- --------- PDB NORMAL PDB$SEED NORMAL PDB1 NORMAL SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ ONLY 4 PDB1 READ WRITE SQL> alter session set container=pdb1; Session altered. SQL> select file_name from dba_data_files; FILE_NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/cdb/pdb1/system01.dbf /u01/app/oracle/oradata/cdb/pdb1/sysaux01.dbf /u01/app/oracle/oradata/cdb/pdb1/test01.dbf
Cloning a Local PDB With the FILE_NAME_CONVERT:
CREATE PLUGGABLE DATABASE pdb1 FROM pdb FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/cdb/pdb/', '/u01/app/oracle/oradata/cdb/pdb1/') NOLOGGING;
SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB MOUNTED SQL> alter pluggable database pdb open; Pluggable database altered. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ WRITE SQL> CREATE PLUGGABLE DATABASE pdb1 FROM pdb FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/cdb/pdb/', '/u01/app/oracle/oradata/cdb/pdb1/') NOLOGGING; 2 3 Pluggable database created. SQL> SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ WRITE 4 PDB1 MOUNTED SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ WRITE 4 PDB1 READ WRITE
Cloning a Local PDB Without Cloning Its Data:
Restrictions:
The NO DATA clause is only valid is the the source PDB doesn't contain any of the following.
- Index-organized tables
- Advanced Queue (AQ) tables
- Clustered tables
- Table clusters
SQL> ALTER PLUGGABLE DATABASE pdb OPEN READ ONLY; Pluggable database altered. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ ONLY SQL> CREATE PLUGGABLE DATABASE pdb1 FROM pdb FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb/pdb/','/u01/app/oracle/oradata/cdb/pdb1/') NO DATA; CREATE PLUGGABLE DATABASE pdb1 FROM pdb FILE_NAME_CONVERT=('/u01/app/oracle/oradata/cdb/pdb/','/u01/app/oracle/oradata/cdb/pdb1/') NO DATA * ERROR at line 1: ORA-65161: Unable to create pluggable database with no data SQL> !oerr ora 65161 65161, 00000, "Unable to create pluggable database with no data" // *Cause: An attempt was made to clone a pluggable database which contains // some clustered tables or index organized tables or advanced // queue tables. // *Action: Retry the clone operation after dropping all such objects from the // source pluggable database.
Cloning a Remote PDB or Non-CDB
Prerequisites:
- The current user must have the CREATE PLUGGABLE DATABASE system privilege in the root of the CDB that will contain the target PDB.
- The source PDB or source non-CDB must be in open read-only mode.
- A database link must enable a connection from the CDB that will contain the target PDB to the remote source. If the source is a remote PDB, then the database link can connect to either the root of the remote CDB or to the remote source PDB.
- The user that the database link connects with at the remote source must have the CREATE PLUGGABLE DATABASE system privilege in the source PDB or in the non-CDB.
- If the database link connects to the root in a remote CDB, then the user that the database link connects with must be a common user.
- The source and target platforms must meet these requirements:
- They must have the same endianness.
- The database options installed on the source platform must be the same as, or a subset of, the database options installed on the target platform.
- If you are creating a PDB by cloning a non-CDB, then both the CDB and the non-CDB must be running Oracle Database 12c Release 1 (12.1.0.2) or later.
CREATE PLUGGABLE DATABASE pdb1 FROM cdb1_pdb@cdb1_pdb_link file_name_convert=('/u01/app/oracle/oradata/cdb1/cdb1_pdb/','/u01/app/oracle/oradata/cdb/pdb1/');Example with setup for cloning Remove CDB database:
SQL> create database link cdb1_pdb_link connect to test identified by oracle using 'CDB1_PDB_SRV'; Database link created. SQL> select sysdate from dual@cdb1_pdb_link; SYSDATE --------- 13-MAR-18 CREATE PLUGGABLE DATABASE pdb1 FROM cdb1_pdb@cdb1_pdb_link file_name_convert=('/u01/app/oracle/oradata/cdb1/cdb1_pdb/','/u01/app/oracle/oradata/cdb/pdb1/'); cdb1: SQL> create tablespace test_tbs datafile '/u01/app/oracle/oradata/cdb1/cdb1_pdb/test_tbs_01.dbf' size 5m; Tablespace created. SQL> alter user test default tablespace test_tbs; User altered. SQL> create table test.test_table (name varchar2(20)); Table created. SQL> alter user test quota unlimited on test_tbs; User altered. SQL> insert into test.test_table (name) values ('test entry'); 1 row created. SQL> commit; Commit complete. cdb: SQL> CREATE PLUGGABLE DATABASE pdb1 FROM cdb1_pdb@cdb1_pdb_link file_name_convert=('/u01/app/oracle/oradata/cdb1/cdb1_pdb/','/u01/app/oracle/oradata/cdb/pdb1/'); 2 Pluggable database created. SQL> SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ ONLY 4 PDB1 MOUNTED SQL> col name for a20 SQL> desc dba_pdbs Name Null? Type ----------------------------------------- -------- ---------------------------- PDB_ID NOT NULL NUMBER PDB_NAME NOT NULL VARCHAR2(128) DBID NOT NULL NUMBER CON_UID NOT NULL NUMBER GUID RAW(16) STATUS VARCHAR2(9) CREATION_SCN NUMBER VSN NUMBER LOGGING VARCHAR2(9) FORCE_LOGGING VARCHAR2(3) FORCE_NOLOGGING VARCHAR2(3) CON_ID NOT NULL NUMBER SQL> col pdb_name for a20 SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS -------------------- --------- PDB NORMAL PDB$SEED NORMAL PDB1 NEW SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS -------------------- --------- PDB NORMAL PDB$SEED NORMAL PDB1 NORMAL SQL> alter session set container=pdb1; Session altered. SQL> select * from test.test_table; NAME -------------------- test entryRemote non-CDB database:
CREATE PLUGGABLE DATABASE pdb1 FROM orcl@orcl_link file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/cdb/pdb1/');Example with setup for cloning Remove non-CDB database:
SQL> create database link orcl_link connect to test identified by oracle using 'ORCL_SRV'; Database link created. SQL> select sysdate from dual@orcl_link; SYSDATE --------- 13-MAR-18 SQL> CREATE PLUGGABLE DATABASE pdb1 FROM orcl@orcl_link file_name_convert=('/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/cdb/pdb1/'); Pluggable database created. @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql SQL> select name, open_mode from v$pdbs; NAME OPEN_MODE ------------------------------ ---------- PDB1 MOUNTED 1 row selected. SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> select * from test.test_table; NAME -------------------- test entry orcl 1 row selected.
Create a PDB by plugging an unplugged PDB into a CDB
Requirements:- The XML file that describes the PDB must exist in a location that is accessible to the CDB. The USING clause must specify the XML file.
- The files associated with the PDB (such as the data files and wallet file) must exist in a location that is accessible to the CDB.
- The source and target CDB platforms must meet the following requirements:
- They must have the same endianness.
- The database options installed on the source platform must be the same as, or a subset of, the database options installed on the target platform.
- The CDB that contained the unplugged PDB and the target CDB must have compatible character sets and national character sets.
SQL> BEGIN DBMS_PDB.DESCRIBE( pdb_descr_file => '/tmp/cdb1_pdb.xml', pdb_name => 'CDB1_PDB'); END; / 2 3 4 5 6 PL/SQL procedure successfully completed.On the target CDB database:
- If the output is YES, then the PDB is compatible, and you can continue with the next step. - If the output is NO, then the PDB is not compatible, and you can check the PDB_PLUG_IN_VIOLATIONS view to see why it is not compatible.
SQL> SET SERVEROUTPUT ON DECLARE compatible CONSTANT VARCHAR2(3) := CASE DBMS_PDB.CHECK_PLUG_COMPATIBILITY( pdb_descr_file => '/tmp/cdb1_pdb.xml', pdb_name => 'CDB1_PDB') WHEN TRUE THEN 'YES' ELSE 'NO' END; BEGIN DBMS_OUTPUT.PUT_LINE(compatible); END; /SQL> YES PL/SQL procedure successfully completed.Unplugging PDB:
SQL> ALTER PLUGGABLE DATABASE cdb1_pdb UNPLUG INTO '/tmp/cdb1_pdb.xml'; ALTER PLUGGABLE DATABASE cdb1_pdb UNPLUG INTO '/tmp/cdb1_pdb.xml' * ERROR at line 1: ORA-65025: Pluggable database CDB1_PDB is not closed on all instances. SQL> alter pluggable database cdb1_pdb close; Pluggable database altered. SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 CDB1_PDB MOUNTED SQL> ALTER PLUGGABLE DATABASE cdb1_pdb UNPLUG INTO '/tmp/cdb1_pdb.xml'; Pluggable database altered.Plugging In a Unplugged PDB:
SQL> CREATE PLUGGABLE DATABASE pdb1 USING '/tmp/cdb1_pdb.xml' SOURCE_FILE_DIRECTORY = '/u01/app/oracle/oradata/cdb1/cdb1_pdb/' COPY FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/cdb1/cdb1_pdb/', '/u01/app/oracle/oradata/cdb/pdb1/') TEMPFILE REUSE; 2 3 4 5 Pluggable database created.
SQL> select con_id, name, open_mode from v$pdbs; CON_ID NAME OPEN_MODE ---------- ------------------------------ ---------- 2 PDB$SEED READ ONLY 3 PDB READ ONLY 4 PDB1 MOUNTED SQL> col pdb_name for a10 SQL> select pdb_name, status from dba_pdbs; PDB_NAME STATUS ---------- --------- PDB NORMAL PDB$SEED NORMAL PDB1 NEW SQL> alter pluggable database pdb1 open; Pluggable database altered. SQL> alter session set container=pdb1; Session altered. SQL> select file_name from dba_data_files; FILE_NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/cdb/pdb1/system01.dbf /u01/app/oracle/oradata/cdb/pdb1/sysaux01.dbf /u01/app/oracle/oradata/cdb/pdb1/SAMPLE_SCHEMA_users01.dbf /u01/app/oracle/oradata/cdb/pdb1/example01.dbf /u01/app/oracle/oradata/cdb/pdb1/test_tbs_01.dbf
Comments
Post a Comment