ITPUB??ì3
ITPUB论坛 » Oracle新技术/11g » Oracle 10g features- ---alter table ... shrink space

标题: [新特性] Oracle 10g features- ---alter table ... shrink space
离线 玉面飞龙
斧头帮帮主


精华贴数 1
个人空间 0
技术积分 9939 (118)
社区积分 3151 (418)
注册日期 2002-1-20
论坛徽章:20
现任管理团队成员ITPUB元老ITPUB北京九华山庄2008年会纪念徽章参与2007年甲骨文全球大会(中国上海)纪念管理团队2006纪念徽章蓝锆石
会员2007贡献徽章会员2006贡献徽章授权会员2008北京奥运纪念徽章:自行车2008北京奥运纪念徽章:沙滩排球2008年新春纪念徽章

发表于 2005-4-8 09:18 
Oracle 10g features- ---alter table ... shrink space

Ora Ora Oracle
Welcome to the world of Oracle enthusiasts
Free mail magazine for the people who want to know more about Oracle


Oracle 10g  
Hello. In this issue, I will start a new topic, analysis of new features in Oracle 10g.
New features and enhancements of Oracle 10g are geared towards grid computing which is an extension of the clustering features (i.e. Real Application Clusters.) Also, Oracle 10g enhances its automatic management functions.

Oracle 10g features
When you delete large amount of data from a table, what do you do to reduce high water mark (HWM)?

The answers may be:
1. exp/imp
2. alter table ... move

In addition to the above, alter table ... shrink space command has been newly introduced in Oracle 10g.

This shrink command enables recovering space and amending the high water mark. You can use this command to the following objects:

1. Table
2. Index
3. Materialized view
4. Materialized view log

The objects need to be stored in locally managed tablespace with automatic segment space management.

Now, I issue alter table .. shrink space command.

Testing environment
Linux 2.4.9-e.24enterprise
Oracle10g EE Release 10.1.0.2.0

Using the shrink command
SQL> select owner,segment_name,bytes,blocks,extents from dba_segments
where segment_name = 'EMP';

OWNER SEGMENT_NAME      BYTES     BLOCKS    EXTENTS
----- ------------ ---------- ---------- ----------
SCOTT EMP            53477376       6528         66


SQL> alter table emp shrink space;

ORA-10636: ROW MOVEMENT is not enabled



Execution of the shrink command requires row movement. Thus, it is necessary to enable row movement in advance.

SQL> alter table emp enable row movement;

Table altered.


SQL> alter table emp shrink space;

Table altered.


SQL> select owner,segment_name,bytes,blocks,extents from dba_segments
where segment_name = 'EMP';

OWNER SEGMENT_NAME      BYTES     BLOCKS    EXTENTS
----- ------------ ---------- ---------- ----------
SCOTT EMP               65536          8          1



This looks like alter table ... move command, but actually it is different in Oracle 10g.

alter table ... shrink space VS. alter table ... move

(1)Shrink command can be executed online

SES1>alter table emp move;


SES2>select l.oracle_username,o.name objname,l.locked_mode from
v$locked_object l,obj$ o where l.object_id=o.obj#;

ORACLE_USERNAME           OBJNAME                        LOCKED_MODE
------------------------- ------------------------------ -----------
SCOTT                     EMP                                      6


SES2>select rownum from scott.emp where rownum=1 for update nowait;

ORA-00054: Resource busy, NOWAIT is specified.


SES1> alter table emp shrink space;


SES2> select l.oracle_username,o.name objname,l.locked_mode from
v$locked_object l,obj$ o where l.object_id=o.obj#;

ORACLE_USERNAME           OBJNAME                        LOCKED_MODE
------------------------- ------------------------------ -----------
SCOTT                     EMP                                      3


SES2>select rownum from scott.emp where rownum=1 for update nowait;

    ROWNUM
----------
         1



The difference between shrink command and move command is that the shrink command does not lock the object in exclusive mode.
move command is executed with LOCKED_MODE=6 (exclusive mode). shrink command, on the other hand, is executed with LOCKED_MODE=3 (row lock mode), which enables recovering without stopping operations.

Segment is shrunk even though the command is stopped in the middle of the execution

Shrink SCOTT.EMP

*dbms_space.space_usage procedure to determine the value that is
not yet shrunk
Segment Owner      = SCOTT
Segment Name       = EMP
Unformatted Blocks = 16
0 - 25% free blocks= 0
25- 50% free blocks= 6366
50- 75% free blocks= 0
75-100% free blocks= 36
Full Blocks        = 0

*Forcefully terminate while executing the shrink command
SQL> alter table emp shrink space;

ORA-00028: your session has been killed


*Determine the value after the command is forcefully terminated
Segment Owner      = SCOTT
Segment Name       = EMP
Unformatted Blocks = 16
0 - 25% free blocks= 1
25- 50% free blocks= 2808
50- 75% free blocks= 0
75-100% free blocks= 1004
Full Blocks        = 2553


*Execute the shrink command again and determine the value
after the execution is completed properly
Segment Owner      = SCOTT
Segment Name       = EMP
Unformatted Blocks = 0
0 - 25% free blocks= 1
25- 50% free blocks= 2
50- 75% free blocks= 0
75-100% free blocks= 0
Full Blocks        = 4567



Take a look at the changes in the value determined from dbms_space.space_usage procedure.

1. Before executing the shrink command
There are no full blocks, which means that most of the blocks have sufficient free space.

2. Forcefully terminating the process while the command is executed
**% free blocks decrease and full blocks increase instead. This means that the shrink process is being executed.

3. After executing the shrink command
There are few **% free blocks. Also, the total percentage of the blocks drops to 70%, which means that the high water mark is reduced.

Even when you don't have much time to do the database maintenance, you can repeat the process above several times to recover space.

That's it for today.

Takuya Kishimoto


还没有测试shrink对性能的影响,不过oracle提供的东西并不见得一定要用,就和online build index一样, 我倒是对这个Materialized view log 非常期待:)


__________________
只看该作者    顶部
在线/呼叫 cyt2005
老会员


来自 天津
精华贴数 0
个人空间 0
技术积分 2301 (673)
社区积分 83 (3684)
注册日期 2006-3-9
论坛徽章:10
会员2007贡献徽章2008北京奥运纪念徽章:摔跤2008北京奥运纪念徽章:艺术体操2008北京奥运纪念徽章:举重生肖徽章2007版:虎生肖徽章2007版:兔
生肖徽章2007版:鼠生肖徽章2007版:猴生肖徽章2007版:牛ITPUB新首页上线纪念徽章  

发表于 2008-3-12 14:06 
今天用到了~


__________________
饥饿艺术家说着,小脑袋微微抬起,嘴唇像要吻看管人似的,直贴在他的耳根,生怕露掉一个字,“因为我找不到适合我胃口的食物。假如我找到这样的食物,请相信我,我不会招人参观,惹人显眼,并像你,像大伙一样,吃得饱饱的。”
只看该作者    顶部
离线 jiangjh62


精华贴数 0
个人空间 0
技术积分 327 (5879)
社区积分 51 (4725)
注册日期 2006-1-7
论坛徽章:16
2008北京奥运纪念徽章:射箭2008北京奥运纪念徽章:羽毛球2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:羽毛球2008北京奥运纪念徽章:拳击2008北京奥运纪念徽章:击剑
生肖徽章2007版:猪设计板块每日发贴之星每日论坛发贴之星数据库板块每日发贴之星生肖徽章2007版:猴生肖徽章2007版:牛

发表于 2008-3-14 10:48 
不错


只看该作者    顶部
离线 cainiao2
高级会员


精华贴数 0
个人空间 0
技术积分 8433 (141)
社区积分 23 (6887)
注册日期 2002-2-27
论坛徽章:21
ITPUB元老会员2007贡献徽章    
      

发表于 2008-4-7 17:44 
学习


__________________
好好学习,天天向上!!!!!!
只看该作者    顶部
离线 bosonmaster
中级会员


精华贴数 1
个人空间 0
技术积分 2133 (725)
社区积分 20 (7452)
注册日期 2007-1-31
论坛徽章:7
金色在线徽章生肖徽章2007版:鸡生肖徽章2007版:鼠生肖徽章2007版:猴数据库板块每日发贴之星ITPUB新首页上线纪念徽章
每日论坛发贴之星     

发表于 2008-4-15 13:30 
不错学习下


__________________
ORACLE QQ技术群44425882
http://www.oralife.cn
只看该作者    顶部
离线 kangoo77



精华贴数 0
个人空间 0
技术积分 350 (5493)
社区积分 0 (1685848)
注册日期 2008-1-24
论坛徽章:1
2008年新春纪念徽章     
      

发表于 2008-4-20 07:28 
对作了基于ROWID实体化视图的基表是不是不能使用?


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问