相关视图:
dba_tablespaces、v$tablespace,dba_free_space
dba_data_files、v$datafile
dba_temp_files、v$tempfile
1.创建表空间
SQL> create bigfile/smallfile tablespace example datafile '/opt/oracle/oradata/exam
ple.dbf' size 10m autoextend on;
Tablespace created.
---------------------------------------
数据库强制logging大于表空间logging
create TABLESPACE fixf DATAFILE size 100m REUSE AUTOEXTEND ON NEXT 20m MAXSIZE UNLIMITED
LOGGING EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO ;
创建表空间时压缩
SQL> create bigfile/smallfile tablespace example datafile '/opt/oracle/oradata/exam
ple.dbf' size 10m autoextend on DEFAULT COMPRESS FOR OLTP;
2.修改表压缩空间
ALTER TABLESPACE USERS DEFAULT COMPRESS FOR OLTP;
ALTER TABLESPACE USERS DEFAULT COMPRESS FOR BASIC;
3.修改数据文件路径,
1)使表空间脱机,2)拷贝文件到系统指定路径,3)指定新的表空间数据文件路径
注意在修改完数据文件的路径后,记得备份新的控制文件。
SQL> alter tablespace example offline;
Tablespace altered.
ho cp /opt/oracle/oradata/example.dbf /opt/oracle/oradata/ORCLCDB/
SQL> alter tablespace example rename datafile '/opt/oracle/oradata/example
.dbf' to '/opt/oracle/oradata/ORCLCDB/example.dbf';
----------------------------------------------------------------------
备份控制文件
alter database backup controlfile to trace;
-------------------------------------------------------------------------
4.修改表空间名称。
SQL> alter tablespace sample rename to test;
Tablespace altered.
5.修改表空间文件大小
1)在表空间不足是可以多添加数据文件来扩充表空间。
2)也可以在原始表空间文件上面扩充文件大小。
SQL> alter tablespace test add datafile '/opt/oracle/oradata/ORCLCDB/TEST.db
f' size 30m ;
SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf' r
esize 30m ;
Database altered.
select * from dba_data_files;
alter DATABASE datafile 33 resize 500m;
6.设置关闭/开启表空间自动扩展
SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
autoextend off ;
Database altered.
SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
autoextend on ;
Database altered.
SQL> alter database datafile '/opt/oracle/oradata/ORCLCDB/TEST.dbf'
autoextend on next 20G ;
select * from dba_data_files;
alter DATABASE datafile 33 AUTOEXTEND ON NEXT 100M;
7.删除表空间
1).只删除表空间
2).删除表空间同时删除系统当中数据文件。
SQL> drop tablespace test;
Tablespace dropped.
alter database datafile '/templv/osm/OSM_TABP_00.dbf' offline drop;
SQL> drop tablespace example including contents;
Tablespace dropped.
删除表空间并且删除系统当中数据文件
drop TABLESPACE UNDOTBS03 INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
8.12c新功能直接移动或修改数据文件名
查看表空间
select * from dba_tablespaces a,dba_data_files b
where a.tablespace_name=b.tablespace_name ;
----------------------------------------------------------------
修改路径
alter DATABASE move datafile '/opt/oracle/product/18c/dbhome_1/dbs/fixf'to
'/opt/oracle/oradata/ORCLCDB/fixf.dbf';
-----------------------------------------------------------------
重命名
alter DATABASE move datafile
'/opt/oracle/oradata/ORCLCDB/fixf.dbf'to
'/opt/oracle/oradata/ORCLCDB/fix.dbf';
9.创建临时表空间
select name from v$tempfile;
select from dba_tablespaces where contents =’TEMPORARY’;
select from dba_tablespace_groups;
create TEMPORARY tablespace undotbs2 TEMPFILE ;
create TEMPORARY tablespace temp3 TEMPFILE TABLESPACE group tempgrp; 创建并追加到组
10.修改临时表空间的组
alter TABLESPACE temp3 tablespace GROUP tempgrp1;
11.修改数据库默认表空间组
alter database DEFAULT TEMPORARY TABLESPACE tempgrp1;
12.删除临时表空间组
alter database default temporary tablespace temp;修改数据库正在使用的临时表空间组
alter tablespace temp3 tablespace group '';清除要删除表空间的组名称
drop tablespace temp3 including contents and datafiles;删除临时表空间
13.创建undo表空间
create undo tablespace undo1 DATAFILE ;
14.修改表空间脱机
alter tablespace users offline normal;
alter tablespace users offline temporary;
alter tablespace users offline immediate;
15.OMF(Oracle管理的文件)
db_create_file_dest:数据文件和临时文件的默认位置
db_create_online_log_dest_n:重做日志和控制文件的创建位置
db_recovery_file_dest:快速恢复区的默认位置
db_recovery_file_dest_size: 快速恢复区的大小