--=================================
-- List Available PDBs
--=================================
SHOW PDBS
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBX READ WRITE NO
SELECT con_id, name, open_mode FROM V$PDBS;
CON_ID NAME OPEN_MODE
------- ------------ ----------
2 PDB$SEED READ ONLY
3 PDBX READ WRITE
SHOW con_id SHOW con_name
CON_ID CON_NAME
--------- -------------
1 CDB$ROOT
SELECT
SYS_CONTEXT('USERENV','CON_ID') CON_ID,
SYS_CONTEXT('USERENV','CON_NAME') CON_NAME
FROM DUAL;
CON_ID CON_NAME
-------- --------------
3 PDBX
SELECT pdb_id, pdb_name, dbid, con_id FROM CDB_PDBS;
PDB_ID PDB_NAME DBID CON_ID
------ -------- ---------- ------
3 PDBX 1234567890 3
2 PDB$SEED 123456789 2
--=================================
-- Open the PDB.
--=================================
ALTER PLUGGABLE DATABASE ALL OPEN;
ALTER PLUGGABLE DATABASE PDBX OPEN;
ALTER PLUGGABLE DATABASE ALL EXCEPT PDBX OPEN;
ALTER PLUGGABLE DATABASE PDBX OPEN READ ONLY;
ALTER PLUGGABLE DATABASE PDBX OPEN READ ONLY [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE PDBX OPEN READ WRITE;
ALTER PLUGGABLE DATABASE PDBX OPEN READ WRITE [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE PDBX OPEN UPGRADE [RESTRICTED];
--- Connected in PDB ---
ALTER SESSION SET CONTAINER = PDBX;
ALTER PLUGGABLE DATABASE OPEN READ WRITE [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE OPEN READ ONLY [RESTRICTED] [FORCE];
ALTER PLUGGABLE DATABASE OPEN UPGRADE [RESTRICTED];
--=================================
-- Save State:
--=================================
SELECT name, open_mode FROM v$pdbs;
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
PDBX MOUNTED
ALTER PLUGGABLE DATABASE PDBX OPEN;
ALTER PLUGGABLE DATABASE PDBX SAVE STATE;
ALTER PLUGGABLE DATABASE ALL SAVE STATE;
SELECT con_name, instance_name, state FROM CDB_PDB_SAVED_STATES;
CON_NAME INSTANCE_NAME STATE
-------------------- -------------------- --------------
PDBX CDBX OPEN
--=================================
-- Close the PDB.
--=================================
ALTER PLUGGABLE DATABASE ALL CLOSE;
ALTER PLUGGABLE DATABASE PDBX CLOSE;
ALTER PLUGGABLE DATABASE ALL EXCEPT PDBX CLOSE IMMEDIATE;
ALTER PLUGGABLE DATABASE PDBX CLOSE [IMMEDIATE];
-- connected to the PDB
ALTER SESSION SET CONTAINER = PDBX;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;
--=================================
-- Automatic Startup:
--=================================
CREATE OR REPLACE TRIGGER open_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END open_pdbs;
/
--=================================
-- Unplug the PDB:
--=================================
ALTER PLUGGABLE DATABASE PDBX CLOSE;
ALTER PLUGGABLE DATABASE PDBX UNPLUG INTO '/tmp/pdbx.pdb';
SELECT pdb_id, pdb_name, status FROM cdb_pdbs;
PDB_ID PDB_NAME STATUS
------ -------- ----------
2 PDB$SEED NORMAL
3 PDB18 NORMAL
--=================================
-- Rename:
--=================================
SHOW PDBS
CONNECT sys@PDBX AS SYSDBA
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;
ALTER PLUGGABLE DATABASE OPEN RESTRICTED;
SELECT con_id, name, open_mode, restricted FROM V$PDBS;
ALTER PLUGGABLE DATABASE RENAME GLOBAL_NAME TO PDB_ORCL;
SELECT con_id, name, open_mode, restricted FROM V$PDBS;
ALTER PLUGGABLE DATABASE CLOSE IMMEDIATE;
ALTER PLUGGABLE DATABASE OPEN;
SELECT con_id, name, open_mode, restricted FROM V$PDBS;
--=================================
-- Remove:
--=================================
DROP PLUGGABLE DATABASE PDBX INCLUDING DATAFILES;
DROP PLUGGABLE DATABASE PDBX KEEP DATAFILES;
--=================================
-- Check applications
--=================================
SELECT
name, con_id, application_root "APP_ROOT",
application_seed "APP_Seed",application_pdb "APP_PDB",
application_root_con_id "APP_ROOT_CONID"
FROM v$containers;
--=================================
-- CDB / PDB
--=================================
ALTER SESSION SET CONTAINER = CDB$ROOT;
ALTER SESSION SET CONTAINER = PDBX;