空间状态相关内容
-----------------------------------------------------------------------
1、查看表空间的名称及大小
SELECT t.Tablespace_Name, Round(SUM(Bytes / (1024 * 1024)), 0) Ts_Size
FROM Dba_Tablespaces t, Dba_Data_Files d
WHERE t.Tablespace_Name = d.Tablespace_Name
GROUP BY t.Tablespace_Name;
-----------------------------------------------------------------------
2、查看表空间物理文件的名称及大小
SELECT Tablespace_Name, File_Id, File_Name,
Round(Bytes / (1024 * 1024), 0) Total_Space
FROM Dba_Data_Files
ORDER BY Tablespace_Name;
-----------------------------------------------------------------------
3、求表空间的未用空间
col mbytes format 9999.9999
SELECT Tablespace_Name, SUM(Bytes) / 1024 / 1024 Mbytes
FROM Dba_Free_Space
GROUP BY Tablespace_Name;
-----------------------------------------------------------------------
4、察看数据库的大小,和空间使用情况
SELECT SUM(Bytes) / (1024 * 1024) AS Free_Space, Tablespace_Name
FROM Dba_Free_Space
GROUP BY Tablespace_Name;
SELECT a.Tablespace_Name, a.Bytes Total, b.Bytes Used, c.Bytes Free,
(b.Bytes * 100) / a.Bytes "% USED",
(c.Bytes * 100) / a.Bytes "% FREE"
FROM Sys.Sm$ts_Avail a, Sys.Sm$ts_Used b, Sys.Sm$ts_Free c
WHERE a.Tablespace_Name = b.Tablespace_Name
AND a.Tablespace_Name = c.Tablespace_Name;
-----------------------------------------------------------------------
5、查看表空间的文件使用情况
SELECT b.File_Id 文件id, b.Tablespace_Name 表空间, b.File_Name 物理文件名,
b.Bytes 总字节数, (b.Bytes - SUM(Nvl(a.Bytes, 0))) 已使用,
SUM(Nvl(a.Bytes, 0)) 剩余,
SUM(Nvl(a.Bytes, 0)) / (b.Bytes) * 100 剩余百分比
FROM Dba_Free_Space a,
Dba_Data_Files b where a.File_Id = b.File_Id group BY b.Tablespace_Name,
b.File_Name, b.File_Id, b.Bytes order BY b.Tablespace_Name
--/ dba_Free_Space --表空间剩余空间状况
-- dba_Data_Files --数据文件空间占用情况
-----------------------------------------------------------------------
6、 查询表空间的碎片程度
SELECT Tablespace_Name, COUNT(Tablespace_Name)
FROM Dba_Free_Space
GROUP BY Tablespace_Name
HAVING COUNT(Tablespace_Name) > 10;
alter tablespace name coalesce;
alter table name deallocate unused;
create or replace view ts_blocks_v as
SELECT Tablespace_Name, Block_Id, Bytes, Blocks, 'free space' Segment_Name
FROM Dba_Free_Space
UNION ALL
SELECT Tablespace_Name, Block_Id, Bytes, Blocks, Segment_Name
FROM Dba_Extents;
select * from ts_blocks_v;
SELECT Tablespace_Name, SUM(Bytes), MAX(Bytes), COUNT(Block_Id)
FROM Dba_Free_Space
GROUP BY Tablespace_Name;