----------------------------------------------------------------------------
-- 什么情况下给表添加extent
----------------------------------------------------------------------------
如果表空间TST有两个数据文件,一个大rm0.dbf(1G),一个小rm1.dbf(10m)。
表TAB_T创建在表空间TST上。
向表TAB_T中插入数据,extent如何在数据文件中扩展?
经过试验得到:
1、oracle会先从大的数据文件中分配extent,而不是将小的数据文件扩大,再在其中分配extent。
2、当大的数据文件用完后,会扩大小的数据文件,然后在其中分配extent。
3、当大数据文件和小数据文件都没有空间后,oracle会依次扩展数据文件,分配extent。
----------------------------------------------------------------------------
-- 1、构建测试环境
----------------------------------------------------------------------------
create tablespace tst datafile
'D:\APP\rm0.dbf' size 1024m autoextend on next 10m,
'D:\APP\rm1.dbf' size 10m autoextend on next 10m
segment space management auto;
create table tab_t as select * from dba_objects where 1 = 2;
create table TAB_T
(
owner VARCHAR2(30),
object_name VARCHAR2(128),
subobject_name VARCHAR2(30),
object_id NUMBER,
data_object_id NUMBER,
object_type VARCHAR2(19),
created DATE,
last_ddl_time DATE,
timestamp VARCHAR2(19),
status VARCHAR2(7),
temporary VARCHAR2(1),
generated VARCHAR2(1),
secondary VARCHAR2(1),
namespace NUMBER,
edition_name VARCHAR2(30)
)
tablespace tst;
insert into tab_t select * from dba_objects;
commit;
insert into tab_t select * from tab_t;
commit;
----------------------------------------------------------------------------
-- 2、查询extent
----------------------------------------------------------------------------
select segment_name,
tablespace_name,
extent_id,
file_id,
bytes,
blocks,
relative_fno
from dba_extents
where file_id in (28, 29);
select relative_fno, count(*)
from dba_extents
where file_id in (28, 29)
group by relative_fno;
----------------------------------------------------------------------------
-- 自动扩展
----------------------------------------------------------------------------
-- 查找表空间是否自动扩展
select file_id, file_name, tablespace_name, autoextensible
from dba_data_files
order by file_id;
alter database datafile 'xxx.dbf' autoextend off;
alter database datafile 'xxx.dbf' autoextend on;
----------------------------------------------------------------------------
-- 给表在数据文件上创建extent
----------------------------------------------------------------------------
alter table XXX allocate extent (datafile XXX size Xm);
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/720091/viewspace-1067557/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/720091/viewspace-1067557/