{"id":20,"date":"2015-12-05T12:10:03","date_gmt":"2015-12-05T18:10:03","guid":{"rendered":"http:\/\/www.aamirharoon.com\/?p=20"},"modified":"2015-12-05T12:10:03","modified_gmt":"2015-12-05T18:10:03","slug":"flush-sql-cursor-cache-oracle-library-cache","status":"publish","type":"post","link":"http:\/\/www.aamirharoon.com\/?p=20","title":{"rendered":"How to Flush SQL Cursor Cache from Oracle Library Cache"},"content":{"rendered":"<div><\/div>\n<div class=\"fontplugin_fontid_1086_AllerRg\">\n<p>All most all of Oracle DBAs are familiar with command to flush shared pool: <span style=\"font-family: 'courier new';\">alter system flush shared_pool;<\/span><\/p>\n<\/div>\n<p class=\"fontplugin_fontid_1086_AllerRg\">This command clears all data from shared pool in system global area (SGA). \u00a0The shared pool stores cached data dictionary information and shared SQL and PL\/SQL areas of SQL Statements, stored procedures, packages, functions and triggers.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-101 size-full\" title=\"Oracle Memory Architecture\" src=\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\" alt=\"Library Cache\" width=\"589\" height=\"547\" srcset=\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg 589w, http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga-300x279.jpg 300w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p class=\"fontplugin_fontid_1086_AllerRg\">This command is handy for dev, test or performance environments. \u00a0But what if you want to only flush a single SQL Cursor cache? \u00a0What if the environment is Production and a program (like Informatica) is stuck using bad explain plan and you want only flush this one SQL Cursor cache so optimizer can hard parse again and pick up a different explain plain?<\/p>\n<div class=\"fontplugin_fontid_1086_AllerRg\">\n<p>To flush the cursor cache from Library Cache, you\u2019ll need SQL ID of the query\/cursor you want to flush.<\/p>\n<\/div>\n<div class=\"fontplugin_fontid_1086_AllerRg\">Use the SQL ID to get address of the handle to the parent for this cursor and hash value of the parent statement in the library cache from\u00a0<span style=\"font-family: 'courier new';\">v$sqlarea<\/span> <span class=\"fontplugin_fontid_1086_AllerRg\">view.<\/span><\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<pre class=\"c\" data-blogger-escaped-name=\"code\">SQL&gt; select address, hash_value \r\nfrom v$sqlarea \r\nwhere sql_id in ('0wdq0hfrj4qxk');\r\n\r\nADDRESS          HASH_VALUE\r\n---------------- ----------\r\n\r\n0700000C5480FE90 804411656\r\n<\/pre>\n<div>\n<p><span class=\"fontplugin_fontid_1086_AllerRg\" style=\"font-family: calibri, sans-serif;\">Use these 2 values to purge the cursor cache. 2<sup>nd<\/sup> parameter can be anything except &#8216;P&#8217; or &#8216;p&#8217; or &#8216;Q&#8217; or &#8216;q&#8217; or &#8216;R&#8217; or &#8216;r&#8217; or &#8216;T&#8217; or &#8216;t&#8217;.<\/span><\/p>\n<\/div>\n<div><\/div>\n<pre class=\"c\" data-blogger-escaped-name=\"code\">SQL&gt; exec dbms_shared_pool.purge('0700000C5480FE90, 804411656',<span style=\"color: #ff0000;\">'C'<\/span>);\r\n\r\nPL\/SQL procedure successfully completed.\r\n<\/pre>\n<\/div>\n<div><\/div>\n<div>\n<p><span style=\"font-family: calibri, sans-serif;\"><span class=\"fontplugin_fontid_1086_AllerRg\">Verify that cursor cache has been cleared.<\/span><\/span><\/p>\n<\/div>\n<div><\/div>\n<div>\n<pre class=\"c\" data-blogger-escaped-name=\"code\">SQL&gt; select address, hash_value \r\nfrom v$sqlarea \r\nwhere sql_id in ('0wdq0hfrj4qxk');\r\n\r\nno rows selected\r\n<\/pre>\n<\/div>\n<div><\/div>\n<div>\n<p><span style=\"font-family: Calibri;\"><span class=\"fontplugin_fontid_1086_AllerRg\">You can also run the following to generate purge sql:<\/span><\/span><\/p>\n<\/div>\n<div><\/div>\n<div class=\"fontplugin_fontid_368_monof55\">\n<pre class=\"c\" data-blogger-escaped-name=\"code\">SELECT 'exec dbms_shared_pool.purge(''' || ADDRESS || ',' || HASH_VALUE || ''',''C'');' \r\nFROM V$SQLAREA \r\nWHERE SQL_TEXT LIKE 'SELECT col1 from tab1%';\r\n\r\nSELECT 'exec dbms_shared_pool.purge(''' || ADDRESS || ',' || HASH_VALUE || ''',''C'');' \r\nFROM V$SQLAREA \r\nwhere sql_id in ('0wdq0hfrj4qxk');\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>All most all of Oracle DBAs are familiar with command to flush shared pool: alter system flush shared_pool; This command clears all data from shared<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[30,33,31,32,28,29],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-11gr2","category-12cr1","tag-cache","tag-explain-plan","tag-oracle","tag-performance","tag-sql","tag-sql-cursor"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.aamirharoon.com\/?p=20\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman\" \/>\n<meta property=\"og:description\" content=\"All most all of Oracle DBAs are familiar with command to flush shared pool: alter system flush shared_pool; This command clears all data from shared\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.aamirharoon.com\/?p=20\" \/>\n<meta property=\"og:site_name\" content=\"The Database Handyman\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-05T18:10:03+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\" \/>\n<meta name=\"author\" content=\"Aamir\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@aamir814\" \/>\n<meta name=\"twitter:site\" content=\"@aamir814\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aamir\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20\"},\"author\":{\"name\":\"Aamir\",\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63\"},\"headline\":\"How to Flush SQL Cursor Cache from Oracle Library Cache\",\"datePublished\":\"2015-12-05T18:10:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20\"},\"wordCount\":229,\"commentCount\":1,\"publisher\":{\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63\"},\"image\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\",\"keywords\":[\"cache\",\"explain plan\",\"oracle\",\"performance\",\"sql\",\"sql cursor\"],\"articleSection\":[\"Oracle Database 11gR2\",\"Oracle Database 12cR1\"],\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/www.aamirharoon.com\/?p=20#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20\",\"url\":\"http:\/\/www.aamirharoon.com\/?p=20\",\"name\":\"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman\",\"isPartOf\":{\"@id\":\"http:\/\/www.aamirharoon.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\",\"datePublished\":\"2015-12-05T18:10:03+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.aamirharoon.com\/?p=20\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#primaryimage\",\"url\":\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\",\"contentUrl\":\"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\",\"width\":589,\"height\":547},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.aamirharoon.com\/?p=20#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.aamirharoon.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Flush SQL Cursor Cache from Oracle Library Cache\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.aamirharoon.com\/#website\",\"url\":\"http:\/\/www.aamirharoon.com\/\",\"name\":\"The Database Handyman\",\"description\":\"My notes about Oracle Database, APEX, OEM Cloud Control and whatever I learn\",\"publisher\":{\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.aamirharoon.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63\",\"name\":\"Aamir\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/63cc5bb07711a1b9719cc47e13a8205072859c1aef30fac28f412baa84b9cf9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/63cc5bb07711a1b9719cc47e13a8205072859c1aef30fac28f412baa84b9cf9b?s=96&d=mm&r=g\",\"caption\":\"Aamir\"},\"logo\":{\"@id\":\"http:\/\/www.aamirharoon.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.aamirharoon.com\/about\/\",\"https:\/\/x.com\/aamir814\"],\"url\":\"http:\/\/www.aamirharoon.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.aamirharoon.com\/?p=20","og_locale":"en_US","og_type":"article","og_title":"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman","og_description":"All most all of Oracle DBAs are familiar with command to flush shared pool: alter system flush shared_pool; This command clears all data from shared","og_url":"http:\/\/www.aamirharoon.com\/?p=20","og_site_name":"The Database Handyman","article_published_time":"2015-12-05T18:10:03+00:00","og_image":[{"url":"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","type":"","width":"","height":""}],"author":"Aamir","twitter_card":"summary_large_image","twitter_creator":"@aamir814","twitter_site":"@aamir814","twitter_misc":{"Written by":"Aamir","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.aamirharoon.com\/?p=20#article","isPartOf":{"@id":"http:\/\/www.aamirharoon.com\/?p=20"},"author":{"name":"Aamir","@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63"},"headline":"How to Flush SQL Cursor Cache from Oracle Library Cache","datePublished":"2015-12-05T18:10:03+00:00","mainEntityOfPage":{"@id":"http:\/\/www.aamirharoon.com\/?p=20"},"wordCount":229,"commentCount":1,"publisher":{"@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63"},"image":{"@id":"http:\/\/www.aamirharoon.com\/?p=20#primaryimage"},"thumbnailUrl":"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","keywords":["cache","explain plan","oracle","performance","sql","sql cursor"],"articleSection":["Oracle Database 11gR2","Oracle Database 12cR1"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/www.aamirharoon.com\/?p=20#respond"]}]},{"@type":"WebPage","@id":"http:\/\/www.aamirharoon.com\/?p=20","url":"http:\/\/www.aamirharoon.com\/?p=20","name":"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman","isPartOf":{"@id":"http:\/\/www.aamirharoon.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.aamirharoon.com\/?p=20#primaryimage"},"image":{"@id":"http:\/\/www.aamirharoon.com\/?p=20#primaryimage"},"thumbnailUrl":"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","datePublished":"2015-12-05T18:10:03+00:00","breadcrumb":{"@id":"http:\/\/www.aamirharoon.com\/?p=20#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.aamirharoon.com\/?p=20"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"http:\/\/www.aamirharoon.com\/?p=20#primaryimage","url":"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","contentUrl":"http:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","width":589,"height":547},{"@type":"BreadcrumbList","@id":"http:\/\/www.aamirharoon.com\/?p=20#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.aamirharoon.com\/"},{"@type":"ListItem","position":2,"name":"How to Flush SQL Cursor Cache from Oracle Library Cache"}]},{"@type":"WebSite","@id":"http:\/\/www.aamirharoon.com\/#website","url":"http:\/\/www.aamirharoon.com\/","name":"The Database Handyman","description":"My notes about Oracle Database, APEX, OEM Cloud Control and whatever I learn","publisher":{"@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.aamirharoon.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":["Person","Organization"],"@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/dbcd256c4a97c6e27b7cc408200a9b63","name":"Aamir","image":{"@type":"ImageObject","inLanguage":"en","@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/63cc5bb07711a1b9719cc47e13a8205072859c1aef30fac28f412baa84b9cf9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/63cc5bb07711a1b9719cc47e13a8205072859c1aef30fac28f412baa84b9cf9b?s=96&d=mm&r=g","caption":"Aamir"},"logo":{"@id":"http:\/\/www.aamirharoon.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.aamirharoon.com\/about\/","https:\/\/x.com\/aamir814"],"url":"http:\/\/www.aamirharoon.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":21,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":342,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/342"}],"wp:attachment":[{"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}