Confirm which container you are in and query all PDBs from the root (CDB_ / CONTAINERS)
OracleMultitenantCommand
-- Current container:
SHOW CON_NAME
SHOW CON_ID
SHOW PDBS
SELECT SYS_CONTEXT('USERENV','CON_NAME') AS con_name,
SYS_CONTEXT('USERENV','CON_ID') AS con_id
FROM dual;
-- All containers, from the root:
SELECT con_id, name, open_mode FROM v$containers ORDER BY con_id;
-- CDB_ views combine all open PDBs with CON_ID:
SELECT c.name AS container, t.tablespace_name, t.status
FROM cdb_tablespaces t JOIN v$containers c ON c.con_id = t.con_id
ORDER BY c.name, t.tablespace_name;
-- Query any table/view across all PDBs with CONTAINERS():
SELECT con_id, COUNT(*) AS users
FROM CONTAINERS(dba_users)
GROUP BY con_id ORDER BY con_id;What it does
Shows the container the session is connected to; from the root, CDB_ views and the CONTAINERS() clause collect dictionary information from all open PDBs in a single query.
When to use it
To make sure you are in the right container before a DDL/parameter change, and to build a space, user and object inventory across all PDBs.
Caution
Read-only. Do not accidentally create application objects or local users in the root (CDB$ROOT); ALTER SYSTEM in the root affects the whole CDB. CDB_ views and CONTAINERS() return only open PDBs; MOUNTED PDBs do not appear in the result.
Related
- Create a new PDB from PDB$SEED
- Clone a PDB within the same CDB (local / hot clone)
- Clone a PDB from another CDB over a DB link (remote clone)
- Unplug a PDB and plug it into another (or the same) CDB
- Open PDBs and keep them open across CDB restarts (SAVE STATE)
- Set per-PDB CPU, memory, I/O and storage limits