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

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

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值