DB_FILES参数限制数据文件的数量
SQL> show parameter db_files
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_files integer 200
创建数据文件的方式(6种)
create tablespace:创建表空间的同时创建数据文件
create temporary tablespace :创建临时表空间的同时创建数据文件
create database :创建数据库的同时创建数据文件
alter database...create datafile:数据库恢复时,新建一个数据文件取代出错的数据文件
alter tablespace...add datafile:向表空间中添加一个数据文件
alter tablespace.. add tempfile:向临时表空间添加一个临时数据文件
SQL> alter tablespace users add datafile '/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf' size 20M;
SQL> alter tablespace temp add tempfile '/opt/oracle/oradata/ORCL/datafile/temp01.dbf' size 20M;
设置数据文件为自动增长模式
SQL> alter tablespace users add datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' size 10M autoextend on next 512K maxsize 50m;
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' autoextend on next 512K maxsize unlimited;
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' autoextend off;
手动改变数据文件的大小
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' resize 8M;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/user01.dbf ONLINE
(1)归档模式下数据文件可用性的改变
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' offline;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/user01.dbf RECOVER
SQL> recover datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf';
Media recovery complete.
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' online;
(2)非归档模式下数据文件可用性的改变
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1272600 bytes
Variable Size 130024680 bytes
Database Buffers 33554432 bytes
Redo Buffers 2920448 bytes
Database mounted.
SQL> alter database noarchivelog;
SQL> alter database open;
SQL> alter database datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' offline for drop; ---在非归档模式下,除非数据文件损坏才可以执行此操作
(3)改变表空间中所有的数据文件的可用性
SQL> alter tablespace users datafile offline;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf RECOVER
/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf RECOVER
/opt/oracle/oradata/ORCL/datafile/user01.dbf RECOVER
SQL> recover tablespace users; --必须
Media recovery complete.
SQL> alter tablespace users datafile online;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/user01.dbf ONLINE
(1)改变同一个表空间的数据文件的名称和位置
使表空间处于脱机状态
SQL> alter tablespace users offline;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf OFFLINE
/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf OFFLINE
/opt/oracle/oradata/ORCL/datafile/user01.dbf OFFLINE
在操作系统移动数据文件
对表空间的数据文件进行重命名
SQL> alter tablespace users rename datafile '/opt/oracle/oradata/ORCL/datafile/o1_mf_users_8hs65hmd_.dbf' to '/opt/oracle/oradata/ORCL/datafile/users/o1_mf_users_8hs65hmd_.dbf';
SQL> alter tablespace users rename datafile '/opt/oracle/oradata/ORCL/datafile/haoxiaoyu01.dbf' to '/opt/oracle/oradata/ORCL/datafile/users/haoxiaoyu01.dbf';
SQL> alter tablespace users rename datafile '/opt/oracle/oradata/ORCL/datafile/user01.dbf' to '/opt/oracle/oradata/ORCL/datafile/users/user01.dbf';
表空间联机
SQL> alter tablespace users online;
SQL> select name,status from v$datafile;
NAME STATUS
-------------------------------------------------------------------------------- -------
/opt/oracle/oradata/ORCL/datafile/o1_mf_system_8hs63rgd_.dbf SYSTEM
/opt/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_8hs64fpt_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/o1_mf_sysaux_8hs64ow1_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/users/o1_mf_users_8hs65hmd_.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/users/haoxiaoyu01.dbf ONLINE
/opt/oracle/oradata/ORCL/datafile/users/user01.dbf ONLINE
(2)改变属于多个表空间的数据文件
如果数据文件不在同一个表空间
1.关闭数据库
2.在操作系统移动数据文件到新的地方
3.启动到mount状态
4.执行alter database rename file ...to ....
5.打开数据库
删除数据文件的约束:
数据库运行在开启状态
数据文件或者临时数据文件必须是空的
不能删除表空间的第一个或最后一个数据文件或临时数据文件
不能删除只读表空间中的数据文件
不能删除system表空间的数据文件
不能删除采用本地管理的处于脱机状态的数据文件
SQL> alter tablespace users drop datafile '/opt/oracle/oradata/ORCL/datafile/users/user01.dbf';
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/ORCL/datafile/o1_mf_temp_8hs64vg1_.tmp
/opt/oracle/oradata/ORCL/datafile/temp01.dbf
SQL> alter tablespace temp drop tempfile '/opt/oracle/oradata/ORCL/datafile/temp01.dbf';
SQL> select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/ORCL/datafile/o1_mf_temp_8hs64vg1_.tmp
dba_data_files:包括数据库中所有数据文件的信息,包括所属表空间,数据文件编号等
dba_temp_files:临时数据文件信息
dba_extents:所有表空间中已分配区的描述信息
user_extents:包含当前用户所拥有的对象在所有表空间中已分配区的描述信息
dba_free_space:所有的表空间的空闲区的描述信息
user_free_space:当前用户可访问的表空间中空闲区的描述信息
v$datafile:包含从控制文件中获取的数据文件信息
v$tempfile:临时文件的基本信息
v$datafile_header:从数据文件头部获取的信息