数据文件一旦追加到某个表空间后就不能删除该数据文件了,如果要删除数据文件,只能删除其所属的表空间。
数据文件的使用原则:
1.少量大数据文件优于大量小数据文件。
2.maxdatafiles 可以指定控制文件中数据文件所预留的空间,默认为32.
3.db_file限制了数据库可以同时打开的最大数据文件个数。
4.最好将数据文件和重做日志文件分布在不同的盘上
段:
用于存储特定的逻辑对象的所有数据。
段名和对象名相同
表段、索引段、undo段、临时段。
undo段:存放旧值
临时段:用于存放排序产生的临时数据。
区:一次分配最小单位
块:一次IO的最小单位
system表空间:用于存放数据字典和system回滚段的。
sysaux :存放oracle产品和特征信息的
表空间建议:
不同类型的数据存放在不同的表空间
建立专门存放表的数据表空间,存放索引的索引表空间,存放undo段的undo 表空间,临时数据的临时表空间。
应用工具的 lob段数据的
本地管理表空间不需要合并空间碎片,会自动合并。而字典管理需要。
create tablespace user01 datafile='.............' size 2m uniform. size 128k
uniform. 为分配区的大小
autoallocate 自动分配区大小。
不能使用default storage 选项
大文件表空间:
可以显著提高数据库的存储能力,create bigfile tablespace 不能使用数据字典管理。
建立undo表空间:
对于混合系统来说,多undo表空间比较有利
create undo tablespace undotbs2 datafile '...........'size 10m
临时表空间:
create temporary tablespace temp01 tempfile '.............' size 5m uniform. size 256k
大文件临时表空间:
create bigfile temporary tablespace temp02 tempfile '.............' size 5m;
临时表空间组:
最后加入:tablespace group group1
修改制定组:alter tablespace temp tablespace group group2;
删除组中的临时表空间:alter tablespace temp03 tablespace group '';
非标准块表空间:
1.分配非标准数据高速缓存:
alter system set db_cache_size=20M;
alter system set db_8k_cache_size=4M;
2.create tablespace tbs_8k datafile '.............' size 2M blocksize 8k
管理表空间:
改变表空间可用性
alter tablespace test offline;
alter database datafile '.........' offline
offline后,直接online是不可以的,必须先recover 后才能起
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' online;
alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/u01/app/oracle/oradata/xie/test01.dbf'
SQL> recover datafile '/u01/app/oracle/oradata/xie/test01.dbf';
Media recovery complete.
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' online;
Database altered.
SQL>
如果是非归档则不可以直接offline
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' offline;
alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' offline
*
ERROR at line 1:
ORA-01145: offline immediate disallowed unless media recovery enabled
必须使用offline drop选项
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test01.dbf' offline drop;
Database altered.
表空间只读:
SQL> alter tablespace test read only;
Tablespace altered.
SQL> alter tablespace test read write;
Tablespace altered.
表空间改名:
SQL> alter tablespace test rename to test1;
Tablespace altered.
设置数据库默认表空间:
alter database default tablespace users;
设置数据库默认临时表空间:
alter database default temporary tablespace temp01
删除表空间及其对象和数据文件:
drop tablespace temp include contents and datafiles;
扩展表空间:
1.增加数据文件:
SQL> alter tablespace test1 ADD DATAFILE '/u01/app/oracle/oradata/xie/test02.dbf' size 100m;
Tablespace altered.
2.手工扩展
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test02.dbf' resize 110m;
Database altered.
SQL> alter database datafile '/u01/app/oracle/oradata/xie/test02.dbf' resize 20m;
Database altered.
3.允许表空间自动扩展
alter database datafile '.......' autoextend on next 10m maxsize 1G;
移动数据文件:
open状态下:不能移动system表空间
SQL> select tablespace_name from dba_data_files where file_name='/u01/app/oracle/oradata/xie/test02.dbf';
TABLESPACE_NAME
------------------------------
TEST1
SQL> alter tablespace test1 offline;
Tablespace altered.
SQL> host mv /u01/app/oracle/oradata/xie/test02.dbf /u01/app/oracle/oradata/xie/test03.dbf;
SQL> alter tablespace test1 rename datafile '/u01/app/oracle/oradata/xie/test02.dbf' to '/u01/app/oracle/oradata/xie/test03.dbf';
Tablespace altered.
SQL> alter tablespace test1 online;
Tablespace altered.
mount下:可以移动任何
查询:
v$tablespace dba_tablespaces user_tablespaces;
SQL> select * from v$tablespace;
TS# NAME INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
0 SYSTEM YES NO YES
1 UNDOTBS1 YES NO YES
2 SYSAUX YES NO YES
3 TEMP NO NO YES
4 USERS YES NO YES
5 TEST1 YES NO YES
inc 全备份时是否包含此表空间
big 是否为大文件
fla 是否支持闪回
SQL> col file_name format A40;
SQL> select file_name,bytes,maxbytes,autoextensible from dba_data_files where tablespace_name='TEST1';
FILE_NAME BYTES MAXBYTES AUT
---------------------------------------- ---------- ---------- ---
/u01/app/oracle/oradata/xie/test01.dbf 104857600 0 NO
/u01/app/oracle/oradata/xie/test03.dbf 20971520 0 NO
查询数据文件检查点时scn
SQL> select name,checkpoint_time,checkpoint_change# from v$datafile;
NAME CHECKPOINT_T CHECKPOINT_CHANGE#
----------------------------------- ------------ ------------------
/u01/app/oracle/oradata/xie/system0 30-DEC-10 709466
1.dbf
/u01/app/oracle/oradata/xie/undotbs 30-DEC-10 709466
01.dbf
/u01/app/oracle/oradata/xie/sysaux0 30-DEC-10 709466
1.dbf
/u01/app/oracle/oradata/xie/users01 30-DEC-10 709466
.dbf
NAME CHECKPOINT_T CHECKPOINT_CHANGE#
----------------------------------- ------------ ------------------
/u01/app/oracle/oradata/xie/test01. 30-DEC-10 711157
dbf
/u01/app/oracle/oradata/xie/test03. 30-DEC-10 711157
dbf
6 rows selected.
临时表空间组:
dba_tablespace_groups;
临时表空间的数据文件:
dba_temp_files;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15799689/viewspace-687362/ ,如需转载,请注明出处,否则将追究法律责任。