您的位置:首页 > 数据库

dba_free_space 以及查询剩余表空间百分比和回滚段命中率的SQL

2008-12-18 10:42 393 查看
dba_free_space 显示的是有free 空间的tablespace ,如果一个tablespace 的free 空间不连续,那每段free空间都会在dba_free_space中存在一条记录。如果一个tablespace 有好几条记录,说明表空间存在碎片,当采用字典管理的表空间碎片超过500就需要对表空间进行碎片整理。

select tablespace_name,sum(bytes) 总字节数,max(bytes),count(*) from dba_free_space group by tablespace_name;

count大于500 要考虑一下了 是否需要整理

或者

SQL> select a.tablespace_name ,count(1) 碎片量 from dba_free_space a, dba_tablespaces b
2 where a.tablespace_name=b.tablespace_name
3 and b.extent_management = 'DICTIONARY'
4 group by a.tablespace_name
5 having count(1) >20
6 order by 2;

能否查到tablespace_name

表空间碎片整理语法:

alter tablespace [tablespace_name] coalesce;

===============================================================================================

剩余表空间百分比

select df.tablespace_name "表空间名",totalspace "总空间M",freespace "剩余空间M",round((1-freespace/totalspace)*100,2) "使用率%" from (select tablespace_name,round(sum(bytes)/1024/1024) totalspace from dba_data_files group by tablespace_name) df, (select tablespace_name,round(sum(bytes)/1024/1024) freespace from dba_free_space group by tablespace_name) fs where df.tablespace_name=fs.tablespace_name;

表空间名 总空间M 剩余空间M 使用率%
------------------------------ ---------- ---------- ----------
AA 5 5 0
UNDOTBS1 25 21 16
SYSAUX 260 13 95
USERS 5 5 0
SYSTEM 480 5 98.96

==================================================================================================

回滚段命中率

select rn.name,rs.gets 被访问次数,rs.waits 等待回退段块的次数,(rs.waits/rs.gets)*100 命中率 from v$rollstat rs,v$rollname rn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐