Oracle数据库中,我们怎样查看表空间或数据文件包含哪些数据库对象呢?有怎样查看数据库对象所在的表空间及数据文件呢?
本文将提供一些查询脚本,供大家参考。
SELECT TABLESPACE_NAME,
SEGMENT_NAME,
SUM(BYTES)/1024/1024 SEGMENT_SIZE_M
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME='&TABLESPACE_NAME'
GROUP BY TABLESPACE_NAME,SEGMENT_NAME;
也通过下面SQL语句查看表空间的对象:
SELECT OWNER,
'TABLE' SEGMENT_TYPE,
TABLE_NAME SEGMENT_NAME
FROM DBA_TABLES
WHERE TABLESPACE_NAME='&TABLESPACE_NAME'
UNION ALL
SELECT OWNER,
'INDEX' SEGMENT_TYPE,
INDEX_NAME SEGMETN_NAME
FROM DBA_INDEXES
WHERE TABLESPACE_NAME='&TABLESPACE_NAME'
UNION ALL
SELECT OWNER,
'LOBSEGMENT' SGEMENT_TYPE,
SEGMENT_NAME SEGMENT_NAME
FROM DBA_LOBS
WHERE TABLESPACE_NAME='&TABLESPACE_NAME';
SELECT A.OWNER,
A.SEGMENT_NAME,
A.SEGMENT_TYPE,
B.FILE_NAME,
SUM(A.BYTES)/1024/1024 SEGMENT_SIZE_M
FROM DBA_EXTENTS A
INNER JOIN DBA_DATA_FILES B ON A.FILE_ID= B.FILE_ID
WHERE B.FILE_ID =&FILE_ID
GROUP BY A.OWNER,A.SEGMENT_NAME,A.SEGMENT_TYPE,B.FILE_NAME;
或
SELECT A.OWNER,
A.SEGMENT_NAME,
A.SEGMENT_TYPE,
B.FILE_NAME,
SUM(A.BYTES)/1024/1024 SEGMENT_SIZE_M
FROM DBA_EXTENTS A
INNER JOIN DBA_DATA_FILES B ON A.FILE_ID= B.FILE_ID
WHERE B.FILE_NAME ='&FILE_NAME'
GROUP BY A.OWNER,A.SEGMENT_NAME,A.SEGMENT_TYPE,B.FILE_NAME;
SELECT TABLE_NAME, TABLESPACE_NAME
FROM USER_TABLES
WHERE TABLE_NAME = '&TABLE_NAME';
SELECT A.OWNER,
A.SEGMENT_TYPE,
A.SEGMENT_NAME,
A.PARTITION_NAME,
A.TABLESPACE_NAME,
B.FILE_NAME,
SUM(A.BYTES)/1024/1024 SEGMENT_SIZE_M
FROM DBA_EXTENTS A
INNER JOIN DBA_DATA_FILES B ON A.FILE_ID= B.FILE_ID
WHERE A.OWNER='&OWNER'
AND A.SEGMENT_NAME='&SEGMENT_NAME'
GROUP BY A.OWNER,A.SEGMENT_TYPE,A.PARTITION_NAME,A.SEGMENT_NAME,A.TABLESPACE_NAME,B.FILE_NAME;