由于管理的库最近发生了表空间不够的问题,原本是做了每小时任务,低于30G就邮件报警的功能,但是那天由于一位同事临时导入大量数据,导致第二天空间不够。
为了防止这种问题的继续发生,做了表空间自动添加功能:
说明:
首先做逻辑判断,如果当前的表空间小于配置的大小 如: 40G( 表空间的剩余和自动扩展文件的总大小),
首先创建如下视图:
create or replace view dba_tablespace_free as
select a.tablespace_name,a.total_space_mb allocated_space_mb,round(b.free_space_mb,2) free_space_mb,(a.max_space-a.total_space_mb) free_allocate_mb,round(a.max_space,2) max_space_mb,
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(case when AUTOEXTENSIBLE='YES' then maxbytes
else bytes end)/1024/1024) max_space
from dba_data_files group by tablespace_name)a,(select tablespace_nam