第37章 存储结构

第37章 存储结构
表空间

查看表空间的名字
select tablespace_name,file_name from dba_data_files;
desc dna_tablespaces

select stablespace_name,contents,retention,bigfile from dba_tablespaces;

创建表空间
create bigfile|smallfile tablespace <> datafile '...' size <> autoextend on|off;

create tablespace a1 datafile '/u01/oralce/oradata/wyzc10g/a1.dbf' size 10m autoextend on maxsize 1g;

不指定路径和大小
alter session set db_create_file_dest='/u01/oracle/';
create tablespace a1;

放到asm中
create tablespace a1 datafile '+DB' size 10m;
当然如果指定名字也是可以的
create tablespace a1 datafile '+DB/a1.dbf' size 10m;

undo表空间
一个实例一个undo表空间
undo_tablespace=<>
create bigfile|smallfile undo tablespace <> datafiel ..
create undo tablespace undo1;
create undo tabllspace undo1 datafile '+db' size 10m autoextend on;

temporary临时表空间
create bigfile|smallfile temporary tablespace tempfile '....' size <> autoextend on

查看表空间的状态
select tablespace_name,status,online_status from dba_data_files;

只有系统表空间是system 其他的都是online

alter tablespace <> online|offline ;
alter tablespace <> read only| read write;

修改表空间的状态
alter tablespace users online;
alter tablespace users read only;
alter tablespace users read write;

#注意UNDO表空间和系统表空间是不能设置成offline的,辅助表空间是可以设置成offline的

查看表空间的read only 和 read write的状态

select file#,name,status,enabled from v$datafile;

修改表空间的状态
alter tablespace users read write|only;

数据文件脱机必须要是read only 条件下的,并且不能是undo表空间、零食表空间的和系统表空间的,然后
alter database datafile 4 offline;
查看文件状态
archive log list

表空间名字的修改
alter tablespace <> rename to <>;
alter tablespace users rename to user2;

表空间的删除
drop tablespace <>;

drop tablespcae <> including contents;
drop tablespace <> including contents and datafiles;

eg:
create tablespace a1 datafile '/u01/oracle/oradata/wyzc10g/a1.dbf' size 10m;
create table scott.a1 tablespace a1 as select * from scott.emp;
drop tablespace a1;
drop tablespace a1 including contens;
这个时候还会残留有数据文件
create tablespace a1 datafile '/u01/oracle/oradata/wyzc10g/a1.dbf' size 10m reuse;
drop tablespace a1 including contents and datafiles;
这样的操作过后数据文件才回彻底删除,可以查看一下试试
ho ls /u01/oracle/oradata/wyzc10g/a1.dbf

##总结
使用OMF和ASM的删除表空间的时候直接使用 drop tablespace a1 including contents;就行,否则就要加上and datafiles;系统表空间,默认使用用户表空间,undo表空间,默认使用临时表空间是不能删除的

猜你喜欢

转载自www.cnblogs.com/tudousix/p/9474213.html