[20180822]session_cached_cursors與子游標堆0.txt

lfree發表於2018-08-22

[20180822]session_cached_cursors與子游標堆0.txt

--//前幾天測試重新整理共享池與父子游標的問題,
--//連結: http://blog.itpub.net/267265/viewspace-2200066/=>[20180813]重新整理共享池與父子游標.txt
--//我測試如果語句被回話快取時,重新整理共享池後,
--//父子游標,父遊標堆0,子游標都沒有清除.並且KGLHDLMD=1
--//子游標堆0,子游標堆6會被清除.
--//晚上看<oracle核心技術揭密>時,提到對於快取的遊標,子游標堆0的記憶體也不會被覆蓋.程式在掃描LRU尋找可覆蓋的chunk時,如果發
--//現子游標堆0,會檢查它對應的子游標控制程式碼上是否有1號Library cache lock.如果有,會將其從LRU中去掉,而子游標堆6就沒有這種"待
--//遇".也就是這樣方式父子游標,父遊標堆0,子游標,子游標堆0都沒有清除,僅僅子游標堆6會被清除.
--//與重新整理共享池操作有一點點不同,差別在於子游標堆0是否被清除覆蓋,我重複驗證看看:

1.環境
SCOTT@book> @ 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> show parameter session_cached_cursors
NAME                   TYPE    VALUE
---------------------- ------- -----
session_cached_cursors integer 50

SCOTT@book> show parameter open_cursors
NAME         TYPE    VALUE
------------ ------- -----
open_cursors integer 300

SCOTT@book> alter system set open_cursors=50000 scope=memory;
System altered.

--//注意這個引數設定後要退出才會生效!!

2.測試:

--//session 1:
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
select * from dept where deptno=10;
--//確定sql_id=4xamnunv51w9j,可以查詢v$sql檢視確定.

SYS@book> @ &r/sharepool/shp4 4xamnunv51w9j 0
TEXT           KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
-------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 000000007D4B8000 000000007D4B8390 select * from dept where deptno=10                0          0          0 000000007D07E040 000000007D07E838       4528      12144       3067     19739      19739  911274289 4xamnunv51w9j          0
父遊標控制程式碼地址 000000007D4B8390 000000007D4B8390 select * from dept where deptno=10                0          0          0 000000007D0D6318 00                     4720          0          0      4720       4720  911274289 4xamnunv51w9j      65535

--//建立測試指令碼,僅僅分析sql語句,不執行.這樣利用前面設定open_cursor引數,消耗共享池記憶體.
create table a1( id1 number,id2 number);

$ cat ac.sql
declare
msql varchar2(500);
mcur number;
mstat number;
begin
    for i in 1 .. 49000 loop
        mcur := dbms_sql.open_cursor;
        msql := 'select id1 from a1 where id2='||to_char(i);
        dbms_sql.parse(mcur,msql,dbms_sql.native);
--        mstat := dbms_sql.execute(mcur);
    end loop;
end;
/

3.執行測試指令碼:
SCOTT@book> @ ac.sql
--//等,報錯!!
declare
*
ERROR at line 1:
ORA-04031: unable to allocate 32 bytes of shared memory ("shared pool","select job, nvl2(last_date, ...","SQLA","tmp")
ORA-06512: at "SYS.DBMS_SQL", line 1199
ORA-06512: at line 9

SYS@book> @ &r/sharepool/shp4 4xamnunv51w9j 0
TEXT           KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
-------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 000000007D4B8000 000000007D4B8390 select * from dept where deptno=10                1          0          0 000000007D07E040 00                     4528          0       3067      7595       7595  911274289 4xamnunv51w9j          0
父遊標控制程式碼地址 000000007D4B8390 000000007D4B8390 select * from dept where deptno=10                1          0          0 000000007D0D6318 00                     4720          0          0      4720       4720  911274289 4xamnunv51w9j      65535

--//確實,子游標堆0沒有清除.不過有點奇怪的是重新整理共享池可以清除子游標堆0,不理解.

SYS@book> alter system flush shared_pool;
System altered.

SYS@book> @ &r/sharepool/shp4 4xamnunv51w9j 0
TEXT           KGLHDADR         KGLHDPAR         C40                                        KGLHDLMD   KGLHDPMD   KGLHDIVC KGLOBHD0         KGLOBHD6           KGLOBHS0   KGLOBHS6   KGLOBT16   N0_6_16        N20   KGLNAHSH KGLOBT03        KGLOBT09
-------------- ---------------- ---------------- ---------------------------------------- ---------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 000000007D4B8000 000000007D4B8390 select * from dept where deptno=10                1          0          1 00               00                        0          0       3067      3067       3067  911274289 4xamnunv51w9j          0
父遊標控制程式碼地址 000000007D4B8390 000000007D4B8390 select * from dept where deptno=10                1          0          1 000000007D0D6318 00                     4720          0          0      4720       4720  911274289 4xamnunv51w9j      65535

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2212613/,如需轉載,請註明出處,否則將追究法律責任。

相關文章