数据库CDB、PDB中的常用查询语句
数据库CDB、PDB中的常用查询语句
·
1.查看CDB中容器的信息
可以通过V$CONTAINERS视图来查看容器的信息
SQL>
SQL> desc V$CONTAINERS
Name Null? Type
----------------------------------------------------------------------------------- -------- --------------------------------------------------------
CON_ID NUMBER
DBID NUMBER
CON_UID NUMBER
GUID RAW(16)
NAME VARCHAR2(128)
OPEN_MODE VARCHAR2(10)
RESTRICTED VARCHAR2(3)
OPEN_TIME TIMESTAMP(3) WITH TIME ZONE
CREATE_SCN NUMBER
TOTAL_SIZE NUMBER
BLOCK_SIZE NUMBER
RECOVERY_STATUS VARCHAR2(8)
SNAPSHOT_PARENT_CON_ID NUMBER
APPLICATION_ROOT VARCHAR2(3)
APPLICATION_PDB VARCHAR2(3)
APPLICATION_SEED VARCHAR2(3)
APPLICATION_ROOT_CON_ID NUMBER
APPLICATION_ROOT_CLONE VARCHAR2(3)
PROXY_PDB VARCHAR2(3)
LOCAL_UNDO NUMBER
UNDO_SCN NUMBER
UNDO_TIMESTAMP DATE
CREATION_TIME DATE
PDB_COUNT NUMBER
AUDIT_FILES_SIZE NUMBER
MAX_SIZE NUMBER
MAX_DIAGNOSTICS_SIZE NUMBER
MAX_AUDIT_SIZE NUMBER
LAST_CHANGED_BY VARCHAR2(11)
MEMBER_CDB VARCHAR2(3)
TENANT_ID VARCHAR2(256)
UPGRADE_LEVEL NUMBER
GUID_BASE64 VARCHAR2(30)
SQL>
SQL> col name format a16
SQL> SELECT NAME,CON_ID,DBID,CON_UID,GUID FROM V$CONTAINERS ORDER BY CON_ID;
NAME CON_ID DBID CON_UID GUID
---------------- ---------- ---------- ---------- --------------------------------
CDB$ROOT 1 1093429351 1 86B637B62FDF7A65E053F706E80A27CA
PDB$SEED 2 2760955567 2760955567 EC789E4FEBCCDC88E0538A08A8C08E87
PDB1 3 2714456025 2714456025 EC78D5CEF183E2DBE0538A08A8C09E00
PDB2 4 3722518118 3722518118 EE89FBF58254959FE0538A08A8C0629A
CNDBAPDB 5 874005088 874005088 EE926813D203A023E0538A08A8C0E91E
CNDBAPDB3 6 570690296 3590399619 EE966433CFF1B7D7E0538A08A8C04375
CNDBAPDB2 7 3771255074 3771255074 EE926813D209A023E0538A08A8C0E91E
CNDBAPDB4_FRESH 8 803347847 803347847 EEA6240CF3422D52E0538A08A8C0C03F
CNDBAPDB6 9 4087158383 2561116322 EECFD8030E829AE2E0538A08A8C02B62
9 rows selected.
SQL>
2.查看PDB的信息
可以通过CDB_PDBS或DBA_PDBS视图来查看关于PDB的相关信息,
SQL>
SQL> desc CDB_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(10)
CREATION_SCN NUMBER
VSN NUMBER
LOGGING VARCHAR2(9)
FORCE_LOGGING VARCHAR2(39)
FORCE_NOLOGGING VARCHAR2(3)
APPLICATION_ROOT VARCHAR2(3)
APPLICATION_PDB VARCHAR2(3)
APPLICATION_SEED VARCHAR2(3)
APPLICATION_ROOT_CON_ID NUMBER
IS_PROXY_PDB VARCHAR2(3)
CON_ID NOT NULL NUMBER
UPGRADE_PRIORITY NUMBER
APPLICATION_CLONE VARCHAR2(3)
FOREIGN_CDB_DBID NUMBER
UNPLUG_SCN NUMBER
FOREIGN_PDB_ID NUMBER
CREATION_TIME NOT NULL DATE
REFRESH_MODE VARCHAR2(6)
REFRESH_INTERVAL NUMBER
TEMPLATE VARCHAR2(3)
LAST_REFRESH_SCN NUMBER
TENANT_ID VARCHAR2(255)
SNAPSHOT_MODE VARCHAR2(6)
SNAPSHOT_INTERVAL NUMBER
CREDENTIAL_NAME VARCHAR2(262)
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(10)
CREATION_SCN NUMBER
VSN NUMBER
LOGGING VARCHAR2(9)
FORCE_LOGGING VARCHAR2(39)
FORCE_NOLOGGING VARCHAR2(3)
APPLICATION_ROOT VARCHAR2(3)
APPLICATION_PDB VARCHAR2(3)
APPLICATION_SEED VARCHAR2(3)
APPLICATION_ROOT_CON_ID NUMBER
IS_PROXY_PDB VARCHAR2(3)
CON_ID NOT NULL NUMBER
UPGRADE_PRIORITY NUMBER
APPLICATION_CLONE VARCHAR2(3)
FOREIGN_CDB_DBID NUMBER
UNPLUG_SCN NUMBER
FOREIGN_PDB_ID NUMBER
CREATION_TIME NOT NULL DATE
REFRESH_MODE VARCHAR2(6)
REFRESH_INTERVAL NUMBER
TEMPLATE VARCHAR2(3)
LAST_REFRESH_SCN NUMBER
TENANT_ID VARCHAR2(255)
SNAPSHOT_MODE VARCHAR2(6)
SNAPSHOT_INTERVAL NUMBER
CREDENTIAL_NAME VARCHAR2(262)
SQL> COL PDB_NAME FORMAT a16
SQL>
SQL> SELECT PDB_ID,PDB_NAME,STATUS FROM DBA_PDBS ORDER BY PDB_ID;
PDB_ID PDB_NAME STATUS
---------- ---------------- ----------
2 PDB$SEED NORMAL
3 PDB1 NORMAL
4 PDB2 NORMAL
5 CNDBAPDB NORMAL
6 CNDBAPDB3 NORMAL
7 CNDBAPDB2 NORMAL
8 CNDBAPDB4_FRESH REFRESHING
9 CNDBAPDB6 NEW
8 rows selected.
SQL>
3.查看PDB的打开状态和打开时间
可以通过V$PDBS视图来查看PDB的打开状态和打开时间
SQL>
SQL> desc v$PDBS
Name Null? Type
----------------------------------------------------------------------------------- -------- --------------------------------------------------------
CON_ID NUMBER
DBID NUMBER
CON_UID NUMBER
GUID RAW(16)
NAME VARCHAR2(128)
OPEN_MODE VARCHAR2(10)
RESTRICTED VARCHAR2(3)
OPEN_TIME TIMESTAMP(3) WITH TIME ZONE
CREATE_SCN NUMBER
TOTAL_SIZE NUMBER
BLOCK_SIZE NUMBER
RECOVERY_STATUS VARCHAR2(8)
SNAPSHOT_PARENT_CON_ID NUMBER
APPLICATION_ROOT VARCHAR2(3)
APPLICATION_PDB VARCHAR2(3)
APPLICATION_SEED VARCHAR2(3)
APPLICATION_ROOT_CON_ID NUMBER
APPLICATION_ROOT_CLONE VARCHAR2(3)
PROXY_PDB VARCHAR2(3)
LOCAL_UNDO NUMBER
UNDO_SCN NUMBER
UNDO_TIMESTAMP DATE
CREATION_TIME DATE
DIAGNOSTICS_SIZE NUMBER
PDB_COUNT NUMBER
AUDIT_FILES_SIZE NUMBER
MAX_SIZE NUMBER
MAX_DIAGNOSTICS_SIZE NUMBER
MAX_AUDIT_SIZE NUMBER
LAST_CHANGED_BY VARCHAR2(11)
TEMPLATE VARCHAR2(3)
TENANT_ID VARCHAR2(256)
UPGRADE_LEVEL NUMBER
GUID_BASE64 VARCHAR2(30)
SQL> COL NAME FORMAT A16
SQL> COLUMN RESTRICTED FORMAT A15
SQL> COL OPEN_TIME FORMAT A10
SQL> COL OPEN_TIME FORMAT A40
SQL> SELECT NAME,OPEN_MODE,RESTRICTED,OPEN_TIME FROM V$PDBS;
NAME OPEN_MODE RESTRICTED OPEN_TIME
---------------- ---------- --------------- ----------------------------------------
PDB$SEED READ ONLY NO 30-NOV-22 08.34.29.904 PM +08:00
PDB1 READ WRITE NO 30-NOV-22 10.08.21.688 PM +08:00
PDB2 MOUNTED 30-NOV-22 10.07.56.099 PM +08:00
CNDBAPDB MOUNTED 30-NOV-22 10.07.56.116 PM +08:00
CNDBAPDB3 MOUNTED 30-NOV-22 10.07.56.123 PM +08:00
CNDBAPDB2 MOUNTED 30-NOV-22 10.07.56.103 PM +08:00
CNDBAPDB4_FRESH MOUNTED
CNDBAPDB6 MOUNTED 02-DEC-22 10.23.05.878 AM +08:00
8 rows selected.
SQL>
4.查看PDB中的表
设置PDB_ID>2是为了不查询CDB root和PDB seed
SQL> column owner format a16
SQL> column PDB_NAME format a16
SQL> select p.PDB_ID,p.PDB_NAME, T.OWNER,T.TABLE_NAME
2 FROM DBA_PDBS P,CDB_TABLES t
3 WHERE p.PDB_ID > 2 AND
4 t.owner in ('SCOTT','HR') AND
5 P.PDB_ID = t.CON_ID
6 ORDER BY p.PDB_ID;
PDB_ID PDB_NAME OWNER TABLE_NAME
---------- ---------------- ---------------- ------------------------------
3 PDB1 SCOTT T01
3 PDB1 HR COUNTRIES
3 PDB1 SCOTT EMP
3 PDB1 SCOTT BONUS
3 PDB1 SCOTT SALGRADE
3 PDB1 SCOTT EMP_AGGR_MV
3 PDB1 SCOTT TAB1
3 PDB1 SCOTT TAB2
3 PDB1 HR REGIONS
3 PDB1 HR LOCATIONS
3 PDB1 HR DEPARTMENTS
3 PDB1 HR JOBS
3 PDB1 HR EMPLOYEES
3 PDB1 HR JOB_HISTORY
3 PDB1 SCOTT DEPT
15 rows selected.
SQL>
5.查看PDB的数据文件
查看所有与PDB相关的数据文件,包括PDB seed
SQL>
SQL> col PDB_ID FORMAT 999
SQL> COL PDB_NAME FORMAT 999
SQL> COL PDB_NAME FORMAT A9
SQL> COL FILE_ID FORMAT 999
SQL> COL FILE_ID FORMAT 9999
SQL>
SQL>
SQL>
SQL> col PDB_ID FORMAT 999
SQL> COL PDB_NAME FORMAT A9
SQL> COL FILE_ID FORMAT 9999
SQL> COL TABLESPACE_NAME FORMAT A10
SQL> COL FILE_NAME FORMAT A40
SQL>
SQL> select p.PDB_ID,p.PDB_NAME,d.FILE_ID,d.TABLESPACE_NAME,d.FILE_NAME
2 FROM DBA_PDBS p,CDB_DATA_FILES d
3 WHERE p.PDB_ID = d.CON_ID
4 ORDER BY p.PDB_ID;
PDB_ID PDB_NAME FILE_ID TABLESPACE FILE_NAME
------ --------- ------- ---------- ----------------------------------------
3 PDB1 9 SYSTEM /u02/oradata/CDB1/pdb1/system01.dbf
3 PDB1 12 USERS /u02/oradata/CDB1/pdb1/users01.dbf
3 PDB1 11 UNDOTBS1 /u02/oradata/CDB1/pdb1/undotbs01.dbf
3 PDB1 10 SYSAUX /u02/oradata/CDB1/pdb1/sysaux01.dbf
SQL>
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献10条内容
所有评论(0)