自己编写的监控表空间利用率的小脚本,这个脚本没有监控temp表空间
这个脚本按照表空间使用率降序排列
col tablespace_name format a15
col total_space format a10
col free_space format a10
col used_space format a10
col used_rate format 99.99
select a.tablespace_name,a.total_space_Mb||'m' total_space,b.free_space_Mb||'m' free_space,a.total_space_Mb-b.free_space_Mb||'m' used_space,
(1-(b.free_space_Mb/a.total_space_Mb))*100 used_rate,a.total_blocks,b.free_blocks from
(select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_files group by tablespace_name) a,
(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name order by used_rate desc;
这个脚本格式化了百分比
col tablespace_name format a15
col total_space format a10
col free_space format a10
col used_space format a10
col used_rate format a10
select a.tablespace_name,a.total_space_Mb||'m' total_space,b.free_space_Mb||'m' free_space,a.total_space_Mb-b.free_space_Mb||'m' used_space,
round((1-(b.free_space_Mb/a.total_space_Mb)),4)*100||'%' used_rate,a.total_blocks,b.free_blocks from
(select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,sum(blocks) total_blocks from dba_data_files group by tablespace_name) a,
(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb,sum(blocks) free_blocks from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name;
上面两个脚本没有考虑数据文件是否能自动增长,下面的脚本考虑数据文件能自动增长的情况
col tablespace_name heading Tablespace_Name
col allocated_space heading Allocated_Space
col free_space heading Free_Space(Mb)
col max_spacee heading Max_space(Mb)
select a.tablespace_name,a.total_space_mb allocated_space,round(b.free_space_mb,2) free_space,round(a.max_space,2) max_space,
round((a.total_space_mb-b.free_space_mb)/a.total_space_mb*100,2) pct_usage,round(a.total_space_mb/a.max_space*100,2) pct_allocated
from (select tablespace_name,sum(bytes)/1024/1024 total_space_Mb,decode(sum(maxbytes/1024/1024),0,
sum(bytes)/1024/1024,sum(maxbytes)/1024/1024) max_space
from dba_data_files group by tablespace_name)a,(select tablespace_name, sum((bytes)/1024/1024) free_space_Mb
from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name order by pct_allocated desc;
监控数据文件脚本
col max_size heading Max_Size(Gb)
col file_size heading File_Size(Mb)
col next heading Next(Bytes)
col autoextensible heading Auto
col file_name heading File_Name
col tablespace_name heading Tablespace_Name
col free_size heading Free_Size(Mb)
col used_rate heading Pct.used
select tablespace_name,file_name,bytes/1024/1024 file_size,round(a.free_size,2) free_size,autoextensible,increment_by next,round(maxbytes/1024/1024/1024)
max_size,round(((bytes/1024/1024)-a.free_size)/(bytes/1024/1024)*100,2) used_rate from dba_data_files b,(select file_id,sum(bytes)/1024/1024 free_size from dba_free_space group by file_id) a
where b.file_id=a.file_id order by used_rate desc;