【Oracle日常积累】Oracle表空间扩展

用户生产系统运行一段时间后,表空间已经耗尽,只有扩展表空间,才能继续在表空间上添加表数据。

1.先去查询表空间的使用情况及使用百分比

select a.tablespace_name "表空间名",
       a.bytes / 1024 / 1024 "表空间大小(m)",
       (a.bytes - b.bytes) / 1024 / 1024 "已使用空间(m)",
       b.bytes / 1024 / 1024 "空闲空间(m)",
       round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用%比"
  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.查询表空间名,文件名,是否自动扩展,表空间大小及最大空间

select t.tablespace_name,
       d.file_name,
       d.autoextensible,
       d.bytes,
       d.maxbytes,
       d.status
  from dba_tablespaces t, dba_data_files d
 where t.tablespace_name = d.tablespace_name
 order by tablespace_name, file_name;

3.表空间扩容

注意:一个数据文件最大只能32G

3.1 方法一

--手工改变已存在数据文件的大小
alter tablespace test_comm add datafile'd:\oracle\product\10.2.0\oradata\hisdb\test01.dbf' size 20480m;

3.2 方法二

--允许已存在的数据文件自动增长
alter database datafile 'd:\oracle\product\10.2.0\oradata\hisdb\test01.dbf'autoextend on next 100m maxsize 20480m; 

3.3 方法三

--增加数据文件
 /* 其中设置的每个文件初始分配空间为7g, autoextend on为自动增长大小,oracle单个文件大小最大不超过32g*/
 /*说明1:sql脚本(增加两个数据文件,需要扩容的表空间是test_comm)*/
 /*说明2:
  /data/oracle/tablespace/msg21.dbf -文件名及存放路径
  size -表空间的大小
  utoextend -是否开启自动扩展,on开启
*/
alter tablespace test_comm add datafile '/data/oracle/tablespace/test02.dbf' size 7167m autoextend on ;
alter tablespace test_comm add datafile '/data/oracle/tablespace/test03.dbf' size 7167m autoextend on ;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Aries·Zhao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值