[20171120]11G關閉直接路徑讀.txt--//今天做filesystemio_options參數測試時,遇到一個關於直接路徑讀的問題.--//如果看以前的博客介紹,設置"_serial_direct_read"=never或者events '10949 trace name context ...
[20171120]11G關閉直接路徑讀.txt
--//今天做filesystemio_options參數測試時,遇到一個關於直接路徑讀的問題.
--//如果看以前的博客介紹,設置"_serial_direct_read"=never或者events '10949 trace name context forever';就可以關閉直接路徑讀.
--//我的測試在11GR2下set events '10949 trace name context forever';不行.
--//通過例子來說明問題
1.環境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SCOTT@book> create table t as select rownum id from dual connect by level<=2;
Table created.
SCOTT@book> ALTER TABLE t MINIMIZE RECORDS_PER_BLOCK ;
Table altered.
--//這樣可以實現每塊2條記錄.
SCOTT@book> insert into t select rownum+2 from dual connect by level <=64000-2;
63998 rows created.
SCOTT@book> commit ;
Commit complete.
insert into t select * from t;
insert into t select * from t;
insert into t select * from t;
commit ;
--//分析表略.
SCOTT@book> select OWNER,SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK,BYTES,BLOCKS from dba_segments where owner=user and segment_name='T';
OWNER SEGMENT_NAME SEGMENT_TYPE HEADER_FILE HEADER_BLOCK BYTES BLOCKS
------ -------------------- ------------------ ----------- ------------ ---------- ----------
SCOTT T TABLE 4 546 2153775104 262912
--//占用2153775104/1024/1024=2054M,262912塊.
SCOTT@book> select object_id,data_object_id from dba_objects where owner=user and object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
90702 90702
2.測試1:
SCOTT@book> alter system flush buffer_cache;
System altered.
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
0
SCOTT@book> select count(*) from t ;
COUNT(*)
----------
512000
SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 45vdc2q5hs1f3, child number 1
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 71059 (100)| | 1 |00:00:01.24 | 256K| 256K|
| 1 | SORT AGGREGATE | | 1 | 1 | | | 1 |00:00:01.24 | 256K| 256K|
| 2 | TABLE ACCESS FULL| T | 1 | 512K| 71059 (1)| 00:14:13 | 512K|00:00:01.21 | 256K| 256K|
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
11
--//看reads=256K,僅僅緩存11塊就能確定問題.現在是直接路徑讀.執行多次看執行依舊.
SCOTT@book> @ &r/viewsess "physical reads direct"
NAME STATISTIC# VALUE SID
------------------------------------------ ---------- ---------- ----------
physical reads direct 97 256064 274
physical reads direct temporary tablespace 110 0 274
physical reads direct (lob) 176 0 274
3.測試set events '10949 trace name context forever';
SCOTT@book> host oerr ora 10949
10949, 00000, "Disable autotune direct path read for full table scan"
// *Cause:
// *Action: Disable autotune direct path read for serial full table scan.
--//按照介紹應該這個也可以.
SCOTT@book> alter session set events '10949 trace name context forever';
Session altered.
SCOTT@book> alter session set statistics_level=all ;
Session altered.
SCOTT@book> alter system flush buffer_cache;
System altered.
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
0
SCOTT@book> select count(*) from t ;
COUNT(*)
----------
512000
SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 45vdc2q5hs1f3, child number 1
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 71059 (100)| | 1 |00:00:00.71 | 256K| 256K|
| 1 | SORT AGGREGATE | | 1 | 1 | | | 1 |00:00:00.71 | 256K| 256K|
| 2 | TABLE ACCESS FULL| T | 1 | 512K| 71059 (1)| 00:14:13 | 512K|00:00:00.69 | 256K| 256K|
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
20 rows selected.
SCOTT@book> @ &r/viewsess "physical reads direct"
NAME STATISTIC# VALUE SID
------------------------------------------ ---------- ---------- ----------
physical reads direct 97 256064 274
physical reads direct temporary tablespace 110 0 274
physical reads direct (lob) 176 0 274
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
11
--//看reads=256K,僅僅緩存11塊就能確定問題.現在是直接路徑讀.執行多次看執行依舊.
--//說明設置set events '10949 trace name context forever';無法關閉直接路徑讀.
4.設置"_serial_direct_read"=never;
SCOTT@book> alter session set "_serial_direct_read"=never;
Session altered.
SCOTT@book> alter session set statistics_level=all ;
Session altered.
SCOTT@book> alter system flush buffer_cache;
System altered.
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
0
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
0
SCOTT@book> select count(*) from t ;
COUNT(*)
----------
512000
SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 45vdc2q5hs1f3, child number 1
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 71059 (100)| | 1 |00:00:01.80 | 256K| 256K|
| 1 | SORT AGGREGATE | | 1 | 1 | | | 1 |00:00:01.80 | 256K| 256K|
| 2 | TABLE ACCESS FULL| T | 1 | 512K| 71059 (1)| 00:14:13 | 512K|00:00:01.78 | 256K| 256K|
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
SCOTT@book> @ &r/viewsess "physical reads direct"
NAME STATISTIC# VALUE SID
---------------------------------------------------------------------- ---------- ---------- ----------
physical reads direct 97 0 274
physical reads direct temporary tablespace 110 0 274
physical reads direct (lob) 176 0 274
--//直接路徑讀為0
SCOTT@book> select count(*) from v$bh where OBJD=90702 and STATUS<>'free';
COUNT(*)
----------
49959
--//已經緩存了49959塊.多次執行如下語句:
SCOTT@book> select count(*) from t ;
COUNT(*)
----------
512000
SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 45vdc2q5hs1f3, child number 1
-------------------------------------
select count(*) from t
Plan hash value: 2966233522
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 71059 (100)| | 1 |00:00:01.37 | 256K| 217K|
| 1 | SORT AGGREGATE | | 1 | 1 | | | 1 |00:00:01.37 | 256K| 217K|
| 2 | TABLE ACCESS FULL| T | 1 | 512K| 71059 (1)| 00:14:13 | 512K|00:00:01.35 | 256K| 217K|
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / T@SEL$1
20 rows selected.
--//你可以發現讀的數量降到了217K塊.
總結:
--//測試一定要註意一些oracle版本的變化,一些參數可能隨著版本的變化發生變化.
--//這也是我為什麼每次寫blog都指明我當前的使用版本.
--//關閉直接路徑讀alter session set "_serial_direct_read"=never;對於11GR2才有效.