日期:2014-05-16  浏览次数:20589 次

Oracle 减少redo size的方法

用实验说明

一、在非归档模式下:

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

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

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

视图已创建。

用sys用户创建同义词

SQL> create public synonym redo_size for redo_size;

同义词已创建。

以下用scott操作

创建测试表

SQL> create table test_redos as select * from dba_objects where 1=2;

表已创建。

查看当前redo量

SQL> select * from redo_size;

     VALUE
----------
       736

插入数据,看结果

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):

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的情况下

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模式

SQL> alter table test_redos nologging;

Table altered.
继续测试

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模式

SQL> select username,default_tablespace from dba_users where username='SCOTT';

USERNAME                       DEFAULT_TABLESPACE
------------------------------ ------------------------------
SCOTT