All about oracle smallfile and bigfile tablespace
Oracle表空间Tablespace是逻辑结构的最高层次,其他分别对应段对象segment、区extent和块block。而物理层面的Oracle
数据库是通过一系列的文件构成,其中数据文件datafile是与Tablespace进行对应的对象。
Tablespace与Datafile的关系是一对多的关系。一个表空间Tablespace可以对应多个Datafile,Datafile则是只能归属在一个Tablespace里。传统的
Oracle管理概念中,倡导一个表空间中创建多个数据文件,特别是创建分布在多个存储磁盘上,以期分散I/O。但是,Oracle10g推出的BigFile Tablespace大文件表空间,将这个概念有所变化。
1、 Bigfile tablespace
在Oracle10g中,推出了Bigfile tablespace的概念。表空间Tablespace从Oracle10g以后就分为两个类型,smallfile tablespace和bigfile tablespace。过去一个表空间对应多个数据文件我们成为Smallfile Tablespace。
10g 数据库在创建的时候,会指定默认的表空间类型。如果不特殊指定的话,默认为 SMALLFILE 类型的表空间。
======================================================================================
SYS@ orcl> select * from database_properties where property_name = 'DEFAULT_TBS_TYPE';
PROPERTY_NAME PROPERTY_VALU DESCRIPTION
------------------------------ ------------- --------------------------
DEFAULT_TBS_TYPE SMALLFILE Default tablespace type
## 可以设置默认的表空间类型。
SQL> ALTER DATABASE SET DEFAULT bigfile TABLESPACE;
======================================================================================
所谓Bigfile Tablespace最显著的差别就是一个表空间只能对应一个数据文件。Bigfile Tablespace虽只对应一个数据文件,但数据文件对应的最大体积大大增加。传统的small datafile每个文件中最多包括4M个数据块,按照一个数据块8K的大小核算,最大文件大小为32G。每个Small Tablespace理论上能够包括1024个数据文件,这样计算理论的最大值为32TB大小。而Bigfile Datafile具有更强大的数据块block容纳能力,最多能够包括4G个数据块。同样按照数据块8K计算,Bigfile Datafile大小为32KG=32TB。理论上small tablespace和big tablespace总容量相同。
下面我们通过一连串的实验来观察Bigfile Tablespace。
此处,我们通过create bigfile tablespace语句建立Bigfile Tablespace。注意两方面的问题,其一是Bigfile Tablespace必须使用local本地extent管理方式,不允许使用DMT(Dictionary Managed Tablespace)。另一方面是段segment空间使用auto自动方式,不要使用manual。
不过这两个条件在Undo或者临时Bigfile表空间的时候,是允许例外的。
Small Tablespace和Bigfile Tablespace是可以并存的。
===================================================================
SYS@ orcl> select tablespace_name, bigfile from dba_tablespaces;
TABLESPACE_NAME BIG
------------------------------ ---
SYSTEM NO
SYSAUX NO
UNDOTBS1 NO
TEMP NO
USERS NO
BTTEST YES
===================================================================
在创建bigfile tablespace的时候,就已经指定了数据文件。如果此时我们尝试加入一个新的数据文件,Oracle
系统会报错。
=================================================================================================
SYS@ orcl> alter tablespace bttest add datafile '/oradata/orcl/bttest2.dbf' size 10M autoextend off;
alter tablespace bttest add datafile '/oradata/orcl/bttest2.dbf' size 10M autoextend off
*
ERROR at line 1:
ORA-32771: cannot add file to bigfile tablespace
=================================================================================================
2、Bigfile的相对文件编号
此处我们观察一下Bigfile Tablespace体系下的一些特征。
=======================================================================
SYS@ orcl> select file_name, file_id, relative_fno from dba_data_files;
FILE_NAME FILE_ID RELATIVE_FNO
------------------------------ ---------- ------------
/ora