常用空间维护SQL

本文介绍了如何使用SQL查询数据库的使用空间情况,包括查看整个数据库的总空间、数据文件使用、SCHEMA空间占用、特定表空间及表的大小,以及表空间碎片和移动对象的表空间操作。
摘要由CSDN通过智能技术生成

一、查看整个数据库使用总空间

select sum("file_size(M)") as "total_size(M)" from (
select 'SPFILE' as "file_type",value as "file_name",1 as "file_size(M)" from v$parameter where  name ='spfile'
UNION
select 'CONTROL' as "file_type",name as "file_name",round(BLOCK_SIZE*FILE_SIZE_BLKS/1024/1024,2) as "file_size(M)" from v$controlfile
UNION
select  'REDOLOG' as "file_type",v$logfile.member as "file_name",round(v$log.bytes/1024/1024,2) as "file_size(M)" from v$log,v$logfile where v$log.group#=v$logfile.group#
UNION
select 'TEMP' as "file_type",name as "file_name",round(bytes/1024/1024,2) as "file_size(M)" from v$tempfile
UNION
select 'DATAFILE' as "file_type",name as "file_name",round(bytes/1024/1024,2) as "file_size(M)" from v$datafile
);


二、查看数据库中各个文件占用的系统空间

select * from (
select 'SPFILE' as "file_type",value as "file_name",1 as "file_size(M)" from v$parameter where  name ='spfile'
UNION
select 'CONTROL' as "file_type",name as "file_name",round(BLOCK_SIZE*FILE_SIZE_BLKS/1024/1024,2) as "file_size(M)" from v$controlfile
UNION
select  'REDOLOG' as "file_type",v$logfile.member as "file_name",round(v$log.bytes/1024/1024,2) as "file_size(M)" from v$log,v$logfile where v$log.group#=v$logfile.group#
UNION
select 'TEMP' as "file_type&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值