Check if the database is CDB or non-CDB
SQL> select cdb from v$database; CDB --- YES
Connecting to Container
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> show con_id CON_ID ------------------------------ 1 SQL> show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 PRD_PDB_CON READ WRITE NO 4 PRD_PDB_TEN READ WRITE NO
Navigate across PDBs
SQL> alter session set container=PDB$SEED; Session altered. SQL> alter session set container=PRD_PDB_CON; Session altered. SQL>
Information about PDBs
SQL> COLUMN PDB_NAME FORMAT A15 SQL> COLUMN PDB_NAME FORMAT A15 SQL> SELECT PDB_ID, PDB_NAME, STATUS FROM DBA_PDBS ORDER BY PDB_ID; PDB_ID PDB_NAME STATUS ---------- --------------- --------- 2 PDB$SEED NORMAL 3 PRD_PDB_CON NORMAL 4 PRD_PDB_TEN NORMAL
Checking/changing Parameter
SQL> select * from v$system_parameter; SQL> select * from PDB_SPFILE$; SQL> alter system set parameter_name=value; SQL> alter system set parameter_name=value CONTAINER=CURRENT;
Startup and shutdown of PDB
Some typical values:
STARTUP [NOMOUNT | MOUNT | RESTRICT | UPGRADE | FORCE | READ ONLY]
SHUTDOWN [IMMEDIATE | ABORT]
$ export ORACLE_SID=pcdb01 $ sqlplus / as sysdba SQL> shutdown immediate;
Stop Pluggable Database
SQL> alter pluggable database PRD_PDB_CON close [immediate]; SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON close [immediate]; SQL> alter pluggable database ALL close; SQL> alter pluggable database PRD_PDB_CON close [immediate] [instances=all];
Or:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> shutdown immediate;
Start Pluggable Database
STARTUP FORCE
STARTUP OPEN READ WRITE [RESTRICT]
STARTUP OPEN READ ONLY [RESTRICT]
STARTUP UPGRADE
SHUTDOWN [IMMEDIATE]
SQL> alter pluggable database PDB01 open; SQL> alter pluggable database ALL EXCEPT PRD_PDB_CON open; SQL> alter pluggable database ALL open; SQL> alter pluggable database PDB01 open [instances=all];
Or:
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; SQL> startup; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ WRITE [RESTRICTED] [FORCE]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN READ ONLY [RESTRICTED][FORCE]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> OPEN UPGRADE [RESTRICTED]; SQL> alter PLUGGABLE DATABASE <pdb-name-clause> CLOSE [IMMEDIATE];
Preserve PDB Startup State (12.1.0.2 onward)
SQL> alter PLUGGABLE DATABASE pdb2 OPEN; SQL> alter PLUGGABLE DATABASE pdb2 SAVE STATE;
The DBA_PDB_SAVED_STATES view displays information about the saved state of containers.
SQL> COLUMN con_name FORMAT A20 SQL> COLUMN instance_name FORMAT A20 SQL> SELECT con_name, instance_name, state FROM dba_pdb_saved_states; CON_NAME INSTANCE_NAME STATE -------------------- -------------------- -------------- PRD_PDB_CON pcdb01 OPEN
Size of pluggable database
SQL> COLUMN NAME FORMAT A20 SQL> SELECT DBID, NAME, CON_ID, CON_UID, TOTAL_SIZE FROM V$CONTAINERS ORDER BY CON_ID; DBID NAME CON_IDCON_UID TOTAL_SIZE ---------- ------------------------------ ---------- ---------- ---------- 2732069181 CDB$ROOT 1 1 0 3552543733 PDB$SEED 2 3552543733 775946240 4008367944 PRD_PDB_CON 3 4008367944 1203765248 2667104724 PRD_PDB_TEN 4 2667104724 1182793728
Startup time of pluggable database
SQL> set linesize 180 SQL> col name for a30 SQL> col open_time for a33 SQL> select con_id,name,dbid,open_mode,open_time from v$containers; CON_ID NAME DBID OPEN_MODE OPEN_TIME ---------- ---------------- -------------- ---------- ---------- --------------------------------- 1 CDB$ROOT 456650806 READ WRITE 17-MAR-18 11.59.36.176 PM -03:00 2 PDB$SEED 2688102972 READ ONLY 17-MAR-18 11.59.36.182 PM -03:00 3 PDB_PN1O0101 1079206163 READ WRITE 18-MAR-18 12.00.00.589 AM -03:00 4 PDB_BATCHWEB 2340495643 READ WRITE 18-MAR-18 12.00.03.485 AM -03:00 4 rows selected.
Uptime of pluggable database
SQL> set linesize 180 SQL> col name for a30 SQL> col open_time for a28 SQL> select name,floor(sysdate-cast(open_time as date))||'Days '||floor(((sysdate-cast(open_time as date))-floor(sysdate-cast(open_time as date)))*24)||'hours '||round(((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date) )*24)-floor((sysdate-cast(open_time as date)-floor(sysdate-cast(open_time as date))*24)))*60)||'minutes' "Database Uptime" from v$containers; NAME Database Uptime --------------- --------------------------- CDB$ROOT 1331Days 11hours 28minutes PDB$SEED 1331Days 11hours 28minutes PDB_PN1O0101 1331Days 11hours 28minutes PDB_BATCHWEB 1331Days 11hours 28minutes 4 rows selected.
Name of services
SQL> COLUMN NAME FORMAT A30 SQL> SELECT NAME,CON_ID,PDB FROM V$SERVICES ORDER BY CON_ID; NAME CON_ID PDB ------------------------------ ---------- ------------------------------ pcdb01XDB 1 CDB$ROOT SYS$BACKGROUND 1 CDB$ROOT SYS$USERS 1 CDB$ROOT pcdb01 1 CDB$ROOT prd_pdb_con 3 PRD_PDB_CON prd_pdb_ten 4 PRD_PDB_TEN 6 rows selected.
Create Common users with access to all pdbs
SQL> CREATE USER c##user1 IDENTIFIED BY password1 CONTAINER=ALL; User created. SQL> GRANT CREATE SESSION TO c##user1 CONTAINER=ALL; Grant succeeded.
Create Common users without access to pdbs
SQL> CREATE USER c##user2 IDENTIFIED BY password1; User created. SQL> GRANT CREATE SESSION TO c##user2; Grant succeeded.
Create local user with access only to pdb
SQL> CREATE USER user3 IDENTIFIED BY password3 CONTAINER=CURRENT; User created. SQL> GRANT CREATE SESSION TO user3 CONTAINER=CURRENT; Grant succeeded.
Create Common role
SQL> CONN / AS SYSDBA SQL> CREATE ROLE c##role1; Role created. SQL> GRANT CREATE SESSION TO c##role1; Grant succeeded.
Grant role to a common user
SQL> GRANT c##role1 TO c##user1 CONTAINER=ALL; Grant succeeded.
Grant role to a common user to a local user
SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; Session altered. SQL> GRANT c##role1 TO user2; Grant succeeded.
Local Roles
SQL> CONN / AS SYSDBA SQL> alter SESSION SET CONTAINER = PRD_PDB_CON; Session altered. SQL> CREATE ROLE role1; Role created. SQL> GRANT CREATE SESSION TO role1; Grant succeeded.
Creating PDBs
SQL> create pluggable database HMLPDB admin user admin identified by PassDw1 roles = (DBA); SQL> create pluggable database DSVPDB admin user admin identified by Manager1roles = (DBA) storage (MAXSIZE 1G) FILE_NAME_CONVERT=('/u01/app/oracle/oradata/pcdb01/pcdb01_pdbseed_','/u01/app/oracle/oradata/dsvpdb/dsvpdb_'); SQL> create pluggable database DSVPDB1 from DSVPDB file_name_convert=('/DSVPDB/','/DSVPDB1/');
Excluding PDBs
SQL> alter pluggable database DSVPDB1 close [immediate] [instances=all]; SQL> drop pluggable database DSVPDB1 including datafiles;
Unplugging PDBs
$ sqlplus / as sysdba SQL> alter pluggable database PRD_PDB_CON close; SQL> alter pluggable database PRD_PDB_CON unplug into '/tmp/prd_pdb_con.xml';
Plugging PDBs
$ sqlplus / as sysdba SQL> create pluggable database PRD_PDB_CON using '/tmp/prd_pdb_con.xml' FILE_NAME_CONVERT=('/oradata/cdb1/prd_pdb_con', '/oradata/cdb2/prd_pdb_con'); SQL> alter pluggable database PRD_PDB_CON open;
Configuring Services on Oracle RAC with CDBs
$ srvctl add service -db CDB01 -service new_service -pdb PRD_PDB_CON $ srvctl modify service -db CDB01 -service new_service -pdb PRD_PDB_CON $ srvctl remove service -db CDB01 -service new_service BEGIN DBMS_SERVICE.CREATE_SERVICE( service_name => 'new_service', network_name => 'new_service.com'); END; / BEGIN DBMS_SERVICE.DELETE_SERVICE( service_name => 'new_service'); END; /
With root container, we have cdb_tablespaces and cdb_data_files shows the tablespace and datafiles of all the container in the CDB.
When connected to a PDB, cdb_tablespaces and cdb_data_files shows the same information as dba_tablespaces, dba_data_files for the PDB.
SQL> alter session set container=CDB$ROOT; Session altered. SQL> select tablespace_name, con_id from cdb_tablespaces order by con_id; TABLESPACE_NAME CON_ID ------------------------------ -------- SYSTEM 1 SYSAUX 1 UNDOTBS2 1 TEMP 1 USERS 1 UNDOTBS1 1 SYSTEM 3 SYSAUX 3 TBS_GEN_01 3 TEMP 3 TBS_CON_IDX_01 3 TBS_CON_DT_01 3 USERS 3 SYSTEM 4 SYSAUX 4 TBS_GEN_01 4 USERS 4 TEMP 4 18 rows selected. SQL> select tablespace_name from dba_tablespaces; TABLESPACE_NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 TEMP USERS UNDOTBS2 6 rows selected.
How to check for Local Undo feature in 12.2
In Oracle Database 12c Release 1 all containers in an instance shared the same undo tablespace.
In Oracle 12c Release 2 each container in an instance can use its own undo tablespace.
SQL> shutdown immediate; SQL> startup upgrade; SQL> alter database local undo on; SQL> shutdown immediate; SQL> startup; SQL> col property_name format a30 SQL> col property_value format a30 SQL> select property_name, property_value from database_properties where property_name = 'LOCAL_UNDO_ENABLED'; PROPERTY_NAME PROPERTY_VALUE ---------------- -------------- LOCAL_UNDO_ENABLED TRUE
References