表空间的创建、日常维护管理

01 创建数据表空间

 

本地管理的表空间:

create tablespace test01 
  datafile '/oracle/oradata/orcl/test01a.dbf' 
  size 2m 
  autoextend off 
  segment space management auto;

  

autoextend off —不自动扩展

segment space management auto —自动段管理,推荐

 

不自动扩展表空间

CREATE TABLESPACE test02 LOGGING DATAFILE 
  '/oracle/oradata/orcl/test02a.dbf' SIZE 2M AUTOEXTEND OFF, 
  '/oracle/oradata/orcl/test02b.dbf' SIZE 2M AUTOEXTEND OFF 
  EXTENT MANAGEMENT LOCAL 
  SEGMENT SPACE MANAGEMENT AUTO;

  

自动扩展表空间

CREATE TABLESPACE test03 LOGGING DATAFILE 
    '/oracle/oradata/orcl/test03a.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M, 
    '/oracle/oradata/orcl/test03b.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M 
    EXTENT MANAGEMENT LOCAL 
    SEGMENT SPACE MANAGEMENT AUTO;

  

 创建大表空间:

CREATE BIGFILE TABLESPACE bigtbs DATAFILE 
    '/u02/oracle/data/bigtbs01.dbf' SIZE 50G;

  

02 创建临时表空间

create temporary tablespace temp1 
    tempfile '/oracle/oradata/orcl/temp1.dbf' size 5m autoextend off;

  

03 创建UNDO表空间

create undo tablespace testundo1 
    datafile '/oracle/oradata/orcl/testundo1.dbf' size 2m autoextend off;

  

04 表空间的扩展与修改大小

表空间添加数据文件

alter tablespace temp1 
    add tempfile '/oracle/oradata/orcl/temp1b.dbf' size 5m autoextend off;

  

alter tablespace test01 
    add datafile '/oracle/oradata/orcl/test01b.dbf' size 1m autoextend off;

  

修改表空间文件大小

alter database 
    datafile '/oracle/oradata/orcl/test02b.dbf' resize 2m;

  

select name, bytes from v$tempfile;

  

alter database 
    tempfile '/oracle/oradata/orcl/temp1.dbf' resize 5m;

 

05 表空间重命名

ALTER TABLESPACE test03 RENAME TO test04;

  

06 删除表空间

drop tablespace testundo1; -- 直接删除表空间,而不删除对应的数据文件

  

drop tablespace test04 including contents and datafiles; --加上该选项 则连同数据文件 一起删除了

  

如果出现:ORA-02449: unique/primary keys in table referenced by foreign keys

 

select p.owner,

  p.table_name,

  p.constraint_name,

  f.table_name referencing_table,

  f.constraint_name foreign_key_name,

  f.status fk_status

from dba_constraints P,

  dba_constraints F,

  dba_tables T

where p.constraint_name = f.r_constraint_name

  and f.constraint_type = 'R'

  and p.table_name = t.table_name

  and t.tablespace_name = UPPER('&tablespace_name')

order by 1,2,3,4,5;

  

删除表空间和对应的表空间文件

drop tablespace test04 including contents and datafiles cascade constraints;

  

07 更改表空间的读写模式

alter tablespace test01 read only; --test01表空间只读
alter tablespace test01 read write;--test01表空间可读写

  

查看表空间的状态

select tablespace_name,status from dba_tablespaces;

  

表的读写模式

alter table test read only;--让表只读
alter table test read write;--让表可读写

  

08 更改表空间的在线模式

alter tablespace users offline;--离线user表空间

alter database datafile 6 offline;--离线6号数据文件

alter database datafile 6 offline for drop;--离线6号数据文件,并需要恢复

alter database datafile 6 online;--使6号文件在线

recover datafile 6;--恢复6号文件

   

 

转载于:https://www.cnblogs.com/black-start/p/11021675.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值