1、块(block)
oracle存储的最小单位,默认块大小是8K,可通过“show parameter db_block_size”查看,数据库建立后不可修改
2、区(extent)
多个数据块(block)组成区,区也是oracle进行空间扩展的最小单位。如下图所示,一个区含有8个块,故区的大小为:8 * 8192 = 65536
但区含有块的个数是不确定的
3、段
数据段是与数据库对象相对应,一般一个数据库对象对应一个数据段。多个extent是对应一个数据段,每个数据段就是数据库一个对象。表、索引、回滚、聚集这些都是数据段的一种表现形式
如下图所示,从segment_type可以看出,CM_DG_MIFENG_HISTORY是一张表,而每一行数据即为一个区,一个段由多个区组成。
4、表空间
建立一个表空间需要指定存储的文件。一个表空间可以指定多个数据文件,多个文件可以在不同的物理存储上。
4.1、创建默认表空间:
create tablespace tablespaceName datafile ‘/tablespace/tablespaceName01.dbf’ size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
一个表空间指定多个数据文件(表空间名字一样,文件路径不同)
create tablespace tablespaceName datafile ‘/tablespace/tablespaceName02.dbf’ size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
4.2、创建临时表空间
create temporary tablespace tablespaceName_temp tempfile ‘/tablespace/tablespaceName01_temp.dbf’ size 100m reuse autoextend on next 20m maxsize unlimited;
4.3、创建用户,并指定默认表空间和临时表空间
create user root identified by root default tablespace tablespaceName temporary tablespace tablespaceName_temp;
注:在创建表时,可以指定表空间,在没有指定表空间的情况下,就使用默认的表空间。故表空间和用户,没有必然联系,一个用户下的不同表,可以指定不同的表空间
4.4、表空间大小
在创建表空间时,可以指定表空间大小,并让表空间自动扩展,但标空间也会有最大值,4M个数据块,如果数据块大小为8K(1024*8),则表空间最大为4M * 8K = 32G
猜测:在数据文件tablespaceName01.dbf达到最大值时,会将数据存到tablespaceName02.dbf中。
4.5、表空间命令
4.5.1、删除表空间,及对应的表空间文件也删除掉
drop tablespace ABC including contents and datafiles cascade constraint;
4.5.2、查询表空间文件,可查看数据文件的目录
select * from dba_data_files;