可以通过以下方式方便地找出监控oracle表空间使用率的sql:
找了个测试库,确保只有一个用户连接,利用toad查看表空间的使用率,先刷新share pool,再刷新查看表空间的使用率,此时,可以在share pool查看刚执行sql,如下:
select ts.tablespace_name 表空间名,
ts.status 状态,
ts.contents,
ts.extent_management,
size_info.megs_alloc,
size_info.megs_free,
size_info.megs_used,
size_info.pct_free,
size_info.pct_used,
round(size_info.megs_used*100 / size_info.max) used_of_max, ---add by myself
size_info.max
from (select a.tablespace_name,
round(a.bytes_alloc / 1024 / 1024) megs_alloc,
round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) pct_free,
100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) pct_used,
round(a.maxbytes / 1048576) max
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, 'yes', f.maxbytes, 'no', f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
union all
select h.tablespace_name,
round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
round(sum((h.bytes_free + h.bytes_used) -
nvl(p.bytes_used, 0)) / 1048576) megs_free,
round(sum(nvl(p.bytes_used, 0)) / 1048576) megs_used,
round((sum((h.bytes_free + h.bytes_used) -
nvl(p.bytes_used, 0)) /
sum(h.bytes_used + h.bytes_free)) * 100) pct_free,
100 - round((sum((h.bytes_free + h.bytes_used) -
nvl(p.bytes_used, 0)) /
sum(h.bytes_used + h.bytes_free)) * 100) pct_used,
round(sum(f.maxbytes) / 1048576) max
from sys.v_$temp_space_header h,
sys.v_$temp_extent_pool p,
dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
group by h.tablespace_name) size_info,
sys.dba_tablespaces ts
where ts.tablespace_name = size_info.tablespace_name
以上包括临时表空间的监控,如果只需监控永久表空间,,则简单改写为:
set linesize 100
col tablespace_name format a20
select *
from
(
select a.tablespace_name,
round(a.bytes_alloc / 1024 / 1024) megs_alloc,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
round((a.bytes_alloc - nvl(b.bytes_free, 0))*100/a.maxbytes) used_of_max,
round((a.maxbytes - a.bytes_alloc + nvl(b.bytes_free, 0))/1048576) free_of_max,
round(a.maxbytes / 1048576) max
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, 'yes', f.maxbytes, 'no', f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
)size_info
where size_info.used_of_max > 80;
监控内容只需查看used_of_max、free_of_max,其分别是已使用空间占最大表空间百分比、剩余可扩展表空间大小。(以上脚本是监控表空间使用率超过80%的表空间。)
相关阅读:
oracle undo 镜像数据探究
oracle 回滚(rollback)和撤销(undo)
undo 表空间损坏导致无法open
undo表空间失败的处理方法
oracle undo表空间重建与恢复
