oracle dba常用语句3

 
 
24.查询表空间使用情况
select a.tablespace_name,
       round(a.abytes / 1024 / 1024) totalmb,
       round((a.abytes - f.fbytes) / 1024 / 1024) usedmb,
       round(f.fbytes / 1024 / 1024) freemb,
       (1 - round(f.fbytes / a.abytes, 2)) * 100 "%USED",
       round(f.fbytes / a.abytes, 2) * 100 "%FREE"
  from (select tablespace_name, sum(bytes) abytes from dba_data_files group by tablespace_name) a,
       (select tablespace_name, sum(bytes) fbytes from dba_free_space group by tablespace_name) f
 where a.tablespace_name = f.tablespace_name

也可以这样(这个查询较快):

select a.tablespace_name,
       round(a.abytes / 1024 / 1024) totalmb,
       round((a.abytes - f.fbytes) / 1024 / 1024) usedmb,
       round(f.fbytes / 1024 / 1024) freemb,
       (1 - round(f.fbytes / a.abytes, 2)) * 100 "%USED",
       round(f.fbytes / a.abytes, 2) * 100 "%FREE"
  from (select tablespace_name, sum(bytes) abytes from dba_data_files group by tablespace_name) a,
       (select tablespace_name, sum(bytes) fbytes from dba_free_space group by tablespace_name) f
 where a.tablespace_name = f.tablespace_name
 
25. 查询表空间的碎片程度
 
select tablespace_name,count(tablespace_name) from dba_free_space group by tablespace_name
having count(tablespace_name)>10;
 
alter tablespace name coalesce;
alter table name deallocate unused;
 
create or replace view ts_blocks_v as
select tablespace_name,block_id,bytes,blocks,'free space' segment_name from dba_free_space
union all
select tablespace_name,block_id,bytes,blocks,segment_name from dba_extents;
 
select * from ts_blocks_v;
 
select tablespace_name,sum(bytes),max(bytes),count(block_id) from dba_free_space
group by tablespace_name;
 
26。查询有哪些数据库实例在运行
select inst_name from v$active_instances;

27。查询表占用空间大小

select DISTINCT owner,segment_name,bytes/1024/1024 Mb from dba_extents where 
owner='SCOTT' and segment_type='TABLE';

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值