`

【转】nologging与insert

阅读更多

转载自:http://hi.baidu.com/420350501/blog/item/46f1eed2892abc3107088b97.html

nologging与insert
2011-12-12 16:33

nologging是ORACLE提供的操作无日志选项,对于普通的INSERT 没有多少影响,   但如果INSERT的时候采用了/*+append*/,就会产生很少的日志

前提条件:非归档模式
测试如下(每次都是先删除表,再建表)
建表:
CREATE TABLE test1 AS SELECT * FROM dba_Objects WHERE 1>8 ;

表不作NOLOGGING处理:产生redo 8,697,536
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                              1124
 
SQL> INSERT INTO test1 SELECT * FROM dba_objects ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                              1124    8698660        8,697,536
 
SQL>
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                           8698800
 
SQL> INSERT INTO test1 SELECT * FROM dba_objects nologging ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                           8698800   17390924        8,692,124
 
对表进行nologging操作   产生redo 8,692,300  相对于不作处理,没有变化
SQL> alter table test1 nologging ;
 
Table altered
 
SQL>
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          17393168
 
SQL> INSERT INTO test1 SELECT * FROM dba_objects ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                          17393168   26085468        8,692,300
 
 insert的时候,如果采用append  就会少很很多。 产生redo   66,600
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          26085608
 
SQL> INSERT/*+append*/ INTO test1 SELECT * FROM dba_objects ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                          26085608   26152208           66,600

如果再将表更改为nologging ,然后再insert的时候APPEND   会产生更少的REDO 26,472
 
SQL> alter table test1 nologging ;
 
Table altered
 
SQL>
SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          26162576
 
SQL> INSERT/*+append*/ INTO test1 SELECT * FROM dba_objects ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                          26162576   26189048           26,472

测试条件:归档模式

以上结果大部分不会影响太大,只有append的时候会影响很大。

SQL> SET ECHO OFF
SQL> SET VERIFY OFF
SQL> COLUMN VALUE NEW_VAL V
SQL> DEFINE S='&1'
SQL> SET AUTOTRACE OFF
Cannot SET AUTOTRACE
SQL> SELECT A.NAME,B.VALUE  FROM V$STATNAME A ,V$MYSTAT B
  2  WHERE A.STATISTIC#=B.STATISTIC#
  3  AND LOWER(A.NAME) =LOWER('&S');
 
NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                           8736356
 
SQL> INSERT/*+append*/  INTO test1 a SELECT * FROM dba_objects ;
 
72220 rows inserted
 
SQL>
SQL> set echo off
SQL> set verify off ;
SQL> select distinct a.name,&v 执行前 ,b.value 执行后,to_char(b.value-&v,'999,999,999,999') 操作产生的redo
  2  from v$statname a ,v$mystat b
  3  where a.statistic#=b.statistic#
  4  and lower(a.name) =lower('&s');
 
NAME                                                                    执行前        执行后 操作产生的REDO
---------------------------------------------------------------- ---------- ---------- ----------------
redo size                                                           8736356   17555000        8,818,644
 这个区别也说明了,append只有在非归档模式下才会减少redo

分享到:
评论

相关推荐

    insert大量数据经验之谈

    首先,基础的`INSERT INTO ... SELECT FROM`语句是最常见的数据迁移方式。例如: ```sql INSERT INTO tab1 SELECT * FROM tab2; COMMIT; ``` 这种操作适用于百万至千万级别的数据,可以在一小时内完成。然而,这种...

    Oracle 大数据量操作优化

    2. **批量更新与提交** - 实施批量更新并在每次更新一定数量的记录后立即提交。这种方法可以有效减少回滚段和临时表空间的占用,避免资源过度消耗。 - 示例命令: ``` insert into table_b select * from ...

    oracle 8795792补丁

    在应用补丁前,必须确保数据库处于归档模式(Archived Log Mode)下,因为NOLOGGING操作在非归档模式下是不允许的,而根据描述中的错误提示,这个问题可能与LOGGING和NOLOGGING的冲突有关。同时,为了保证业务不受...

    ORACLE SQL-UPDATE、DELETE、INSERT优化和使用技巧分享

    1. **禁用redo log**:为了提高插入速度,可以临时禁用重做日志(ALTER TABLE <TABLENAME> NOLOGGING;),但需要注意,这样可能会丢失部分事务信息,需要谨慎操作。 2. **APPEND hint**:使用`/*+ APPEND */`暗示,...

    abator 生成ibaties dao xml

    在 MyBatis 中,DAO(Data Access Object)层是负责与数据库进行交互的组件,而 XML 映射文件则是定义 SQL 语句和结果映射的地方。Abator 的作用就是根据你的数据库表结构自动生成这些 DAO 类和对应的 XML 文件。 ...

    oracle FORCE LOGGING.txt

    INSERT /*+ APPEND, PARALLEL */ INTO 目标表名 NOLOGGING SELECT * FROM 表名; ``` ##### 4.2 查看 Force Logging 状态 1. **数据库级别**: ```sql SELECT log_mode, force_logging FROM v$database; ``` ...

    Oracle 大数据量操作优化.pdf

    10. **批量拷贝与常规插入**:Oracle提供的COPY命令和常规的INSERT INTO...SELECT语句是批量数据迁移的常见方式,通过设置ARRAYSIZE和COPYCOMMIT,可以控制批量处理的大小,提高效率。 11. **CTAS(CREATE TABLE AS...

    对比Oracle数据库中多种导入数据方法

    为了优化导入性能,可以调整Oracle的初始化参数,如SORT_AREA_SIZE以增大排序区,或者使用NOLOGGING选项减少redo日志生成,但这可能影响数据库的恢复和standby数据库的同步。此外,合理规划导入过程,如分批导入、...

    ORACLE批量更新四种方法.txt ORACLE批量更新四种方法.txt

    insert /*+ APPEND */ into T3 select T1.* from T1, T2 where T1.ID = T2.ID; ``` **特点:** - **优点:**能够避免大量的undo段占用问题,适用于大规模数据更新。 - **缺点:**需要额外的空间来存储临时表。 **...

    Oracle插入大量数据

    NOLOGGING`),可以在大数据量的插入操作中显著降低日志写入的开销,从而大幅减少操作时间。但值得注意的是,禁用日志记录会牺牲数据恢复的安全性,因此在操作完成后应立即恢复日志记录(`ALTER TABLE ... LOGGING`...

    Oracle事例

    sql> [logging | nologging] [nosort] storage(initial 200k next 200k pctincrease 0 sql> maxextents 50); <3>.pctfree(index)=(maximum number of rows-initial number of rows)*100/maximum number of ...

    Oracle 数据库备份与恢复总结.pdf

    - **LOGGING与NOLOGGING**: 指定数据文件是否记录日志。 - **归档路径**: 设置归档日志存储的位置。 **3.2 NONARCHIVELOG模式** - **脱机冷备与恢复**: 在数据库关闭状态下备份数据文件。 - **案例**: 关闭数据库...

    模拟分批导出BLOB大字段.txt

    ALTER TABLE testuser.ORDER_RECORD NOLOGGING; -- 创建索引 CREATE INDEX testuser.ind_order_id ON testuser.ORDER_RECORD (id); -- 创建自增序列 CREATE SEQUENCE testuser.ORDER_RECORD_id_seq; -- 创建自增...

    常用数据库、开发、sql总结

    CREATE TABLE new_table AS SELECT col1, col2 FROM old_table NOLOGGING; ``` #### 修改表结构 - **添加列**: ```sql ALTER TABLE tableName ADD (col1 col_type, col2 DATE DEFAULT SYSDATE); ``` - **修改...

Global site tag (gtag.js) - Google Analytics