相关视图:
dba_tablespaces、v$tablespace,dba_free_space
dba_data_files、v$datafile
dba_temp_files、v$tempfile

1.创建表空间

  1. SQL> create bigfile/smallfile tablespace example datafile '/opt/oracle/oradata/exam
  2. ple.dbf' size 10m autoextend on;
  3. Tablespace created.
  4. ---------------------------------------
  5. 数据库强制logging大于表空间logging
  6. create TABLESPACE fixf DATAFILE size 100m REUSE AUTOEXTEND ON NEXT 20m MAXSIZE UNLIMITED
  7. LOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO ;
  8. 创建表空间时压缩
  9. SQL> create bigfile/smallfile tablespace example datafile '/opt/oracle/oradata/exam
  10. ple.dbf' size 10m autoextend on DEFAULT COMPRESS FOR OLTP;

2.修改表压缩空间

  1. ALTER TABLESPACE USERS DEFAULT COMPRESS FOR OLTP;
  2. ALTER TABLESPACE USERS DEFAULT COMPRESS FOR BASIC;

3.修改数据文件路径,

1)使表空间脱机,2)拷贝文件到系统指定路径,3)指定新的表空间数据文件路径
注意在修改完数据文件的路径后,记得备份新的控制文件。

  1. SQL> alter tablespace example offline;
  2. Tablespace altered.
  3. ho cp /opt/oracle/oradata/example.dbf /opt/oracle/oradata/ORCLCDB/
  4. SQL> alter tablespace example rename datafile '/opt/oracle/oradata/example
  5. .dbf' to '/opt/oracle/oradata/ORCLCDB/example.dbf';
  6. ----------------------------------------------------------------------
  7. 备份控制文件
  8. alter database backup controlfile to trace;
  9. -------------------------------------------------------------------------

4.修改表空间名称。

  1. SQL> alter tablespace sample rename to test;
  2. Tablespace altered.

5.修改表空间文件大小

1)在表空间不足是可以多添加数据文件来扩充表空间。
2)也可以在原始表空间文件上面扩充文件大小。

  1. SQL> alter tablespace test add datafile '/opt/oracle/oradata/ORCLCDB/TEST.db
  2. f' size 30m ;
  3. SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf' r
  4. esize 30m ;
  5. Database altered.
  6. select * from dba_data_files;
  7. alter DATABASE datafile 33 resize 500m;

6.设置关闭/开启表空间自动扩展

  1. SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
  2. autoextend off ;
  3. Database altered.
  4. SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
  5. autoextend on ;
  6. Database altered.
  7. SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
  8. autoextend on next 20G ;
  9. select * from dba_data_files;
  10. alter DATABASE datafile 33 AUTOEXTEND ON NEXT 100M;

7.删除表空间

1).只删除表空间
2).删除表空间同时删除系统当中数据文件。

  1. SQL> drop tablespace test;
  2. Tablespace dropped.
  3. alter database datafile '/templv/osm/OSM_TABP_00.dbf' offline drop;
  4. SQL> drop tablespace example including contents;
  5. Tablespace dropped.
  6. 删除表空间并且删除系统当中数据文件
  7. drop TABLESPACE UNDOTBS03 INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

8.12c新功能直接移动或修改数据文件名

  1. 查看表空间
  2. select * from dba_tablespaces a,dba_data_files b
  3. where a.tablespace_name=b.tablespace_name ;
  4. ----------------------------------------------------------------
  5. 修改路径
  6. alter DATABASE move datafile '/opt/oracle/product/18c/dbhome_1/dbs/fixf'to
  7. '/opt/oracle/oradata/ORCLCDB/fixf.dbf';
  8. -----------------------------------------------------------------
  9. 重命名
  10. alter DATABASE move datafile
  11. '/opt/oracle/oradata/ORCLCDB/fixf.dbf'to
  12. '/opt/oracle/oradata/ORCLCDB/fix.dbf';

9.创建临时表空间

select name from v$tempfile;
select from dba_tablespaces where contents =’TEMPORARY’;
select
from dba_tablespace_groups;

  1. create TEMPORARY tablespace undotbs2 TEMPFILE ;
  2. create TEMPORARY tablespace temp3 TEMPFILE TABLESPACE group tempgrp; 创建并追加到组

10.修改临时表空间的组

  1. alter TABLESPACE temp3 tablespace GROUP tempgrp1;

11.修改数据库默认表空间组

  1. alter database DEFAULT TEMPORARY TABLESPACE tempgrp1;

12.删除临时表空间组

  1. alter database default temporary tablespace temp;修改数据库正在使用的临时表空间组
  2. alter tablespace temp3 tablespace group '';清除要删除表空间的组名称
  3. drop tablespace temp3 including contents and datafiles;删除临时表空间

13.创建undo表空间

  1. create undo tablespace undo1 DATAFILE ;

14.修改表空间脱机

  1. alter tablespace users offline normal;
  2. alter tablespace users offline temporary;
  3. alter tablespace users offline immediate;

15.OMF(Oracle管理的文件)

  1. db_create_file_dest:数据文件和临时文件的默认位置
  2. db_create_online_log_dest_n:重做日志和控制文件的创建位置
  3. db_recovery_file_dest:快速恢复区的默认位置
  4. db_recovery_file_dest_size: 快速恢复区的大小