Oracle 11g新特性 -- 延迟段
11gR2之前的版本中,当创建一张表时,会自动分配段空间,这样做有几个弊端:
1. 初始创建表时就需要分配空间,自然会占用一些时间,如果初始化多张表,这种影响就被放大。
2. 如果很多表开始的一段时间都不需要,那么就会浪费这些空间。
为此,从11gR2开始,有一种新特性,叫延迟段,即延迟分配段空间。简单讲,默认将表(以及索引、LOB)的物理空间分配推迟到第一条记录插入到表中时。即有实际的数据插入表中时,再为每个对象初始化空间分配。其中11.2.0.1不支持分区表 、bitmap join indexes和domain indexes。11.2.0.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
为什么仍分配了呢?
IOTs and other special tables like clustered tables, global temporary tables, session-specific temporary tables, internal tables, typed tables, AQ tables, external tablesare not supported. Tables owned by SYS,SYSTEM, PUBLIC, OUTLN, and XDB are also excluded.
这里解释了原因,SYS的表是不能使用延迟段的,因此创建时还是立即分配段空间。
那么接下来使用非系统账户建表:
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;
Session altered.
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
4. 使用SEGMENT CREATION子句:
即使禁用了延迟段,还是可以使用SEGMENT CREATION在创建表时指定是否使用延迟段,例如:
SQL> create table tbl_seg(
2 reg_id number,
3 reg_name varchar2(200))
4 segment creation immediate;
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
这可以看到立即为段和区分配了空间。如果使用SEGMENT CREATION DEFERRED则会使用延迟段的功能。
5. 从USER_TABLES看变化:
11g的USER_TABLES比之前的版本会多一些字段,其中有一项就是SEGMENT_CREATED(VARCHAR2(3)),这样就能知道某个段是否已经分配了空间。
6. 导入导出的影响:
11.2.0.1版本下,如果某张表还未分配段,使用exp到导出时是不会导出未分配段的表,解决方法是可以在导出前使用ALLOCATE EXTENT手工分配段,或者使用数据泵expdp导出未分配段的表。
总结:
这种延迟段的新特性的好处是显而易见的,弊端也很明显,至于是否应该使用,则需要根据实际业务来决定,这也是Oracle提供了禁用延迟段选项的目的。
Oracle 11g新特性 -- 延迟段的更多相关文章
- Oracle 11g新特性延迟段创建和truncate的增强
下面测试Oracle 11g开始的新特性truncate的增强和延迟段空间创建. Oracle从11g开始,当用户创建一张空表的时候不会先分配段和空间,只有当对这张表插入第一行数据的时候才分配段和空间 ...
- Oracle 11g 新特性 – HM(Hang Manager)简介
在这篇文章中我们会对oracle 11g 新特性—hang 管理器(Hang Manager) 进行介绍.我们需要说明,HM 只在RAC 数据库中存在. 在我们诊断数据库问题的时候,经常会遇到一些数据 ...
- Oracle 11g 新特性 --SQL Plan Management 说明
Oracle 11g 新特性 --SQL Plan Management 说明 参见大神博主文章: http://blog.csdn.net/tianlesoftware/article/detail ...
- oracle 11g使用deferred_segment_creation 延迟段创建特性时遇到的问题总结
总结,下面是两个问题.问题1是用户可以在所有表空间创建表;问题2是exp不能导出空表 问题1: 版本:oracle 11.2.0.1.0 select * from v$version; 创建用户aa ...
- 使用Oracle 11g新特性 Active Database Duplication 搭建Dataguard环境
Duplication Database 介绍 Duplicate database可以按照用途分为2种: duplicate database(复制出一个数据库) duplicate standby ...
- Oracle 11g新特性
文章转自网络 Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(I ...
- Oracle 11g 新特性 -- 自适应游标共享(Adaptive Cursor Sharing: ACS) 说明(转载)
一.自适应游标共享(Adaptive Cursor Sharing) 说明 1.1 ACS概述绑定变量使Oracle DB 可以为多条SQL 语句共享单个游标,以减少分析SQL 语句所使用的共享内存量 ...
- Oracle 11g 新特性(一)-- 虚拟列
数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Oracle11g 增加了虚拟列的新特性, 具体说明如 ...
- Oracle 11g新特性invisible index(不可见的索引)
假设一张表上有十几个索引,你有什么感受?显然会拖慢增.删.改的速度.不要指望开发者能建好索引.我的处理方法是先监控非常长的一段时间.看哪些索引没实用到,然后删除. 但删除以后,假设发现某一天实用,那又 ...
随机推荐
- ubuntu add application to launcher
eg. add sublime text to launcher so as to be found by launcher, docky, etc. add a file sudo gedit /u ...
- ext grid 子表格
Ext.define('app.view.main.biz.customer.receipt.followup.FollowUpActionPanel', { extend: 'Ext.grid.Pa ...
- 通过Nginx和Nginx Plus阻止DDoS攻击
分布式拒绝服务攻击(DDoS)指的是通过多台机器向一个服务或者网站发送大量看似合法的数据包使其网络阻塞.资源耗尽从而不能为正常用户提供正常服务的攻击手段.随着互联网带宽的增加和相关工具的不断发布,这种 ...
- 【GoLang】golang底层数据类型实现原理
虽然golang是用C实现的,并且被称为下一代的C语言,但是golang跟C的差别还是很大的.它定义了一套很丰富的数据类型及数据结构,这些类型和结构或者是直接映射为C的数据类型,或者是用C struc ...
- Jquery Ajax处理,服务端三种页面aspx,ashx,asmx的比较
常规的Jquery Ajax 验证登录,主要有3种服务端页面相应 ,也就是 aspx,ashx,asmx即webserivice . 下面分别用3种方式来(aspx,ashx,asmx)做服务端来处理 ...
- Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...
- servlet 和filter 的生命周期说明
servlet : 当客户端第一次访问servlet的时候,服务器就会创建servlet实例,servlet 就会执行init方法,每次请求,服务器会开一个新的线程访问servlet中得service ...
- uniq 重复行统计
uniq 命令 文字 uniq 是LINUX命令 用途 报告或删除文件中重复的行. 语法 uniq [ -c | -d | -u ] [ -f Fields ] [ -s Characters ] ...
- Delphi中Format与FormatDateTime函数详解
copy:http://hi.baidu.com/yunfanleo/blog/item/0c51d9cdbc0531550eb34558.html Format是一个很常用,却又似乎很烦的方法,本人 ...
- perl 从文件里读出变量无法使用解决办法
最近在写一个perl函数,把test case 放到配置文件里,读出来然后使用system运行. 我的本意是: 配置文件conf ping -c $count $ip #在主程序中定义$ip和$cou ...