{"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":"https:\/\/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=\"https:\/\/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=\"https:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg\" alt=\"Library Cache\" width=\"589\" height=\"547\" srcset=\"https:\/\/aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg 589w, https:\/\/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 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. &nbsp; [&hellip;]<\/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"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\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=\"https:\/\/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 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. &nbsp; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/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=\"https:\/\/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\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20\"},\"author\":{\"name\":\"Aamir\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#\\\/schema\\\/person\\\/5b7250c4974dcf9818ca431e21831c75\"},\"headline\":\"How to Flush SQL Cursor Cache from Oracle Library Cache\",\"datePublished\":\"2015-12-05T18:10:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20\"},\"wordCount\":229,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#\\\/schema\\\/person\\\/5b7250c4974dcf9818ca431e21831c75\"},\"image\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/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\":[\"https:\\\/\\\/aamirharoon.com\\\/?p=20#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20\",\"url\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20\",\"name\":\"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.aamirharoon.com\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/shared_pool_sga.jpg\",\"datePublished\":\"2015-12-05T18:10:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/aamirharoon.com\\\/?p=20\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#primaryimage\",\"url\":\"https:\\\/\\\/www.aamirharoon.com\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/shared_pool_sga.jpg\",\"contentUrl\":\"https:\\\/\\\/www.aamirharoon.com\\\/wp-content\\\/uploads\\\/2015\\\/10\\\/shared_pool_sga.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/?p=20#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/aamirharoon.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Flush SQL Cursor Cache from Oracle Library Cache\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#website\",\"url\":\"https:\\\/\\\/aamirharoon.com\\\/\",\"name\":\"The Database Handyman\",\"description\":\"Cloud Architecture. Open-Source Databases. Data-Driven Solutions.\",\"publisher\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#\\\/schema\\\/person\\\/5b7250c4974dcf9818ca431e21831c75\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/aamirharoon.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/#\\\/schema\\\/person\\\/5b7250c4974dcf9818ca431e21831c75\",\"name\":\"Aamir\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/cropped-IMG_2639-scaled-1.jpg\",\"url\":\"https:\\\/\\\/aamirharoon.com\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/cropped-IMG_2639-scaled-1.jpg\",\"contentUrl\":\"https:\\\/\\\/aamirharoon.com\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/cropped-IMG_2639-scaled-1.jpg\",\"width\":512,\"height\":512,\"caption\":\"Aamir\"},\"logo\":{\"@id\":\"https:\\\/\\\/aamirharoon.com\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/cropped-IMG_2639-scaled-1.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.aamirharoon.com\\\/about\\\/\",\"https:\\\/\\\/x.com\\\/aamir814\"],\"url\":\"https:\\\/\\\/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":"https:\/\/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 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. &nbsp; [&hellip;]","og_url":"https:\/\/aamirharoon.com\/?p=20","og_site_name":"The Database Handyman","article_published_time":"2015-12-05T18:10:03+00:00","og_image":[{"url":"https:\/\/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":"https:\/\/aamirharoon.com\/?p=20#article","isPartOf":{"@id":"https:\/\/aamirharoon.com\/?p=20"},"author":{"name":"Aamir","@id":"https:\/\/aamirharoon.com\/#\/schema\/person\/5b7250c4974dcf9818ca431e21831c75"},"headline":"How to Flush SQL Cursor Cache from Oracle Library Cache","datePublished":"2015-12-05T18:10:03+00:00","mainEntityOfPage":{"@id":"https:\/\/aamirharoon.com\/?p=20"},"wordCount":229,"commentCount":1,"publisher":{"@id":"https:\/\/aamirharoon.com\/#\/schema\/person\/5b7250c4974dcf9818ca431e21831c75"},"image":{"@id":"https:\/\/aamirharoon.com\/?p=20#primaryimage"},"thumbnailUrl":"https:\/\/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":["https:\/\/aamirharoon.com\/?p=20#respond"]}]},{"@type":"WebPage","@id":"https:\/\/aamirharoon.com\/?p=20","url":"https:\/\/aamirharoon.com\/?p=20","name":"How to Flush SQL Cursor Cache from Oracle Library Cache - The Database Handyman","isPartOf":{"@id":"https:\/\/aamirharoon.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/aamirharoon.com\/?p=20#primaryimage"},"image":{"@id":"https:\/\/aamirharoon.com\/?p=20#primaryimage"},"thumbnailUrl":"https:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","datePublished":"2015-12-05T18:10:03+00:00","breadcrumb":{"@id":"https:\/\/aamirharoon.com\/?p=20#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/aamirharoon.com\/?p=20"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/aamirharoon.com\/?p=20#primaryimage","url":"https:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg","contentUrl":"https:\/\/www.aamirharoon.com\/wp-content\/uploads\/2015\/10\/shared_pool_sga.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/aamirharoon.com\/?p=20#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/aamirharoon.com\/"},{"@type":"ListItem","position":2,"name":"How to Flush SQL Cursor Cache from Oracle Library Cache"}]},{"@type":"WebSite","@id":"https:\/\/aamirharoon.com\/#website","url":"https:\/\/aamirharoon.com\/","name":"The Database Handyman","description":"Cloud Architecture. Open-Source Databases. Data-Driven Solutions.","publisher":{"@id":"https:\/\/aamirharoon.com\/#\/schema\/person\/5b7250c4974dcf9818ca431e21831c75"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/aamirharoon.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":["Person","Organization"],"@id":"https:\/\/aamirharoon.com\/#\/schema\/person\/5b7250c4974dcf9818ca431e21831c75","name":"Aamir","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/aamirharoon.com\/wp-content\/uploads\/2020\/10\/cropped-IMG_2639-scaled-1.jpg","url":"https:\/\/aamirharoon.com\/wp-content\/uploads\/2020\/10\/cropped-IMG_2639-scaled-1.jpg","contentUrl":"https:\/\/aamirharoon.com\/wp-content\/uploads\/2020\/10\/cropped-IMG_2639-scaled-1.jpg","width":512,"height":512,"caption":"Aamir"},"logo":{"@id":"https:\/\/aamirharoon.com\/wp-content\/uploads\/2020\/10\/cropped-IMG_2639-scaled-1.jpg"},"sameAs":["https:\/\/www.aamirharoon.com\/about\/","https:\/\/x.com\/aamir814"],"url":"https:\/\/aamirharoon.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":21,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aamirharoon.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}