Chinaunix首页 | 论坛 | 博客
  • 博客访问: 389312
  • 博文数量: 58
  • 博客积分: 2096
  • 博客等级: 大尉
  • 技术积分: 608
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-29 16:09
个人简介

专注于数据库技术研究和实践,目前就职于互联网金融企业,提供Oracle数据库技术支持和维护。 联系电话:18616803656

文章分类

全部博文(58)

文章存档

2020年(1)

2019年(4)

2018年(1)

2017年(3)

2015年(4)

2014年(7)

2012年(1)

2011年(27)

2010年(8)

2009年(2)

我的朋友

分类: Oracle

2019-03-14 15:17:29

1. 查询占据高水位的对象
select owner,table_name,object_type, count(1) num_obj
from (
select e.owner, nvl(nvl(t.table_name,l.table_name),i.table_name) table_name,
       case
         when t.table_name is not null then 'TABLE'
         when l.table_name is not null then 'LOB'
         when i.table_name is not null then 'INDEX'
       else
         null
       end  object_type
from   dba_extents e,
       dba_tables  t,
       dba_lobs    l,
       dba_indexes i
where e.owner = t.owner(+)
and   e.segment_name = t.table_name(+)
and   e.owner = l.owner(+)
and   e.segment_name = l.segment_name(+)
and   e.owner = i.owner(+)
and   e.segment_name = i.index_name(+)
and   e.block_id > 1966080
and   e.file_id in (data_file_id_list of the tablespace)
)
group by owner, table_name, object_type
;

上述SQL根据提供的数据文件ID查询占用BLOCK大于15GB位置的对象。

2. 收缩表和Lob字段
收缩表
alter table table_name enable row movement;
alter table table_name shrink space compact;
alter table table_name shrink space;

收缩Lob字段

alter table table_name modify lob (lob_column_name) (shrink space cascade);

3. 查询每个数据文件可回收的空间
SELECT a.tablespace_name,
       a.file_id,
       a.file_name,
       CEIL((NVL(hwm, 1) * blksize) / 1024 / 1024)  smallest,
       CEIL(blocks * blksize / 1024 / 1024)         currsize,
       CEIL(blocks * blksize / 1024 / 1024) -
       CEIL((NVL(hwm, 1) * blksize) / 1024 / 1024)  savings
       --,'alter database datafile ''' || file_name || ''' resize ' ||
       --CEIL((NVL(hwm, 1) * blksize) / 1024 / 1024) || 'm;' cmd
  FROM DBA_DATA_FILES a,
       (SELECT file_id, MAX(block_id + blocks - 1) hwm
          FROM DBA_EXTENTS
         GROUP BY file_id) b,
       (SELECT TO_NUMBER(value) blksize
          FROM V$PARAMETER
         WHERE name = 'db_block_size')
 WHERE a.file_id = b.file_id(+)
   AND CEIL(blocks * blksize / 1024 / 1024) -
       CEIL((NVL(hwm, 1) * blksize) / 1024 / 1024) > 0
   AND TABLESPACE_NAME = 'USERS'
 ORDER BY 1, 2 desc;






阅读(6768) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~