標籤:
--版本資訊SELECT * FROM v$version;Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - ProdPL/SQL Release 10.2.0.5.0 - ProductionCORE 10.2.0.5.0 ProductionTNS for 32-bit Windows: Version 10.2.0.5.0 - ProductionNLSRTL Version 10.2.0.5.0 - Production--查看是否歸檔select name,log_mode from v$database;1 ORCL NOARCHIVELOG或sqlplus:ARCHIVE LOG LIST;--建立查看產生redo大小的視圖create or replace view redo_size asselect valuefrom v$mystat, v$statnamewhere v$mystat.statistic# = v$statname.statistic#and v$statname.name = ‘redo size‘;
1.在非歸檔模式下:
--!!!!!!!!!!!非歸檔模式 產生的redo!!!!!!!!!!!!!!!!!!--==============nologging表================SELECT * FROM sys.redo_size;--redo_size:0create table test_nolog nologging as select * from dba_objects where 1=0;--redo_size:17932insert into test_nolog select * from dba_objects;--redo_size:5772780 insert /*+ APPEND */ into test_nolog select * from dba_objects;--redo_size:5782548select (5782548-5772780) redo_append, (5772780-17932) redo_normal from dual;9768 5754848--================logging============================--redo_size:11778596create table test_log as select * from dba_objects where 1=0;--redo_size:11799284insert into test_log select * from dba_objects;--redo_size:17555812insert /*+ APPEND */ into test_log select * from dba_objects;--redo_size:17565544select (17565544-17555812) redo_append, (17555812-11799284) redo_normal from dual;9732 5756528
結論:非歸檔模式下,只需append就能大量減少redo的產生,如果不加append,即使是nologing表也會產生一樣多的redo;
2.在歸檔模式下:
--修改為歸檔模式set ORACLE_SID=ORCLsqlplus / as sysdbaSYS@ORCL> archive log list資料庫記錄模式 非存檔模式自動封存 禁用存檔終點 USE_DB_RECOVERY_FILE_DEST最早的聯機日誌序列 544當前日誌序列 546SYS@ORCL> select log_mode from v$database;LOG_MODE------------NOARCHIVELOGSYS@ORCL> shutdown immediate資料庫已經關閉。已經卸載資料庫。ORACLE 常式已經關閉。SYS@ORCL> startup mountORACLE 常式已經啟動。Total System Global Area 1258291200 bytesFixed Size 1304848 bytesVariable Size 201328368 bytesDatabase Buffers 1048576000 bytesRedo Buffers 7081984 bytes資料庫裝載完畢。SYS@ORCL> alter database ARCHIVELOG;資料庫已更改。SYS@ORCL> archive log list資料庫記錄模式 存檔模式自動封存 啟用存檔終點 USE_DB_RECOVERY_FILE_DEST最早的聯機日誌序列 544下一個存檔日誌序列 546當前日誌序列 546SYS@ORCL> alter database open;資料庫已更改。
--!!!!!!!!!!!歸檔模式 產生的redo!!!!!!!!!!!!!!!!!!--==============nologging表================SELECT * FROM redo_size;--redo_size:0insert into test_nolog select * from dba_objects;--redo_size:5729772 insert /*+ APPEND */ into test_nolog select * from dba_objects;--redo_size:5739436select (5739436-5729772) redo_append, (5729772-0) redo_normal from dual;9664 5729772--================loging============================--redo_size:5729772insert into test_log select * from dba_objects;--redo_size:11355620insert /*+ APPEND */ into test_log select * from dba_objects;--redo_size:17123736select (17123736-11355620) redo_append, (11355620-5729772) redo_normal from dual;5768116 5625848
結論:歸檔模式下,append並且表為nologging 才能減少redo的產生,其餘情況沒效果;
對比append插入資料產生的redo量