[20201111]CURSOR_SPACE_FOR_TIME.txt
[20201111]CURSOR_SPACE_FOR_TIME.txt
--//引數CURSOR_SPACE_FOR_TIME從11g開始已經過時,引入它的初衷是為了緩解child cursor上的與庫快取相關的Latch爭用,11G開始使
--//用MUTEX替換各種與庫快取相關的Latch。
oracle的cursor是有生命週期的,每個session cursor在使用的過程中都至少會經歷一次open,parse,bind,execute,fetch和close中的一
個或者多個階段。當一個目標sql所對應的session cursor的狀態是execute時(即該sql正在執行),oracle會把該SQL語句所對於的child
cursor 給pin在庫快取(11g應該使用mutex)。
在CURSOR_SPACE_FOR_TIME=FALSE的情況下,一旦執行sql語句完畢,對應的session cursor的狀態已經不是execute狀態,此時sql所對應
的child cursor就可以不再pin在庫快取中,意味著如果共享池記憶體緊張,該SQL語句解析樹和執行計劃可以背換出共享池。
如果設定CURSOR_SPACE_FOR_TIME=TRUE。每次session cursor在execute完成後,對應的child cursor上的library cache pin不會釋放。
下次執行時就不會重複pin操作,減少latch的爭用。當然副作用就是對應的child cursor不會釋放,導致共享記憶體緊張。
簡單測試看看
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
SYS@book> alter system set CURSOR_SPACE_FOR_TIME=true scope=spfile;
System altered.
--//重啟資料庫:
SYS@book> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ORACLE instance started.
Total System Global Area 643084288 bytes
Fixed Size 2255872 bytes
Variable Size 205521920 bytes
Database Buffers 427819008 bytes
Redo Buffers 7487488 bytes
Database mounted.
Database opened.
select p.name,p.value
from v$parameter p, v$spparameter s
where s.name=p.name
and p.isdeprecated='TRUE'
and s.isspecified='TRUE';
NAME VALUE
---------------------------------------- ------------------------------
cursor_space_for_time TRUE
--//很明顯11g已經廢除了該引數。在10g下測試看看:
SYS@test> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx 10.2.0.4.0 Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
SYS@test> alter system set cursor_space_for_time=true scope=spfile;
System altered.
--//重啟略:
2.測試:
--//session 1:
SCOTT@test> select count(*) from dept;
COUNT(*)
----------
4
SCOTT@test> @ &r/tpt/hash
HASH_VALUE SQL_ID CHILD_NUMBER HASH_HEX
---------- ------------- ------------ ---------
761178024 1jrz3ucqpx9x8 0 2d5ea7a8
--//session 2:
SYS@test> @ &r/sharepool/shp4 1jrz3ucqpx9x8 0
TEXT KGLHDADR KGLHDPAR C40 KGLHDLMD KGLHDPMD KGLHDIVC KGLOBHD0 KGLOBHD6 KGLOBHS0 KGLOBHS6 KGLOBT16 N0_6_16 N20 KGLNAHSH KGLOBT03 KGLOBT09
-------------- ---------------- ---------------- ------------------------- -------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 0000000077575EF8 0000000077576E28 select count(*) from dept 1 0 0 0000000077575E38 0000000077576778 3664 8088 1794 13546 13546 761178024 1jrz3ucqpx9x8 0
父遊標控制程式碼地址 0000000077576E28 0000000077576E28 select count(*) from dept 1 0 0 0000000077576D68 00 2803 0 0 2803 2803 761178024 1jrz3ucqpx9x8 65535
SYS@test> alter system flush shared_pool;
System altered.
SYS@test> @ &r/sharepool/shp4 1jrz3ucqpx9x8 0
TEXT KGLHDADR KGLHDPAR C40 KGLHDLMD KGLHDPMD KGLHDIVC KGLOBHD0 KGLOBHD6 KGLOBHS0 KGLOBHS6 KGLOBT16 N0_6_16 N20 KGLNAHSH KGLOBT03 KGLOBT09
-------------- ---------------- ---------------- ------------------------- -------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 0000000077575EF8 0000000077576E28 select count(*) from dept 0 0 1 00 00 0 0 1794 1794 1794 761178024 1jrz3ucqpx9x8 0
父遊標控制程式碼地址 0000000077576E28 0000000077576E28 select count(*) from dept 1 0 1 0000000077576D68 00 2803 0 0 2803 2803 761178024 1jrz3ucqpx9x8 65535
--//一樣清除子游標的堆0與堆6.看看在執行狀態如何:
SCOTT@test> select count(*) from dept;
COUNT(*)
----------
4
SYS@test> @ &r/sharepool/shp4 1jrz3ucqpx9x8 0
TEXT KGLHDADR KGLHDPAR C40 KGLHDLMD KGLHDPMD KGLHDIVC KGLOBHD0 KGLOBHD6 KGLOBHS0 KGLOBHS6 KGLOBT16 N0_6_16 N20 KGLNAHSH KGLOBT03 KGLOBT09
-------------- ---------------- ---------------- ------------------------- -------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 0000000077575EF8 0000000077576E28 select count(*) from dept 1 2 1 0000000077575E38 0000000077576778 3664 8088 1794 13546 13546 761178024 1jrz3ucqpx9x8 0
父遊標控制程式碼地址 0000000077576E28 0000000077576E28 select count(*) from dept 1 0 1 0000000077576D68 00 2803 0 0 2803 2803 761178024 1jrz3ucqpx9x8 65535
SYS@test> alter system flush shared_pool;
System altered.
SYS@test> @ &r/sharepool/shp4 1jrz3ucqpx9x8 0
TEXT KGLHDADR KGLHDPAR C40 KGLHDLMD KGLHDPMD KGLHDIVC KGLOBHD0 KGLOBHD6 KGLOBHS0 KGLOBHS6 KGLOBT16 N0_6_16 N20 KGLNAHSH KGLOBT03 KGLOBT09
-------------- ---------------- ---------------- ------------------------- -------- ---------- ---------- ---------------- ---------------- ---------- ---------- ---------- --------- ---------- ---------- ------------- ----------
子游標控制程式碼地址 0000000077575EF8 0000000077576E28 select count(*) from dept 0 2 2 0000000077575E38 0000000077576778 3664 8088 1794 13546 13546 761178024 1jrz3ucqpx9x8 0
父遊標控制程式碼地址 0000000077576E28 0000000077576E28 select count(*) from dept 1 0 2 0000000077576D68 00 2803 0 0 2803 2803 761178024 1jrz3ucqpx9x8 65535
--//在這樣狀態下,無論如何重新整理共享池,子游標的堆0與堆6不會清除。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2733896/,如需轉載,請註明出處,否則將追究法律責任。