查看: 6660|回复: 11

insert /*+append*/ into产生日志的疑问

[复制链接]
论坛徽章:
0
跳转到指定楼层
1#
发表于 2008-4-28 16:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
数据库版本10.2.0.2
书上说使用直接路径插入在标记为nologging的表上执行操作是才能绕过重做日志的生成
故测试如下;
1.创建表
  create table rainbow_objects as select * from dba_objects where 1=2;
2.检查该表属性
  SQL> select LOGGING from dba_tables where table_name='RAINBOW_OBJECTS';

   LOGGING
  ---------
  YES
3.set autotrace traceonly statistics

4.测试插入产生的redo
   方法1 正常插入
   SQL> insert into rainbow_objects select * from dba_objects;

  40352 rows created.


  Statistics
  ----------------------------------------------------------
       1419  recursive calls
       5650  db block gets
       4104  consistent gets
          4  physical reads
   4597764  redo size
        840  bytes sent via SQL*Net to client
        749  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
         13  sorts (memory)
          0  sorts (disk)
      40352  rows processed

  方法2 直接路径插入
  

SQL> insert /*+append*/ into rainbow_objects select * from dba_objects;

40352 rows created.


Statistics
----------------------------------------------------------
        184  recursive calls
        699  db block gets
       2750  consistent gets
          0  physical reads
      13692  redo size
        824  bytes sent via SQL*Net to client
        764  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
      40352  rows processed

结果发现redo size 得到了明显的减少,这是为什么,我的表还没设置为nologging啊
论坛徽章:
40
2#
发表于 2008-4-28 16:36 | 只看该作者
很奇怪哦,而且direct insert好像是工作于Database Noarchivelog + Table Nologging mode,大家给点意见呢

使用道具 举报

回复
论坛徽章:
0
3#
 楼主| 发表于 2008-4-28 16:46 | 只看该作者
我加了nolgging后反而生成的日志更多了,我日
SQL> alter table rainbow_objects nologging;

Table altered.

SQL> insert /*+append*/ into rainbow_objects select * from dba_objects;

40352 rows created.


Statistics
----------------------------------------------------------
        452  recursive calls
        722  db block gets
       2816  consistent gets
          0  physical reads
      16768  redo size
        824  bytes sent via SQL*Net to client
        764  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          6  sorts (memory)
          0  sorts (disk)
      40352  rows processed

     16768  redo size

使用道具 举报

回复
论坛徽章:
40
4#
发表于 2008-4-28 16:55 | 只看该作者
把database 换成Noarchivelog mode 试试看

使用道具 举报

回复
论坛徽章:
131
2006年度最佳技术回答
日期:2007-01-24 12:58:48福特
日期:2013-10-24 13:57:422014年新春福章
日期:2014-02-18 16:41:11马上有车
日期:2014-02-18 16:41:11马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上加薪
日期:2014-02-19 11:55:142013年新春福章
日期:2013-02-25 14:51:24
5#
发表于 2008-4-28 16:57 | 只看该作者

使用道具 举报

回复
论坛徽章:
242
蛋疼蛋
日期:2013-01-29 11:27:262013年新春福章
日期:2013-02-25 14:51:24ITPUB社区12周年站庆徽章
日期:2013-10-08 14:56:08
6#
发表于 2008-4-28 16:59 | 只看该作者
原帖由 蓝衣子龙 于 2008-4-28 16:31 发表
数据库版本10.2.0.2
书上说使用直接路径插入在标记为nologging的表上执行操作是才能绕过重做日志的生成
故测试如下;
1.创建表
  create table rainbow_objects as select * from dba_objects where 1=2;
2.检查该表属性
  SQL> select LOGGING from dba_tables where table_name='RAINBOW_OBJECTS';

   LOGGING
  ---------
  YES
3.set autotrace traceonly statistics

4.测试插入产生的redo
   方法1 正常插入
   SQL> insert into rainbow_objects select * from dba_objects;

  40352 rows created.


  Statistics
  ----------------------------------------------------------
       1419  recursive calls
       5650  db block gets
       4104  consistent gets
          4  physical reads
    4597764  redo size
        840  bytes sent via SQL*Net to client
        749  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
         13  sorts (memory)
          0  sorts (disk)
      40352  rows processed

  方法2 直接路径插入
  

SQL> insert /*+append*/ into rainbow_objects select * from dba_objects;

40352 rows created.


Statistics
----------------------------------------------------------
        184  recursive calls
        699  db block gets
       2750  consistent gets
          0  physical reads
      13692  redo size
        824  bytes sent via SQL*Net to client
        764  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
      40352  rows processed

结果发现redo size 得到了明显的减少,这是为什么,我的表还没设置为nologging啊


你的database是noarchivelog模式吧,在noarchivelog模式下是这样的,和表是否nologging没有关系,只要直接加载产短的log就会少.

使用道具 举报

回复
论坛徽章:
0
7#
 楼主| 发表于 2008-4-28 17:04 | 只看该作者
原帖由 jolly10 于 2008-4-28 16:59 发表


你的database是noarchivelog模式吧,在noarchivelog模式下是这样的,和表是否nologging没有关系,只要直接加载产短的log就会少.



楼上说的是正解,忘了我的数据库是noarchive的

使用道具 举报

回复
论坛徽章:
40
8#
发表于 2008-4-28 17:08 | 只看该作者
学习了

使用道具 举报

回复
招聘 : Linux运维
论坛徽章:
235
紫蜘蛛
日期:2007-09-26 17:05:46玉兔
日期:2007-09-26 17:05:05现任管理团队成员
日期:2011-05-07 01:45:08玉兔
日期:2006-08-29 20:38:48紫蜘蛛
日期:2007-09-26 17:05:34阿斯顿马丁
日期:2013-11-19 10:38:16奔驰
日期:2013-10-16 09:08:58红旗
日期:2014-01-09 11:57:39路虎
日期:2013-08-13 14:52:35林肯
日期:2015-05-19 13:01:16
9#
发表于 2008-4-28 17:13 | 只看该作者
在归档模式下,表nologging+ append 不写redo!
在非归档模式下,append就直接不写redo!

使用道具 举报

回复
论坛徽章:
0
10#
 楼主| 发表于 2008-4-28 17:45 | 只看该作者
谢谢大家的帮助,现在给出在archive log 下的测试结果
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /archivelog
Oldest online log sequence     70
Next log sequence to archive   72
Current log sequence           72

SQL> alter table rainbow_objects logging;

Table altered.

Elapsed: 00:00:00.04
SQL>  set autotrace traceonly statistics;
SQL> insert into rainbow_objects select * from object;

3712476 rows created.

Elapsed: 00:01:04.59

Statistics
----------------------------------------------------------
       9706  recursive calls
    2626845  db block gets
     194131  consistent gets
         11  physical reads
  853455224  redo size
        837  bytes sent via SQL*Net to client
        744  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          7  sorts (memory)
          0  sorts (disk)
    3712476  rows processed

SQL> insert /*+append*/ into rainbow_objects select * from object;

3712476 rows created.

Elapsed: 00:01:34.46

Statistics
----------------------------------------------------------
       3125  recursive calls
     364638  db block gets
      89578  consistent gets
      28409  physical reads
  749863644  redo size
        825  bytes sent via SQL*Net to client
        756  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          1  sorts (disk)
    3712476  rows processed

SQL> alter table rainbow_objects nologging;

Table altered.

Elapsed: 00:00:00.15
SQL> insert /*+append*/ into rainbow_objects select * from object;

3712476 rows created.

Elapsed: 00:01:14.54

Statistics
----------------------------------------------------------
       2300  recursive calls
     352082  db block gets
      91891  consistent gets
      28409  physical reads
  285545596  redo size
        826  bytes sent via SQL*Net to client
        756  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          7  sorts (memory)
          1  sorts (disk)
    3712476  rows processed

SQL> insert into rainbow_objects select * from object;

3712476 rows created.

Elapsed: 00:04:50.75

Statistics
----------------------------------------------------------
        306  recursive calls
    9149717  db block gets
     152892  consistent gets
          0  physical reads
1100134184  redo size
        843  bytes sent via SQL*Net to client
        744  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
    3712476  rows processed



确实在archive 下只有nologging和append 一起使用时才能大幅度减少redo的产生

[ 本帖最后由 蓝衣子龙 于 2008-4-28 17:46 编辑 ]

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表