重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 5296|回复: 0
打印 上一主题 下一主题

[Oracle] oracle回收表空间文件大小

[复制链接]
跳转到指定楼层
楼主
发表于 2021-1-24 17:03:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1、查看表空间的使用情况:
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;

2、使用SQL生成回收表空间文件的命令:
select   'alter database datafile '''||a.file_name||''' resize '    ||round(a.filesize - (a.filesize - c.hwmsize-100) *0.8)||'M;',  
a.filesize,c.hwmsize
from  ( select file_id,file_name,round(bytes/1024/1024) filesize from dba_data_files ) a,
( select file_id,round(max(block_id)*8/1024) HWMsize from dba_extents group by file_id) c
where a.file_id = c.file_id   and a.filesize - c.hwmsize > 100;


3、执行上面生成的收回表空间文件的命令,进行表空间文件大小的回收,但回收时注意选择需要回收的表空间数据文件。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-9-29 06:39 , Processed in 0.163742 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表