fishcat 发表于 2013-3-5 23:24:47

实验证明 Oracle能减少redo size的方法

本帖最后由 fishcat 于 2013-3-5 23:27 编辑


用实验说明

一、在非归档模式下:

view plaincopy

    SQL> archive log list
    数据库日志模式             非存档模式
    自动存档             禁用
    存档终点            USE_DB_RECOVERY_FILE_DEST
    最早的联机日志序列   2491
    当前日志序列         2493


用sys用户创建查询redo size的视图(方便查询)

view plaincopy

    SQL> create or replace view redo_size
      2as
      3select value
      4    from v$mystat, v$statname
      5where v$mystat.statistic# = v$statname.statistic#
      6   and v$statname.name = 'redo size';
      
    视图已创建。

用sys用户创建同义词

view plaincopy

    SQL> create public synonym redo_size for redo_size;
      
    同义词已创建。


以下用scott操作

创建测试表

view plaincopy

    SQL> create table test_redos as select * from dba_objects where 1=2;
      
    表已创建。


查看当前redo量

view plaincopy

    SQL> select * from redo_size;
      
         VALUE
    ----------
         736


插入数据,看结果

view plaincopy

    SQL> insert into test_redos select * from dba_objects;
      
    已创建73104行。
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
       8473536
      
    SQL> insert /*+ append */ into test_redos select * from dba_objects;
      
    已创建73100行。
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
       8504856
      
    SQL> select (8473536-736)普通插入,(8504856-8473536) append插入 from dual;
      
      普通插入 APPEND插入
    ---------- ----------
       8472800      31320


以上结果说明在非归档模式下,append插入数据产生的redo要少得多。


二、在归档模式下(在数据库和表空间级别为设置force logging的情况下,默认非force logging):

view plaincopy

    SQL> archive log list;
    Database log mode            Archive Mode
    Automatic archival             Enabled
    Archive destination            /archive1
    Oldest online log sequence   114
    Next log sequence to archive   116
    Current log sequence         116


同上(非归档里面)建立测试表

①:在表为logging的情况下

view plaincopy

    SQL>create table test_redos as select * from dba_objects where 1=2;
      
    Table created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
         26812
      
    SQL> insert into test_redos select * from dba_objects;
      
    71971 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
       8490044
      
    SQL> insert /*+ append */ into test_redos select * from dba_objects;
      
    71971 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
      17001396
      
    SQL> select (8490044-26812)普通插入,(17001396-8490044) append插入 from dual;
      
      普通插入 APPEND插入
    ---------- ----------
       8463232    8511352
      


可以看出在归档模式表logging(默认)的情况下,append插入产生的redo量并不会减少。

②:在表nologging的情况下

将表设置为nologging模式

view plaincopy

    SQL> alter table test_redos nologging;
      
    Table altered.

继续测试

view plaincopy

    SQL> select * from redo_size;
      
         VALUE
    ----------
       8397184
      
    SQL> insert into test_redos select * from dba_objects;
      
    71971 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
      16801072
      
    SQL> insert /*+ append */ into test_redos select * from dba_objects;
      
    71971 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
      16836516
      
    SQL> select (16801072-8397184)普通插入,(16836516-16801072) append插入 from dual;
      
      普通插入 APPEND插入
    ---------- ----------
       8403888      35444


可以看出在表nologging的模式下,append可以减少大量减少redo量的产生。

三、在归档force logging模式下:

改变SCOTT用户的默认表空间为force logging模式

view plaincopy

    SQL> select username,default_tablespace from dba_users where username='SCOTT';
      
    USERNAME                     DEFAULT_TABLESPACE
    ------------------------------ ------------------------------
    SCOTT                        USERS
    --在数据级别置为force logging模式语句为 alter database force logging;
    SQL> alter tablespace users force logging;
      
    Tablespace altered.

继续测试

view plaincopy

    SQL> select * from redo_size;
      
         VALUE
    ----------
      25488368
      
    SQL> insert into test_redos select * from dba_objects;
      
    72010 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
      33973556
      
    SQL> insert /*+ append */ into test_redos select * from dba_objects;
      
    72010 rows created.
      
    SQL> select * from redo_size;
      
         VALUE
    ----------
      42492396
      
    SQL> select (33973556-25488368)普通插入,(42492396-33973556) append插入 from dual;
      
      普通插入 APPEND插入
    ---------- ----------
       8485188    8518840
      


可以看出在表空间在force logging模式下append不能减少redo量


总结:

非归档模式下:append能大量减少redo量。

归档模式下:在表空间和数据库级非force logging模式下,表如果是nologging,则append能大量减少redo量。
页: [1]
查看完整版本: 实验证明 Oracle能减少redo size的方法