ITPUB??ì3
新一届的微软MVP评选已经开始,欢迎各位推荐!
ITPUB论坛 » Oracle专题深入讨论 » Nologging到底何时才能生效?

标题: [精华] Nologging到底何时才能生效?
离线 Arrayeygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 22:54 
Nologging到底何时才能生效?

最初的问题是这个帖子:

http://www.itpub.net/showthread.php?threadid=239905

请大家仔细看那些测试的例子.

看了Tom的解释,始终觉得牵强.
开始以为可能是bug
经过观察和测试,终于发现了Nologging的秘密


__________________
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 22:57 
我们知道,Nologging只在很少情况下生效
通常,DML操作总是要生成redo的

这个我们不多说.

我们来看一下测试:

1.Nologging跟数据库的运行模式有关

a.数据库运行在非归档模式下:
PHP code:


SQL
archive log list;

Database log mode              No Archive Mode

Automatic archival             Enabled

Archive destination            
/opt/oracle/oradata/hsjf/archive

Oldest online log sequence     155

Current log sequence           157



SQL
> @redo

SQL
create table test as select from dba_objects where 1=0;



Table created.



SQLselect from redo_size;



     
VALUE

----------

     
63392



SQL


SQLinsert into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
1150988



SQL


SQLinsert /*+ append */ into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
1152368



SQL
select (1152368 -1150988redo_append,(1150988 -63392redo from dual;



REDO_APPEND       REDO

----------- ----------

       
1380    1087596



SQL
drop table test;



Table dropped.



.

我们看到在Noarchivelog模式下,对于常规表的insert append只产生少量redo


__________________
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 22:58 
b.在归档模式下
PHP code:


SQL
shutdown immediate

Database closed
.

Database dismounted.

ORACLE instance shut down.

SQLstartup mount

ORACLE instance started
.



Total System Global Area  235999908 bytes

Fixed Size                   451236 bytes

Variable Size             201326592 bytes

Database Buffers           33554432 bytes

Redo Buffers                 667648 bytes

Database mounted
.



SQLalter database archivelog;



Database altered.



SQLalter database open;



Database altered.



SQL> @redo

SQL
create table test as select from dba_objects where 1=0;



Table created.



SQLselect from redo_size;



     
VALUE

----------

     
56288



SQL


SQLinsert into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
1143948



SQL


SQLinsert /*+ append */ into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
2227712



SQL
select (2227712 -1143948redo_append,(1143948 -56288redo from dual;



REDO_APPEND       REDO

----------- ----------

    
1083764    1087660



SQL
drop table test;



Table dropped.

我们看到在归档模式下,对于常规表的insert append产生和insert同样的redo
此时的insert append实际上并不会有性能提高.
但是此时的append是生效了的

通过Logmnr分析日志得到以下结果:
PHP code:


SQL
select operation,count(*)

  
2  from v$logmnr_contents 

  3  group by operation
;



OPERATION                          COUNT(*)

-------------------------------- ----------

COMMIT                                   17

DIRECT INSERT                      10470   

INTERNAL                                49

START                                      17

                                                  1



.

我们注意到这里是DIRECT INSERT,而且是10470条记录,也就是每条记录都记录了redo.


__________________
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 23:00 
2.对于Nologging的table的处理

a. 在归档模式下:
PHP code:


SQL
create table test nologging as select from dba_objects where 1=0;



Table created.



SQLselect from redo_size;



     
VALUE

----------

   
2270284



SQL


SQLinsert into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
3357644



SQL


SQLinsert /*+ append */ into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
3359024



SQL
select (3359024 -3357644redo_append,(3357644 2270284redo from dual;



REDO_APPEND       REDO

----------- ----------

       
1380    1087360



SQL
drop table test;



Table dropped.

我们注意到,只有append才能减少redo


__________________
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 23:01 
b.在非归档模式下:
PHP code:


SQL
shutdown immediate

Database closed
.

Database dismounted.

ORACLE instance shut down.

SQLstartup mount

ORACLE instance started
.



Total System Global Area  235999908 bytes

Fixed Size                   451236 bytes

Variable Size             201326592 bytes

Database Buffers           33554432 bytes

Redo Buffers                 667648 bytes

Database mounted
.

SQLalter database noarchivelog;



Database altered.



SQLalter database open;



Database altered.



SQL> @redo

SQL
create table test nologging as select from dba_objects where 1=0;



Table created.



SQLselect from redo_size;



     
VALUE

----------

     
56580



SQL


SQLinsert into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
1144148



SQL


SQLinsert /*+ append */ into test select from dba_objects;



10470 rows created.



SQLselect from redo_size;



     
VALUE

----------

   
1145528



SQL
select (1145528 -1144148redo_append,(1144148 -56580redo from dual;



REDO_APPEND       REDO

----------- ----------

       
1380    1087568



SQL
>

同样只有append才能减少redo的生成.

这就是通常大家认识的情况.


__________________
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-13 23:08 
biti给出过测试,说明在append模式下不会对数据产生undo

也就是说
在Noarchivelog模式下的append操作将是性能最高的.
等价于对Nologging表的append insert操作

大家可以在你的环境里做个测试,来验证一下这个结果.


__________________
只看该作者    顶部
离线 糖醋兔子
斑竹


精华贴数 0
个人空间 0
技术积分 450 (4316)
社区积分 301 (1890)
注册日期 2004-7-1
论坛徽章:3
管理团队2006纪念徽章会员2006贡献徽章数据库板块每日发贴之星   
      

发表于 2004-7-14 01:28 


QUOTE:
最初由 eygle 发布


在Noarchivelog模式下的append操作将是性能最高的.
等价于对Nologging表的append insert操作



谢谢eygle的辛勤劳动,这个应该是正解了

QUOTE:

biti给出过测试,说明在append模式下不会对数据产生undo


这个帖子,以前我看过的。我认为append insert下只是undo要比insert下的少,但并不是完全没有undo 产生的。
PHP code:


SQL
select from v$version;



BANNER

----------------------------------------------------------------

Oracle9i Enterprise Edition Release 9.2.0.1.0 Production

PL
/SQL Release 9.2.0.1.0 Production

CORE    9.2.0.1.0       Production

TNS 
for 32-bit WindowsVersion 9.2.0.1.0 Production

NLSRTL Version 9.2.0.1.0 
Production



SQL
create table test as select from all_objects where 1=2;



SQLselect usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     101874

         2      23752

         3      50500

         4      51000

         5      49180

         6      35260

         7      23692

         8      23514

         9      22698

        10      34620



已选择11行。



SQL
insert /*+ append */into test select from all_objects;



已创建28950行。  



SQL
select XIDUSN from v$transaction;



    
XIDUSN

----------

         
5



SQL
commit;



提交完成。



SQL
select usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     104666

         2      25790

         3      53322

         4      53038

         5      77560

         6      37590

         7      26236

         8      25446

         9      25302

        10      36552       

        

SQL
select 77560-49180 from dual;



77560-49180

-----------

      
28380   

      

SQL
insert into test select from all_objects;



已创建28950行。



SQL
select XIDUSN from v$transaction;



    
XIDUSN

----------

         
8



SQL
commit;



提交完成。



SQL
select usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     109738

         2      30594

         3      58640

         4      57998

         5      82520

         6      42998

         7      31154

         8     169818

         9      30344

        10      41848



已选择11行。



SQL
select 169818-25446 from dual;



169818-25446

------------

      
1443




__________________
那都是很好很好的 可是我偏不喜欢
只看该作者    顶部
离线 西门吹牛
高级会员


精华贴数 4
个人空间 0
技术积分 12719 (92)
社区积分 2663 (478)
注册日期 2002-4-29
论坛徽章:3
会员2007贡献徽章会员2006贡献徽章授权会员   
      

发表于 2004-7-14 09:05 
收藏了。



__________________
春莺啼岸柳弄春晴,柳弄春晴夜月明。明月夜晴春弄柳,晴春弄柳岸啼莺。夏香莲碧水动风凉,水动风凉夏日长。长日夏凉风动水,凉风动水碧莲香。秋秋江楚雁宿沙洲,雁宿沙洲浅水流。流水浅洲沙宿雁,洲沙宿雁楚江秋。冬红炉透炭炙寒风,炭炙寒风御隆冬。冬隆御风寒炙炭,风寒炙炭透炉红。
只看该作者    顶部
在线/呼叫 biti_rainy
人生就是如此



精华贴数 37
个人空间 0
技术积分 110924 (4)
社区积分 11774 (123)
注册日期 2001-12-12
论坛徽章:41
现任管理团队成员ITPUB长老会成员ITPUB元老年度论坛发贴之星年度论坛发贴之星ITPUB北京九华山庄2008年会纪念徽章
管理团队2007贡献徽章参与2007年甲骨文全球大会(中国上海)纪念ITPUB北京香山2007年会纪念徽章管理团队2006纪念徽章会员2007贡献徽章会员2006贡献徽章

发表于 2004-7-14 09:34 


QUOTE:
最初由 糖醋兔子 发布


谢谢eygle的辛勤劳动,这个应该是正解了



这个帖子,以前我看过的。我认为append insert下只是undo要比insert下的少,但并不是完全没有undo 产生的。
PHP code:


SQL
select from v$version;



BANNER

----------------------------------------------------------------

Oracle9i Enterprise Edition Release 9.2.0.1.0 Production

PL
/SQL Release 9.2.0.1.0 Production

CORE    9.2.0.1.0       Production

TNS 
for 32-bit WindowsVersion 9.2.0.1.0 Production

NLSRTL Version 9.2.0.1.0 
Production



SQL
create table test as select from all_objects where 1=2;



SQLselect usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     101874

         2      23752

         3      50500

         4      51000

         5      49180

         6      35260

         7      23692

         8      23514

         9      22698

        10      34620



已选择11行。



SQL
insert /*+ append */into test select from all_objects;



已创建28950行。  



SQL
select XIDUSN from v$transaction;



    
XIDUSN

----------

         
5



SQL
commit;



提交完成。



SQL
select usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     104666

         2      25790

         3      53322

         4      53038

         5      77560

         6      37590

         7      26236

         8      25446

         9      25302

        10      36552       

        

SQL
select 77560-49180 from dual;



77560-49180

-----------

      
28380   

      

SQL
insert into test select from all_objects;



已创建28950行。



SQL
select XIDUSN from v$transaction;



    
XIDUSN

----------

         
8



SQL
commit;



提交完成。



SQL
select usn,writes from v$rollstat;



       
USN     WRITES

---------- ----------

         
0       6900

         1     109738

         2      30594

         3      58640

         4      57998

         5      82520

         6      42998

         7      31154

         8     169818

         9      30344

        10      41848



已选择11行。



SQL
select 169818-25446 from dual;



169818-25446

------------

      
1443



即使是 nologging +  direct ,redo 也不是完全不产生,logging +  direct 下 undo 的减少,是大大地减少,减少的是什么?  减少的是 数据的undo ,我是特地说了 数据本身的undo ,就如同 redo的减少也一样,我一直都说是 数据本身的 redo ,这和数据库是否产生  redo 和 undo 是不同的概念,比如空间分配的 redo and  undo ,这就不是数据本身的变化!



不管表是否处于nologging下,direct insert 都不会对数据产生 UNDO

----------  这个说法,不会对数据产生undo 和不会产生undo 是两码事,就好比 nologging  +  direct 不会对数据产生 redo(但依然有其他的redo)  和不会产生 redo 是两码事!

这是我当时的测试数据对比
带索引表,表和索引均是logging状态,测试结果及过程如下

----------------------------常规插入-------direct插入

插入日志生成量----------------8350864--------2364484

插入回滚段生成量--------------2343894--------426838

回滚日志生成量----------------4018204--------76032

回滚本身不存在产生回滚-------------------------------------

请再仔细读一读,参考
http://www.itpub.net/showthread.php?threadid=217094


__________________
眼界决定边界,态度决定高度
blog:
人生就是如此
只看该作者    顶部
离线 eygle
天下有雪


精华贴数 65
个人空间 0
技术积分 206744 (1)
社区积分 6444 (233)
注册日期 2001-10-8
论坛徽章:60
现任管理团队成员ITPUB长老会主席2007年度ITPUB杰出贡献ITPUB长老会成员ITPUB元老ITPUB维基人
授权会员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:射击生肖徽章2007版:鼠2008年新春纪念徽章

发表于 2004-7-14 09:39 
不是我的错

我引用的时候就说:

biti给出过测试,说明在append模式下不会对数据产生undo






__________________
只看该作者    顶部
相关内容


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