nolog和append的使用
Nologging只在很少情況下生效,通常,DML操作總是要生成redo的,關於Nologging和append,一直存在很多誤解.經過一系列研究,終於發現了Nologging的真相.
1.Nologging的設定跟資料庫的執行模式有關
a.資料庫執行在非歸檔模式下:
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradata/hsjf/archive
Oldest online log sequence 155
Current log sequence 157
SQL> @redo
SQL> create table test as select * from dba_objects where 1=0;
Table created.
SQL> select * from redo_size;
VALUE
----------
63392
SQL> insert into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
1150988
SQL> insert /*+ append */ into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
1152368
SQL> select (1152368 -1150988) redo_append,(1150988 -63392) redo from dual;
REDO_APPEND REDO
----------- ----------
1380 1087596
SQL> drop table test;
Table dropped.
我們看到在Noarchivelog模式下,對於常規表的insert append只產生少量redo
b.在歸檔模式下
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 235999908 bytes
Fixed Size 451236 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> @redo
SQL> create table test as select * from dba_objects where 1=0;
Table created.
SQL> select * from redo_size;
VALUE
----------
56288
SQL>
SQL> insert into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
1143948
SQL> insert /*+ append */ into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
2227712
SQL> select (2227712 -1143948) redo_append,(1143948 -56288) redo from dual;
REDO_APPEND REDO
----------- ----------
1083764 1087660
SQL> drop table test;
Table dropped.
在歸檔模式下,對於常規表的insert append產生和insert同樣的redo,此時的insert append實際上並不會有效能提高,但是此時的append是生效了的
透過Logmnr分析日誌得到以下結果:
SQL> select operation,count(*)
from v$logmnr_contents
group by operation;
OPERATION COUNT(*)
-------------------------------- ----------
COMMIT 17
DIRECT INSERT 10470
INTERNAL 49
START 17
1
我們注意到這裡是DIRECT INSERT,而且是10470條記錄,也就是每條記錄都記錄了redo.
2.對於Nologging的table的處理
a. 在歸檔模式下:
SQL> create table test nologging as select * from dba_objects where 1=0;
Table created.
SQL> select * from redo_size;
VALUE
----------
2270284
SQL>
SQL> insert into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
3357644
SQL>
SQL> insert /*+ append */ into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
3359024
SQL> select (3359024 -3357644) redo_append,(3357644 - 2270284) redo from dual;
REDO_APPEND REDO
----------- ----------
1380 1087360
SQL> drop table test;
Table dropped.
我們注意到,只有append才能減少redo
b.在非歸檔模式下:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 235999908 bytes
Fixed Size 451236 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> alter database noarchivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> @redo
SQL> create table test nologging as select * from dba_objects where 1=0;
Table created.
SQL> select * from redo_size;
VALUE
----------
56580
SQL>
SQL> insert into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
1144148
SQL>
SQL> insert /*+ append */ into test select * from dba_objects;
10470 rows created.
SQL> select * from redo_size;
VALUE
----------
1145528
SQL> select (1145528 -1144148) redo_append,(1144148 -56580) redo from dual;
REDO_APPEND REDO
----------- ----------
1380 1087568
同樣只有append才能減少redo的生成.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/751371/viewspace-716059/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- jQuery的append和appendTojQueryAPP
- nologgin和appendAPP
- append和nologging的案例APP
- 使用 append 方法追加元素APP
- NOLOG方式重啟資料庫資料庫
- oracle nologging和appendOracleAPP
- go中陣列,切片和append的玄學Go陣列APP
- CTAS和insert append的一個測試APP
- sqlplus /nolog 是什麼意思SQL
- nologging和insert /*+append*/APP
- jquery中append、prepend, before和after方法的區別jQueryAPP
- 聊聊Append、nologging和Redo LogAPP
- URLSearchParams append()APP
- jQuery append()jQueryAPP
- golang appendGolangAPP
- Append HintAPP
- pandas中如何使用合併append函式?APP函式
- append2 給append 新增回撥方法APP
- 關於加快INSERT語句執行速度和 HINT /*+ append*/及nologging的使用APP
- Python3中列表方法append()和extend()的區別PythonAPP
- python append()PythonAPP
- URLSearchParams append() 方法APP
- 列表中的append,extend,+=,+的區別APP
- append與 appendTo的區別APP
- 臨時表的APPEND方式插入APP
- insert的時候使用append會不會影響到表的大小APP
- 關於dbstart指令碼啟動資料庫後無法使用sqlplus /nolog連線的問題指令碼資料庫SQL
- Parallel DML和append將在表上產生exclusive lockParallelAPP
- append HINT 的對事務的影響APP
- [golang]slice的坑:從append到共享GolangAPP
- 關於append sql hint的實驗APPSQL
- APPEND時的TM鎖定級別APP
- 歸檔模式下的 nologging和/*+ append */引數 效能測試模式APP
- append()與html() 區別APPHTML
- 使用append+nologging引起恢復故障實驗APP
- insert /*+ append */ into 與insert into 的區別APP
- insert append需要注意的問題APP
- 關於/*+append*/的一點小常識APP