自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Oracle 從共享池刪除指定SQL的執(zhí)行計劃

運維 數(shù)據(jù)庫運維
Oracle 11g在DBMS_SHARED_POOL包中引入了一個名為PURGE的新存儲過程,用于從對象庫緩存中刷新特定對象,例如游標(biāo),包,序列,觸發(fā)器等。

[[440190]]

本文轉(zhuǎn)載自微信公眾號「DBA閑思雜想錄」,作者瀟湘隱者 。轉(zhuǎn)載本文請聯(lián)系DBA閑思雜想錄公眾號。

Oracle 11g在DBMS_SHARED_POOL包中引入了一個名為PURGE的新存儲過程,用于從對象庫緩存中刷新特定對象,例如游標(biāo),包,序列,觸發(fā)器等。也就是說可以刪除、清理特定SQL的執(zhí)行計劃, 這樣在特殊情況下,就避免你要將整個SHARED POOL清空的危險情況。例如某個SQL語句由于優(yōu)化器產(chǎn)生了錯誤的執(zhí)行計劃,我們希望優(yōu)化器重新解析,生成新的執(zhí)行計劃,必須無將SQL的執(zhí)行計劃從共享池中刷出或?qū)⑵渲脼闊o效,那么優(yōu)化器才能將后續(xù)SQL進(jìn)行硬解析、生成新的執(zhí)行計劃。這在以前只能使用清空共享池的方法或?qū)Ρ磉M(jìn)行DDL操作。現(xiàn)在就可以指定刷新特定SQL的執(zhí)行計劃。當(dāng)然在10.2.0.4 和10.2.0.5的補丁集中該包也被包含進(jìn)來,該包的存儲過程有三個參數(shù),如下所示:

  1. DBMS_SHARED_POOL.PURGE ( 
  2.    name    VARCHAR2,  
  3.    flag    CHAR DEFAULT 'P',  
  4.    heaps   NUMBER DEFAULT 1) 
  5.  
  6. Argument Name                  Type                    In/Out Default
  7.  ------------------------------ ----------------------- ------ -------- 
  8.  NAME                           VARCHAR2                IN 
  9.  FLAG                           CHAR                    IN     DEFAULT 
  10.  HEAPS                          NUMBER                  IN     DEFAULT 

第一個參數(shù)為逗號分隔的ADDRESS列和HASH_VALUE列的值。

第二個參數(shù)可以有多個選項,例如C、P、T、R、Q等。具體意義如下所示 C表示PURGE的對象是CURSOR

  1. Set to 'P' or 'p' to fully specify that the input is the name of a package/procedure/function
  2. Set to 'T' or 't' to specify that the input is the name of a type. 
  3. Set to 'R' or 'r' to specify that the input is the name of a trigger
  4. Set to 'Q' or 'q' to specify that the input is the name of a sequence
  5. ................................... 

第三個參數(shù)heaps,一般使用默認(rèn)值1

  1. Heaps to be purged. For example, if heap 0 and heap 6 are to be purged: 
  2. 1<<0 | 1<<6 => hex 0x41 => decimal 65, so specify heaps =>65.Default is 1, that is, heap 0 which means the whole object would be purged 

在ORACLE 11g當(dāng)中,你可以在$ORACLE_HOME/rdbms/admin/dbmspool.sql中查看該包的具體定義. 但是這個DBMS_SHARED_POOL.PURGE在10.2.0.4.0(實際測試發(fā)現(xiàn)10.2.0.5.0也存在同樣問題)都有一些問題,它可能無法生效,當(dāng)然在Oracle 11g中沒有這個問題,具體演示如下所示:

  1. SQL> select * from v$version; 
  2.  
  3. BANNER 
  4. ---------------------------------------------------------------- 
  5. Oracle Database 10g Release 10.2.0.5.0 - 64bit Production 
  6. PL/SQL Release 10.2.0.5.0 - Production 
  7. CORE    10.2.0.5.0      Production 
  8. TNS for Linux: Version 10.2.0.5.0 - Production 
  9. NLSRTL Version 10.2.0.5.0 - Production 
  10.  
  11. SQL> alter system flush shared_pool; 
  12.  
  13. System altered. 
  14.  
  15. SQL> set linesize 1200; 
  16. SQL> select * from scott.dept where deptno=40;  
  17.  
  18.     DEPTNO DNAME          LOC 
  19. ---------- -------------- ------------- 
  20.         40 OPERATIONS     BOSTON 
  21.  
  22. SQL> select sql_id, first_load_time 
  23.   2  from v$sql 
  24.   3  where sql_text like 'select * from scott.dept%'
  25.  
  26. SQL_ID        FIRST_LOAD_TIME 
  27. ------------- --------------------------------------------------------- 
  28. 3nvuzqdn6ry6x 2016-12-29/08:51:21 
  29.  
  30. SQL> col sql_text for a64; 
  31. SQL> select address, hash_value, sql_text 
  32.   2  from v$sqlarea 
  33.   3  where sql_id='3nvuzqdn6ry6x'
  34.  
  35. ADDRESS          HASH_VALUE SQL_TEXT 
  36. ---------------- ---------- ---------------------------------------------------------------- 
  37. 00000000968ED510 1751906525 select * from scott.dept where deptno=40 
  38.  
  39. SQL> exec dbms_shared_pool.purge('00000000968ED510,1751906525','C'); 
  40.  
  41. PL/SQL procedure successfully completed. 
  42.  
  43. SQL> select address, hash_value, sql_text 
  44.   2  from v$sqlarea 
  45.   3  where sql_id='3nvuzqdn6ry6x'
  46.  
  47. ADDRESS          HASH_VALUE SQL_TEXT 
  48. ---------------- ---------- ---------------------------------------------------------------- 
  49. 00000000968ED510 1751906525 select * from scott.dept where deptno=40 
  50.  
  51. SQL>  

如上截圖所示,DBMS_SHARED_POOL.PURGE并沒有清除這個特定的SQL的執(zhí)行計劃,其實這個是因為在10.2.0.4.0 要生效就必須開啟5614566 EVNET,否則不會生效。具體可以參考官方文檔:

  1. DBMS_SHARED_POOL.PURGE Is Not Working On 10.2.0.4 (文檔 ID 751876.1) 
  2. Bug 7538951 : DBMS_SHARED_POOL IS NOT WORKING AS EXPECTED 
  3. Bug 5614566 : WE NEED A FLUSH CURSOR INTERFACE 
  4.  
  5. DBMS_SHARED_POOL.PURGE is available from 11.1. In 10.2.0.4, it is available 
  6. through the fix for Bug 5614566. However, the fix is event protected.  You need to set the event 5614566 to make use of purge. Unless the event is set, dbms_shared_pool.purge will have no effect. 
  7.  
  8. Set the event 5614566 in the init.ora to turn purge on
  9.  
  10. event="5614566 trace name context forever" 

如下所示,設(shè)置5614566 event后,必須重啟數(shù)據(jù)庫才能生效,這個也是一個比較麻煩的事情。

  1. alter system set event = '5614566 trace name context forever' scope = spfile; 

 

責(zé)任編輯:武曉燕 來源: DBA閑思雜想錄
相關(guān)推薦

2009-11-18 17:05:47

捕獲Oracle SQ

2011-09-14 17:03:17

數(shù)據(jù)庫執(zhí)行計劃解析

2015-04-22 14:17:45

SQL SERVERMSSQL SERVE緩沖區(qū)

2009-11-10 16:00:05

Oracle執(zhí)行計劃

2009-11-13 16:28:02

Oracle生成執(zhí)行計

2011-08-18 14:10:51

Oracle不走索引

2010-10-27 15:26:42

Oracle執(zhí)行計劃

2023-03-02 08:13:53

Oracle共享池監(jiān)控

2017-09-22 11:01:00

Oracle數(shù)據(jù)庫中直方圖

2014-08-28 09:54:35

SQL Server

2010-11-04 14:25:19

DB2 SQL文執(zhí)行計

2024-06-12 09:23:37

2021-03-17 09:35:51

MySQL數(shù)據(jù)庫explain

2023-09-21 10:55:51

MysqlSQL語句

2021-05-28 10:46:36

MySQL執(zhí)行計劃

2011-08-18 09:19:19

SQL Server的SQL查詢優(yōu)化

2020-09-15 08:44:57

MySQL慢日志SQL

2010-04-16 09:27:18

Ocacle執(zhí)行計劃

2019-12-25 14:55:35

數(shù)據(jù)庫MySQLOracle

2022-08-15 15:09:26

SQL數(shù)據(jù)庫MySQL
點贊
收藏

51CTO技術(shù)棧公眾號