oracle表空间管理

0. 创建表空间

create tablespace cloud datafile '/oracle/oradata/sky/cloud01.dbf' size 500M;

1. 表空间的删除

    (1) 删除空的表空间,但是不包含物理文件

drop tablespace tablespace_name;

    (2) 删除非空表空间,但是不包含物理文件

drop tablespace tablespace_name including contents;

    (3) 删除空表空间,包含物理文件

drop tablespace tablespace_name including datafiles;

    (4) 删除非空表空间,包含物理文件

drop tablespace tablespace_name including contents and datafiles;

    (5) 如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上cascade constraints

drop tablespace tablespace_name including contents and datafiles cascade constraints;

2. 增加表空间容量

    (1) 使用resize扩大原有的数据文件

alter database datafile '/oracle/oradata/sky/cloud02.dbf' resize 2g;

    (2) 增加数据文件

alter tablespace cloud add datafile '/oracle//oradata/sky/cloud03.dbf' size 2g;

3. 设置表空间是否自动扩展

    (1) 在添加数据文件时设置表空间为自动扩展(12c默认是不自动扩展)

alter tablespace cloud add datafile '/oracle//oradata/sky/cloud03.dbf' size 2g autoextend on ;

alter tablespace cloud add datafile '/oracle//oradata/sky/cloud03.dbf' size 2g autoextend on next 200M maxsize unlimited;

alter tablespace cloud add datafile '/oracle//oradata/sky/cloud03.dbf' size 2g autoextend on next 200M maxsize 8g;

    (2) 现有数据文件文件设置自动增长

alter database datafile '/oracle/oradata/sky/cloud02.dbf' autoextend on;

    (3) 现有数据文件文件设置非自动增长

alter database datafile '/oracle/oradata/sky/cloud02.dbf' autoextend off;

4. 修改用户默认表空间    

alter user cloud default tablespace cloud;

5. 查询表空间使用率

SELECT upper(f.tablespace_name) "表空间名",
       d.total "表空间大小(M)",
       d.total - f.total_bytes "已使用空间(M)",
       to_char(round((d.total -f.total_bytes) / d.total *100,2),'990.99') "使用率",
       f.total_bytes "空闲空间(M)",
       f.max_bytes "最大块(M)"
 FROM     
    (SELECT tablespace_name,
            round(SUM(bytes)/(1024*1024),2)total_bytes,
            round(MAX(bytes)/(1024*1024),2)max_bytes
      FROM sys.dba_free_space
     GROUP BY tablespace_name) f,
    (SELECT dd.tablespace_name, round(SUM(dd.bytes)/(1024*1024),2) total
      FROM  sys.dba_data_files dd
      GROUP BY dd.tablespace_name) d
WHERE d.tablespace_name =f.tablespace_name   
ORDER BY 4 DESC;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

sky@sea

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

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

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

打赏作者

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

抵扣说明:

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

余额充值