Oracle 数据库查看表空间的使用情况
SELECT d.tablespace_name,
space "SUM_SPACE(MB)",
space - NVL(free_space, 0) "USED_SPACE(MB)",
free_space "FREE_SPACE(MB)",
ROUND((1 - NVL(free_space, 0) / space) * 100, 2) "USED_RATE(%)",
ROUND(NVL(free_space, 0) * 100 / space, 2) "FREE_RATE(%)"
FROM (SELECT tablespace_name, ROUND(SUM(bytes) / (1024 * 1024), 2) space
FROM dba_data_files
GROUP BY tablespace_name) d,
(SELECT tablespace_name,
ROUND(SUM(bytes) / (1024 * 1024), 2) free_space
FROM dba_free_space
GROUP BY tablespace_name) f
WHERE d.tablespace_name = f.tablespace_name(+)
ORDER BY "USED_RATE(%)" DESC;
查看表空间的数据文件
select t1.name, t2.name
from v$tablespace t1, v$datafile t2
where t1.ts# = t2.ts# and t1.name = 'tablespace_Name'
查看表空间的详细情况
SELECT t.tablespace_name,
'Datafile' file_type,
t.status tablespace_status,
d.status file_status,
ROUND((d.bytes - NVL(f.sum_bytes, 0)) / 1048576) used_mb,
ROUND(NVL(f.sum_bytes, 0) / 1048576) free_mb,
t.initial_extent,
t.next_extent,
t.min_extents,
t.max_extents,
t.pct_increase,
d.file_name,
d.file_id,
d.autoextensible,
d.maxblocks,
d.maxbytes,
nvl(d.increment_by, 0) increment_by,
t.block_size
FROM (SELECT tablespace_name, file_id, SUM(bytes) sum_bytes
FROM DBA_FREE_SPACE
GROUP BY tablespace_name, file_id) f,
DBA_DATA_FILES d,
DBA_TABLESPACES t
WHERE t.tablespace_name = d.tablespace_name
AND f.tablespace_name(+) = d.tablespace_name
AND f.file_id(+) = d.file_id
GROUP BY t.tablespace_name,
d.file_name,
d.file_id,
t.initial_extent,
t.next_extent,
t.min_extents,
t.max_extents,
t.pct_increase,
t.status,
d.bytes,
f.sum_bytes,
d.status,
d.AutoExtensible,
d.maxblocks,
d.maxbytes,
d.increment_by,
t.block_size
UNION ALL
SELECT h.tablespace_name,
'Tempfile',
ts.status,
t.status,
ROUND(SUM(NVL(p.bytes_used, 0)) / 1048576),
ROUND(SUM((h.bytes_free + h.bytes_used) - NVL(p.bytes_used, 0)) /
1048576),
-1, -- initial extent
-1, -- initial extent
-1, -- min extents
-1, -- max extents
-1, -- pct increase
t.file_name,
t.file_id,
t.autoextensible,
t.maxblocks,
t.maxbytes,
nvl(t.increment_by, 0) increment_by,
ts.block_size
FROM sys.V_$TEMP_SPACE_HEADER h,
sys.V_$TEMP_EXTENT_POOL p,
sys.DBA_TEMP_FILES t,
sys.dba_tablespaces ts
WHERE p.file_id(+) = h.file_id
AND p.tablespace_name(+) = h.tablespace_name
AND h.file_id = t.file_id
AND h.tablespace_name = t.tablespace_name
and ts.tablespace_name = h.tablespace_name
GROUP BY h.tablespace_name,
t.status,
t.file_name,
t.file_id,
ts.status,
t.autoextensible,
t.maxblocks,
t.maxbytes,
t.increment_by,
ts.block_size
ORDER BY 1, 5 DESC
查看表空间是否可扩展
select file_name,autoextensible,increment_by from dba_data_files;
查看表空间的创建语句
SELECT tablespace_name, DBMS_METADATA.GET_DDL('TABLESPACE', TS.tablespace_name)
FROM DBA_TABLESPACES TS;
查看存储过程方法等的创建语句