假定需要创建表空间s及数据文件
sql> CREATE TABLESPACE s; /*收到了错误信息*/
create tablespace s
*
ERROR at line 1:
ORA-02199: missing DATAFILE/TEMPFILE clause
sql> show parameter db_create_file /*查看db_create_file_dest参数*/
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string
--设定db_create_file_dest参数
sql> ALTER SYSTEM SET db_create_file_dest = '/u01/app/oracle/oradata/orcl';
System altered.
--设定参数后,创建成功
sql> CREATE TABLESPACE s;
Tablespace created.
sql> SELECT NAME FROM v$datafile; /*可以看到ORCL/datafile/o1_mf_s_5vrl1t7h_.dbf是Oralce自动创建的数据文件*/
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
/u01/app/oracle/oradata/orcl/Test.dbf
/u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_s_5vrl1t7h_.dbf
/*查看物理文件,缺省为MB*/
sql> ho ls -lh /u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_s_5vrl1t7h_.dbf
-rw------- 1 oracle oinstall 101M Apr 7 16:54 /u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_s_5vrl1t7h_.dbf
sql> CREATE TABLESPACE t DATAFILE SIZE 10m; /*也可指定数据文件的大小为MB*/
sql> SELECT NAME FROM v$datafile;
/u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_t_5vrlgqtl_.dbf
sql> ho ls -lh /u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_t_5vrlgqtl_.dbf
-rw------- 1 oracle oinstall 11M Apr 7 17:01 /u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_t_5vrlgqtl_.dbf
--删除表空间时,对于使用了OMF生成的数据文件将随着表空间的删除一起被删除
sql> DROP TABLESPACE t;
Tablespace dropped.
--查看物理文件,已经不存在
ls: /u01/app/oracle/oradata/orcl/ORCL/datafile/o1_mf_t_5vrlgqtl_.dbf: No such file or directory
--对于未采用OMF来创建的表空间,在删除表空间之后,其数据文件并没有删除,v$datafile视图中被删除
--下面是未使用OMF创建的x表空间及数据文件
sql> CREATE TABLESPACE x DATAFILE '/u01/app/oracle/oradata/orcl/x.dbf' SIZE 10m;
sql> SELECT NAME FROM v$datafile;
/u01/app/oracle/oradata/orcl/x.dbf
sql> DROP TABLESPACE x;
Tablespace dropped.
sql> SELECT NAME FROM v$datafile; /*视图中已不存在x.dbf的数据文件*/
sql> ho ls /u01/app/oracle/oradata/orcl/x.dbf /*操作系统中依然存在*/
--使用下面的方法重建x表空间,然后使用including contents and datafiles 彻底删除表空间及物理文件
sql> CREATE TABLESPACE X DATAFILE '/u01/app/oracle/oradata/orcl/x.dbf' REUSE;
sql> DROP TABLESPACE x INCLUDING CONTENTS AND DATAFILES;
sql> ho ls /u01/app/oracle/oradata/orcl/x.dbf
ls: /u01/app/oracle/oradata/orcl/x.dbf: No such file or directory
1.使用ALTER SYSTEM SET db_create_file_dest = '<path>'设置路径
2.查看刚刚的设置SHOW PARAMETER db_create_file_dest;
3.创建表空间及数据文件CREATE TABLESPACE tablespace_name
4.单独创建表空间CREATE TABLESPACE <> DATAFILE '<path>' SIZE <>;
5.也可以创建undo和temporary tablespace 。CREATE UNDO TABLESPACE tablespace_name ;CREATE TEMPORARY TABLESPACE tablespace_name;
6.删除表空间DROP TABLESPACE tablespace_name ;OMF情况下则删除物理文件,等效于未使用OMF创建,使用INCLUDING CONTENTS AND DATAFILES 删除方式
原文链接:https://www.f2er.com/oracle/212509.html