{"id":6617,"date":"2015-12-27T20:42:01","date_gmt":"2015-12-27T19:42:01","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/"},"modified":"2015-12-27T20:42:01","modified_gmt":"2015-12-27T19:42:01","slug":"phantom-session-environment-in-multitenant","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/","title":{"rendered":"Phantom session environment in multitenant?"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nIn multitenant a session can switch from one container to another. There are a few restrictions such as a transaction cannot span multiple containers. But how do sessions parameters behave? It seems that there is a small inconsistency.<br \/>\n<!--more--><br \/>\nI was looking at some adaptive plan and SPM behavior (see this tweeter <a href=\"https:\/\/twitter.com\/MarisElsins\/status\/677990324308992000\" target=\"_blank\" rel=\"noopener noreferrer\">conversation<\/a>) and played with the optimizer environment to reproduce the plan I wanted, and then came to a strange behavior. I can understand that a session keep its parameter settings when switching to another container. But not when closing and re-opening the pluggable database. The default values should come then.<\/p>\n<p>Here is an example.<\/p>\n<h3>Change in memory value of optimizer parameter<\/h3>\n<p>This is in 12.1.0.2 latest PSU. I connect to PDB<\/p>\n<pre><code>\n19:13:10 SQL&gt; alter session set container=PDB;\nSession altered.\n<\/code><\/pre>\n<p>and check parameter optimizer_index_cost_adj from memory:<\/p>\n<pre><code>\n19:13:10 SQL&gt; show parameter optimizer_index_cost_adj;\n&nbsp;\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\noptimizer_index_cost_adj             integer     100\n<\/code><\/pre>\n<p>It&#8217;s the default.<\/p>\n<p>then I set it to one in memory only:<\/p>\n<pre><code>\n19:37:17 SQL&gt; alter system set optimizer_index_cost_adj=1 scope=memory;\nSystem altered.\n<\/code><\/pre>\n<p>And I run a query and check that the optimizer used that value<\/p>\n<pre><code>\n19:37:18 SQL&gt; select * from dual;\n&nbsp;\nD\n-\nX\n&nbsp;\n19:37:19 SQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'+outline'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n--------------------------------------------------------------------------\nSQL_ID  a5ks9fhw2v9s1, child number 0\n-------------------------------------\nselect * from dual\n&nbsp;\nPlan hash value: 272002086\n&nbsp;\n--------------------------------------------------------------------------\n| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |\n--------------------------------------------------------------------------\n|   0 | SELECT STATEMENT  |      |       |       |     2 (100)|          |\n|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |\n--------------------------------------------------------------------------\n&nbsp;\nOutline Data\n-------------\n&nbsp;\n  \/*+\n      BEGIN_OUTLINE_DATA\n      IGNORE_OPTIM_EMBEDDED_HINTS\n      OPTIMIZER_FEATURES_ENABLE('12.1.0.2')\n      DB_VERSION('12.1.0.2')\n      OPT_PARAM('optimizer_index_cost_adj' 1)\n      ALL_ROWS\n      OUTLINE_LEAF(@\"SEL$1\")\n      FULL(@\"SEL$1\" \"DUAL\"@\"SEL$1\")\n      END_OUTLINE_DATA\n  *\/\n&nbsp;\n<\/code><\/pre>\n<p>Si this is expected, my custom value has been used to optimize the cursor.<\/p>\n<h3>close and re-open the PDB<\/h3>\n<p>I close and restart my PDB:<\/p>\n<pre><code>\n19:37:19 SQL&gt; shutdown immediate\nPluggable Database closed.\n19:37:21 SQL&gt; startup\nPluggable Database opened.\n<\/code><\/pre>\n<p>As the value was set in memory, it&#8217;s now back to default:<\/p>\n<pre><code>\n19:36:48 SQL&gt; show parameter optimizer_index_cost_adj;\n&nbsp;\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\noptimizer_index_cost_adj             integer     100\n&nbsp;\n<\/code><\/pre>\n<p>and of course, my cursor is not there anymore:<\/p>\n<pre><code>\n19:36:48 SQL&gt; select sql_id,child_number,first_load_time,con_id from v$sql where sql_id='a5ks9fhw2v9s1';\n&nbsp;\nno rows selected\n<\/code><\/pre>\n<p>So now I run again my query and expect the default optimizer environement:<\/p>\n<pre><code>\n19:36:48 SQL&gt; select dummy from dual;\n&nbsp;\nD\n-\nX\n&nbsp;\n19:36:48 SQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'+outline'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n---------------------------------------------------------------------------\nSQL_ID  4au7rzs3y6kzn, child number 0\n-------------------------------------\nselect dummy from dual\n&nbsp;\nPlan hash value: 272002086\n&nbsp;\n--------------------------------------------------------------------------\n| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |\n--------------------------------------------------------------------------\n|   0 | SELECT STATEMENT  |      |       |       |     2 (100)|          |\n|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |\n--------------------------------------------------------------------------\n&nbsp;\nOutline Data\n-------------\n&nbsp;\n  \/*+\n      BEGIN_OUTLINE_DATA\n      IGNORE_OPTIM_EMBEDDED_HINTS\n      OPTIMIZER_FEATURES_ENABLE('12.1.0.2')\n      DB_VERSION('12.1.0.2')\n      OPT_PARAM('optimizer_index_cost_adj' 1)\n      ALL_ROWS\n      OUTLINE_LEAF(@\"SEL$1\")\n      FULL(@\"SEL$1\" \"DUAL\"@\"SEL$1\")\n      END_OUTLINE_DATA\n  *\/\n<\/code><\/pre>\n<p>And my new cursor has used the optimizer_index_cost_adj=1 which is not what I expected at all.<br \/>\nDoes that mean that session parameters remain across PDB close\/start?<br \/>\nNo according to &#8216;show parameter&#8217;:<\/p>\n<pre><code>\n19:37:07 SQL&gt; show parameter optimizer_index_cost_adj;\n&nbsp;\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\noptimizer_index_cost_adj             integer     100\n&nbsp;\n<\/code><\/pre>\n<p>but yes according to V$SES_OPTIMIZER_ENV:<\/p>\n<pre><code>\n19:37:07 SQL&gt; select sid,name,value from v$ses_optimizer_env where name='optimizer_index_cost_adj' and sid=sys_context('userenv','sid');\n&nbsp;\n       SID NAME                                     VALUE\n---------- ---------------------------------------- -------------------------\n        35 optimizer_index_cost_adj                 1\n&nbsp;\n<\/code><\/pre>\n<h3>Conclusion<\/h3>\n<p>I&#8217;ve reproduced the same when re-connecting (instead of changing session container) and even when connecting to another PDB.<br \/>\nIn my opinion, this is a bug. The session parameters should be reinitialized when re-connecting. So be careful.<\/p>\n<h3>Update 12-JUL-2016<\/h3>\n<p>See Maciej Tokar <a href=\"http:\/\/dba24.pl\/2016\/07\/07\/alter-system-cdb-params-hack-from-pdb-a-bug-or-a-feature\/\">post<\/a> about this issue (my case being only one effect)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . In multitenant a session can switch from one container to another. There are a few restrictions such as a transaction cannot span multiple containers. But how do sessions parameters behave? It seems that there is a small inconsistency.<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[220,64,96,209,66,223],"type_dbi":[],"class_list":["post-6617","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-cdb","tag-multitenant","tag-oracle","tag-oracle-12c","tag-pdb","tag-pluggable-databases"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Phantom session environment in multitenant? - dbi Blog<\/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:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Phantom session environment in multitenant?\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . In multitenant a session can switch from one container to another. There are a few restrictions such as a transaction cannot span multiple containers. But how do sessions parameters behave? It seems that there is a small inconsistency.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-27T19:42:01+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Phantom session environment in multitenant?\",\"datePublished\":\"2015-12-27T19:42:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\"},\"wordCount\":320,\"commentCount\":0,\"keywords\":[\"CDB\",\"multitenant\",\"Oracle\",\"Oracle 12c\",\"PDB\",\"Pluggable Databases\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\",\"name\":\"Phantom session environment in multitenant? - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2015-12-27T19:42:01+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Phantom session environment in multitenant?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Phantom session environment in multitenant? - dbi Blog","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:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/","og_locale":"en_US","og_type":"article","og_title":"Phantom session environment in multitenant?","og_description":"By Franck Pachot . In multitenant a session can switch from one container to another. There are a few restrictions such as a transaction cannot span multiple containers. But how do sessions parameters behave? It seems that there is a small inconsistency.","og_url":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/","og_site_name":"dbi Blog","article_published_time":"2015-12-27T19:42:01+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Phantom session environment in multitenant?","datePublished":"2015-12-27T19:42:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/"},"wordCount":320,"commentCount":0,"keywords":["CDB","multitenant","Oracle","Oracle 12c","PDB","Pluggable Databases"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/","url":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/","name":"Phantom session environment in multitenant? - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2015-12-27T19:42:01+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/phantom-session-environment-in-multitenant\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Phantom session environment in multitenant?"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=6617"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6617\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=6617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=6617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=6617"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=6617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}