最近接触数据库自动扩展,发现对表空间大小的监控不能用网上查的通用的方式去获取,通用的没有考虑进去自动扩展,现在自己改了一版。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| select a.tablespace_name, round((a.maxbytes / 1024 / 1024 / 1024), 2) "sum G", round((a.bytes / 1024 / 1024 / 1024), 2) "datafile G", round(((a.bytes - b.bytes) / 1024 / 1024 / 1024), 2) "used G", round(((a.maxbytes - a.bytes + b.bytes) / 1024 / 1024 / 1024), 2) "free G", round(((a.bytes - b.bytes) / a.maxbytes) * 100, 2)||'%' "percent_used(%)" from (select tablespace_name, sum(bytes) bytes, sum(decode(autoextensible,'YES',maxbytes,'NO',bytes)) maxbytes from dba_data_files group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) b where a.tablespace_name = b.tablespace_name order by ((a.bytes - b.bytes) / a.maxbytes) desc;
|
- autoextensible是自动扩展的参数
- decode函数语法:DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )
Value 代表某个表的任何类型的任意列或一个通过计算所得的任何结果。当每个value值被测试,如果value的值为if1,Decode 函数的结果是then1;如果value等于if2,Decode函数结果是then2;等等。事实上,可以给出多个if/then 配对。如果value结果不等于给出的任何配对时,Decode 结果就返回else 。
- 使用自动扩展的datafile,bytes字段为已分配的容量,maxbytes字段为最大容量(32G);不使用自动扩展的datafile,maxbytes字段、maxblocks字段、increment_by字段为0。maxblocks字段为最大块数,increment_by字段为每次自动扩展块数(详见dba_data_files的表结构)
参考
- oracle 表空间自动扩展大小
- 你知道Oracle的数据文件大小有上限么?
- Oracle中数据文件的大小限制