当前位置:Gxlcms > mysql > Oracle11gR2的延迟段功能

Oracle11gR2的延迟段功能

时间:2021-07-01 10:21:17 帮助过:19人阅读

为此,从11gR2开始,有一种新特性,叫延迟段,即延迟分配段空间。简单讲,默认将表(以及索引、LOB)的物理空间分配推迟到第一条记

11gR2之前的版本中,当创建一张表时,会自动分配段空间,这样做有几个弊端:

1. 初始创建表时就需要分配空间,自然会占用一些时间,,如果初始化多张表,这种影响就被放大。

2. 如果很多表开始的一段时间都不需要,那么就会浪费这些空间。

注:使用特性的前提是COMPATIBLE参数是11.2.0及以上。

实验:

1. 首先我们看下11g之前版本对表空间时段空间的分配

SQL> select version from v$instance;
VERSION
-----------------
10.2.0.4.0

SQL> create table tbl_seg(reg_id number, reg_name varchar2(200));
Table created.


SQL> select count(*) from user_segments where segment_name='TBL_SEG';
COUNT(*)
----------
1

SQL> select count(*) from user_extents where segment_name='TBL_SEG';
COUNT(*)
----------
1

SQL> select segment_name, segment_type, bytes, blocks, extents, initial_extent, next_extent, max_extents
2 from user_segments where segment_name='TBL_SEG';
SEGMENT_NAME SEGMENT_TYPE BYTES BLOCKS EXTENTS INITIAL_EXTENT NEXT_EXTENT MAX_EXTENTS
----------------------------- ---------- ---------- ---------- -------------- ----------- --------------------- ----------------- ------------------
TBL_SEG TABLE 65536 8 1 65536 2147483645

可以看到,TBL_SEG表创建后,user_segments和user_extents已经有记录了,说明已经为TBL_SEG分配了段和区的空间。1个EXTENTS的大小是64K。

2、接下来看下11g的分配

[Oracle@riserver1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Mon Aug 4 07:53:24 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select version from v$instance;
VERSION
-----------------
11.2.0.1.0

SQL> create table tbl_seg(reg_id number, reg_name varchar2(200));
Table created.

SQL> select count(*) from user_segments where segment_name='TBL_SEG';
COUNT(*)
----------
1

SQL> select count(*) from user_extents where segment_name='TBL_SEG';
COUNT(*)
----------
1

为什么仍分配了呢?

那么接下来使用非系统账户建表:

SQL> create user user01 identified by user01;

User created.

SQL> grant connect, resource to user01;
Grant succeeded.

[oracle@riserver1 ~]$ sqlplus user01/user01
SQL*Plus: Release 11.2.0.1.0 Production on Mon Aug 4 08:32:06 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show user
USER is "USER01"


SQL> select username,default_tablespace from user_users;
USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------
USER01 USERS

SQL> create table tbl_seg(reg_id number, reg_name varchar2(200));
Table created.

SQL> select count(*) from user_segments where segment_name='TBL_SEG';
COUNT(*)
----------
0

SQL> select count(*) from user_extents where segment_name='TBL_SEG';
COUNT(*)
----------
0

此时可以看到创建表后,段和区是没有分配空间的,那么插入记录:

SQL> insert into tbl_seg values(1, 'BRDSTN');

1 row created.

SQL> select count(*) from user_segments where segment_name='TBL_SEG';

COUNT(*)
----------
1

SQL> select count(*) from user_extents where segment_name='TBL_SEG';

COUNT(*)
----------
1

可以看到段和区已经分配了空间,user_segments和user_extents表均有了TBL_SEG对应的记录。

3. 禁用延迟段

可以禁用延迟段,是否使用延迟段是由DEFERRED_SEGMENT_CREATION参数定义的,该参数可以在会话级别修改,如果想彻底删除延迟段,可以在spfile中修改,本次以及下次启动后就会一直生效了,例如:

SQL> alter session set DEFERRED_SEGMENT_CREATION=false;

人气教程排行