0racle 11g release 1后提供了redo 日志传输压缩的功能,可以快速的解决归档日志gap的问题,可以在ASYNC/MaxPerformance redo transport模式下启用压缩,11.2.0.1版本以后也可以扩展到MaxProtection, MaxAvailability模式;本文介绍oracle 11g active data guard环境下(MAXIMUM AVAILABILITY)对redo传输的压缩; redo 日志传输压缩适用于redo切换快,带宽小且CPU强劲的data guard环境下!

一:查看日志传输的延时情况

   
   
   
   
  1. [root@db1 ~]# su - oracle  
  2. [oracle@db1 ~]$ sqlplus /nolog  
  3. SQL*Plus: Release 11.2.0.3.0 Production on Wed Nov 28 09:42:48 2012  
  4. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  5.  
  6. SQL> conn /as sysdba  
  7. Connected.  
  8.  
  9. SQL> select protection_mode,protection_level,database_role from v$database;  
  10.  
  11. PROTECTION_MODE      PROTECTION_LEVEL     DATABASE_ROLE  
  12. -------------------- -------------------- ----------------  
  13. MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY PRIMARY  
  14.  
  15. SQL> SELECT max(DURATION) FROM V$REDO_DEST_RESP_HISTOGRAM WHERE DEST_ID=2 AND FREQUENCY>1;  
  16.  
  17. MAX(DURATION)  
  18. -------------  
  19.             7  
  20.  
  21. SQL> SELECT min(DURATION) FROM V$REDO_DEST_RESP_HISTOGRAM WHERE DEST_ID=2 AND FREQUENCY>1;  
  22.  
  23. MIN(DURATION)  
  24. -------------  
  25.             1  
  26.  
  27. SQL>  SELECT FREQUENCY, DURATION FROM V$REDO_DEST_RESP_HISTOGRAM WHERE DEST_ID=2 AND FREQUENCY>1;  
  28.  FREQUENCY   DURATION  
  29. ---------- ----------  
  30.       4018          1  
  31.         13          2  
  32.         11          3  
  33.         11          4  
  34.          3          5  
  35.          2          6  
  36.          2          7  
  37. 7 rows selected. 

二:修改隐含参数_REDO_TRANSPORT_COMPRESS_ALL,重启实例

   
   
   
   
  1. SQL> col  parameter for a20  
  2. SQL> col value for a20  
  3.  
  4. SQL> select * from v$option where parameter ='Advanced Compression';  
  5.  
  6. PARAMETER            VALUE  
  7. -------------------- --------------------  
  8. Advanced Compression TRUE  
  9.  
  10. SQL> alter system set "_REDO_TRANSPORT_COMPRESS_ALL"=TRUE SCOPE=SPFILE;  
  11. System altered.  
  12.  
  13. SQL> show parameter COMPRESS;  
  14.  
  15. SQL> shutdown immediate  
  16. Database closed.  
  17. Database dismounted.  
  18. ORACLE instance shut down.  
  19. SQL> startup  
  20. ORACLE instance started.  
  21.  
  22. Total System Global Area 1536602112 bytes  
  23. Fixed Size                  2228624 bytes  
  24. Variable Size            1174408816 bytes  
  25. Database Buffers          352321536 bytes  
  26. Redo Buffers                7643136 bytes  
  27. Database mounted.  
  28. Database opened.  
  29.  
  30. SQL> show parameter COMPRESS;  
  31.  
  32. NAME                                 TYPE        VALUE  
  33. ------------------------------------ ----------- ------  
  34. _redo_transport_compress_all         boolean     TRUE 

三:修改log_archive_dest_2参数

   
   
   
   
  1. SQL> show parameter log_archive_dest_2;  
  2.  
  3. NAME                                 TYPE        VALUE  
  4. ------------------------------------ ----------- ------------------------------  
  5. log_archive_dest_2                   string      SERVICE=db2 lgwr sync valid_fo  
  6.                                                  r=(online_logfiles,primary_role  
  7.                                                  ) db_unique_name=db2 
  8.  
  9. SQL> alter system set log_archive_dest_2='SERVICE=db2 lgwr sync valid_for=(online_logfiles,primary_role) compression=enable db_unique_name=db2';  
  10. System altered.  
  11.  
  12. SQL> show parameter log_archive_dest_2  
  13.  
  14. NAME                                 TYPE        VALUE  
  15. ------------------------------------ ----------- ------------------------------  
  16. log_archive_dest_2                   string      SERVICE=db2 lgwr sync valid_fo  
  17.                                                  r=(online_logfiles,primary_rol  
  18.                                                  e) compression=enable db_uniqu  
  19.                                                  e_name=db2 

四:验证压缩

   
   
   
   
  1. SQL> select DEST_ID,COMPRESSION  from v$archive_dest where dest_id=2;  
  2.  
  3.    DEST_ID COMPRES  
  4. ---------- -------  
  5.          2 ENABLE  
  6.  
  7.  
  8. SQL> archive log list;  
  9. Database log mode              Archive Mode  
  10. Automatic archival             Enabled  
  11. Archive destination            USE_DB_RECOVERY_FILE_DEST  
  12. Oldest online log sequence     196  
  13. Next log sequence to archive   198  
  14. Current log sequence           198  
  15.  
  16. 压缩采用gzip 1方式进行,压缩及解压缩oracle全自动进行,压缩的比率到了79%:  
  17. [oracle@db1 2012_11_28]$ gzip -1  o1_mf_1_198_8cbvxpm1_.arc   
  18. [oracle@db1 2012_11_28]$ gzip --list o1_mf_1_198_8cbvxpm1_.arc.gz   
  19.          compressed        uncompressed  ratio uncompressed_name  
  20.              139090              671744  79.3% o1_mf_1_198_8cbvxpm1_.arc 

参考文章:
http://oraclehandson.wordpress.com/2011/01/07/enabling-redo-log-transport-compression/ (请×××访问!)
http://docs.oracle.com/cd/B28359_01/server.111/b28294/log_transport.htm#BABEBHHB
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=325669420448759&id=729551.1&_afrWindowMode=0&_adf.ctrl-state=7uubfwzms_4