我们知道Oracle有一个延迟段创建的功能,就是创建没有数据的表的时候,不会分配空间,只有在插入第一条记录的时候,才会为段分配空间,具体如下:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
SQL> show parameter deferred
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
deferred_segment_creation boolean TRUE
SQL> conn hr/hr
Connected.
SQL> create table seg_test(c number);
Table created.
SQL> select segment_name from user_segments where segment_name='SEG_TEST';
no rows selected
SQL> insert into seg_test values(1);
1 row created.
SQL> select segment_name,bytes from user_segments where segment_name='SEG_TEST';
SEGMENT_NAME BYTES
-------------------- ----------
SEG_TEST 65536
如果使用SYS用户创建,具体如下:
SQL> conn / as sysdba
Connected.
SQL> create table seg_test1(c number);
Table created.
SQL> select segment_name,tablespace_name,bytes from dba_segments where segment_name='SEG_TEST1';
SEGMENT_NAME TABLESPACE_NAME BYTES
-------------------- ------------------------------ ----------
SEG_TEST1 SYSTEM 65536
SQL> create table seg_test2(c number) tablespace users;
Table created.
SQL> select segment_name,tablespace_name,bytes from dba_segments where segment_name='SEG_TEST2';
SEGMENT_NAME TABLESPACE_NAME BYTES
-------------------- ------------------------------ ----------
SEG_TEST2 USERS 65536
SQL> create table seg_test3(c number) segment creation deferred;
create table seg_test3(c number) segment creation deferred
*
ERROR at line 1:
ORA-14223: Deferred segment creation is not supported for this table
强制使用segment creation deferred报错。
可以看到创建了表之后就分配了空间,与创建在哪个表空间没有关系。
SQL> conn hr/hr
Connected.
SQL> create table emptest3 tablespace system as select * from employees;
Table created.
SQL> select segment_name,bytes from user_segments where segment_name='EMPTEST3';
SEGMENT_NAME BYTES
-------------------- ----------
EMPTEST3 65536
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28536251/viewspace-2072565/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28536251/viewspace-2072565/