[置頂] Oracle 資料庫資料表空間容量調整(資料表空間縮容指令碼)指令碼

來源:互聯網
上載者:User

--1、擷取需要釋放空間的資料表空間資訊(包含oracle database自有資料表空間)
--drop table system.tbs_detail;

create table system.tbs_detail as select

a.tablespace_name,

a.bytes/1024/1024 "Sum_MB",

(a.bytes-b.bytes)/1024/1024 "used_MB",

b.bytes/1024/1024 "free_MB",

round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"   

from

(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,    

(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b    

where a.tablespace_name=b.tablespace_name    

order by ((a.bytes-b.bytes)/a.bytes) desc;

--select * from system.tbs_detail order by "Sum_MB" desc,"free_MB" desc;

--2、擷取需要釋放空間的應用資料表空間資料檔案使用方式

--drop table system.datafile_space;

create table system.datafile_space as 

select a.TABLESPACE_NAME,

       a.FILE_NAME,

       a.BYTES / 1024 / 1024 total,

       b.sum_free / 1024 / 1024 free

  from dba_data_files a,

       (select file_id, sum(bytes) sum_free

          from dba_free_space

         group by file_id) b

 where a.FILE_ID = b.file_id

   and a.TABLESPACE_NAME in (select tablespace_name

                               from system.tbs_detail

                              where (tablespace_name like '%CQLT%' or

                                    tablespace_name like '%CQST%'

                                    or tablespace_name like 'TS%' or tablespace_name like 'IDX%'

                                    or tablespace_name like '%HX%')

                                and "Sum_MB" > 100);

--select * from system.datafile_space;

                                

--3、產生資料檔案大小重設指令碼,在每個資料檔案當前實際使用空間大小基礎上增加 100m 空間

select 'alter database datafile ''' || file_name || ''' resize ' ||

      round(to_number(total - free + 100),0) || ' M;'

  from system.datafile_space;

  

--查看 ASM 磁碟組使用方式

sqlplus / as sysdba <<EOF

set feed off

set linesize 200

set pagesize 200

set echo off

spool /home/oracle/check_log/chktbs.log append

select name,state,type,total_mb,free_mb from v\$asm_diskgroup;

spool off

quit

EOF

 

轉載請註明作者出處及原文連結,否則將追究法律責任:

作者:xiangsir

原文連結:http://blog.csdn.net/xiangsir/article/details/9002201

QQ:444367417

MSN:xiangsir@hotmail.com

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.