您的位置:首页 > 数据库 > Oracle

表空间脚本[置顶] Oracle 数据库表空间容量调整(表空间缩容脚本)脚本

2013-06-01 21:06 295 查看
最近研究表空间脚本,稍微总结一下,以后继续补充:

--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

文章结束给大家分享下程序员的一些笑话语录:

真正的程序员喜欢兼卖爆米花,他们利用CPU散发出的热量做爆米花,可以根据米花爆裂的速度听出正在运行什么程序。

---------------------------------
原创文章 By
表空间和脚本
---------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: