Chinaunix首页 | 论坛 | 博客
  • 博客访问: 832703
  • 博文数量: 199
  • 博客积分: 6363
  • 博客等级: 准将
  • 技术积分: 2225
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-28 10:01
个人简介

来自农村的老实娃

文章分类

全部博文(199)

文章存档

2017年(1)

2014年(2)

2013年(3)

2012年(6)

2011年(26)

2010年(34)

2009年(50)

2008年(44)

2007年(33)

我的朋友

分类: Oracle

2010-12-01 14:56:59

把datafile的size用resize方法变成最小
SQL> set verify off
column file_name format a50 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column currsize format 999,990 heading "Current|Size"
column savings  format 999,990 heading "Poss.|Savings"
break on report
compute sum of savings on report
column value new_val blksize
1)Oracle block的大小
SQL>select value from v$parameter where name = 'db_block_size';
VALUE
--------------------------------------------------------------------------------
8192
2)算出每个文件的信息
select 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
from dba_data_files a,
     ( select file_id, max(block_id+blocks-1) hwm
         from dba_extents
        group by file_id ) b
where a.file_id = b.file_id(+)
/
                                                  Smallest
                                                       Size  Current    Poss.
FILE_NAME                                             Poss.     Size  Savings
-------------------------------------------------- -------- -------- --------
/oracle/oradata/orcl/system01.dbf                       705      710        5
/oracle/product/10.2.0/db_1/dbs/tivoliorts.dbf            2      250      248
/oracle/oradata/orcl/sysaux01.dbf                       764      810       46
/oracle/oradata/orcl/users01.dbf                          2        5        3
/oracle/oradata/orcl/undotbs01.dbf                       87      100       13
/oracle/ts_cus/ts_cus.dbf                                 2      100       98
/oracle/oradata/orcl/dyx                                  1
/oracle/oradata/orcl/ddd.ora                              1
/oracle/oradata/orcl/testtb.dbf                           1
                                                   Smallest
                                                       Size  Current    Poss.
FILE_NAME                                             Poss.     Size  Savings
-------------------------------------------------- -------- -------- --------
                                                                     --------
sum                                                                       413
 
3)动态生成resizesql语句
column cmd format a75 word_wrapped
select '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
where a.file_id = b.file_id(+)
  and ceil( blocks*&&blksize/1024/1024) -
      ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/
SQL>
CMD
---------------------------------------------------------------------------
alter database datafile '/oracle/oradata/orcl/system01.dbf' resize 705m;
alter database datafile '/oracle/product/10.2.0/db_1/dbs/tivoliorts.dbf' resize 2m;
alter database datafile '/oracle/oradata/orcl/sysaux01.dbf' resize 764m;
alter database datafile '/oracle/oradata/orcl/users01.dbf' resize 2m;
alter database datafile '/oracle/oradata/orcl/undotbs01.dbf' resize 87m;
alter database datafile '/oracle/ts_cus/ts_cus.dbf' resize 2m;
6 rows selected.
阅读(11237) | 评论(0) | 转发(1) |
0

上一篇:动态视图字段说明

下一篇:释放TEMP

给主人留下些什么吧!~~