查看表空间利用率及相关及脚本

本文介绍如何使用SQL查询来检查Oracle数据库中表空间的利用率,并提供创建、删除不同类型的表空间(如常规表空间、临时表空间和undo表空间)的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-- 查看表空间利用率

select
b.file_id file_id,
b.tablespace_name,
b.bytes,
b.maxbytes,
(b.bytes-sum(nvl(a.bytes,0))) used,
sum(nvl(a.bytes,0)) unused,
sum(nvl(a.bytes,0))/(b.bytes)*100 percentage
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_id,b.bytes,b.maxbytes
order by b.file_id;

or

select tablespace_name,sum(bytes)/1024/1024/1024 GB
from dba_data_files group by tablespace_name
union all
select tablespace_name,sum(bytes)/1024/1024/1024 GB
from dba_temp_files group by tablespace_name order by GB;

-- 查看数据文件表空间的对应关系

select t.name,t1.name
 from v$tablespace t,
    v$datafile t1
 where t.ts# = t1.ts#
;

-- 创建表空间

1.表空间

create tablespace tablespacename datafile 'datafilepath/datafilename ' size 10g;

--删除

drop tablespace tablespacename including contents and datafiles;--删除表空间及操作系统的数据文件

2.临时表空间

create temporary tablespace TEMP2 TEMPFILE ''/home2/oracle/oradata/sysmon/temp02.dbf'' SIZE 10

g;

-- 删除

drop tablespace temp including contents and datafiles;--删除临时表空间及操作系统的数据文件

3.undo表空间

create undo tablespace undotbs_01
 datafile '/u01/oracle/rbdb1/undo0201.dbf' size 2g;

-- 我们创建表空间时要以tbs_业务类型进行命名.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值