{"id":10456,"date":"2017-09-06T20:20:38","date_gmt":"2017-09-06T18:20:38","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/"},"modified":"2017-09-06T20:20:38","modified_gmt":"2017-09-06T18:20:38","slug":"impdp-contentmetadata_only-locks-the-stats","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/","title":{"rendered":"impdp content=metadata_only locks the stats"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nWith Oracle you can learn something every day. Today, preparing a migration to 12.2, I found all tables had locked statistics. I learned that it is the expected behavior since 10.2 when importing metadata_only including statistics, to avoid that the automatic job gathering comes and replaces the stats by &#8216;0 rows&#8217;.<br \/>\n<!--more--><br \/>\nIt is documented in <a href=\"https:\/\/support.oracle.com\/epmos\/faces\/DocContentDisplay?id=415081.1\" target=\"_blank\" rel=\"noopener noreferrer\">DataPump Import Without Data Locks Table Statistics (Doc ID 415081.1)<\/a> but as I was really surprised about that (and also frustrated to learn a 10.2 thing when migrating to 12.2) that I wanted to test myself.<\/p>\n<p>I create a table DEMO with statistics:<\/p>\n<pre><code>\nSQL&gt; connect sys\/oracle@\/\/localhost\/pdb1 as sysdba\nConnected.\nSQL&gt; create table demo.demo as select * from dual;\nTable created.\n&nbsp;\nSQL&gt; create index demo.demo on demo.demo(dummy);\nIndex created.\n&nbsp;\nSQL&gt; exec dbms_stats.gather_table_stats('DEMO','DEMO');\nPL\/SQL procedure successfully completed.\n&nbsp;\nSQL&gt; create or replace directory TMP as '\/tmp';\nDirectory created.\n&nbsp;\nSQL&gt; select count(*) from DEMO.DEMO;\n&nbsp;\n  COUNT(*)\n----------\n         1\n&nbsp;\nSQL&gt; select object_type from dba_objects where owner='DEMO' and object_name='DEMO';\n&nbsp;\nOBJECT_TYPE\n-----------------------\nTABLE\nINDEX\n&nbsp;\nSQL&gt; select owner,table_name,last_analyzed,stattype_locked,num_rows from dba_tab_statistics where owner='DEMO' and table_name='DEMO';\n&nbsp;\nOWNER      TABLE_NAME           LAST_ANALYZED        STATTYPE_LOCKED        NUM_ROWS\n---------- -------------------- -------------------- -------------------- ----------\nDEMO       DEMO                 06-SEP-17                                          1\n<\/code><\/pre>\n<p>I export it:<\/p>\n<pre><code>\nConnected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production\nStarting \"SYS\".\"SYS_EXPORT_TABLE_01\":  \"sys\/********@\/\/localhost\/pdb1 AS SYSDBA\" tables=DEMO.DEMO directory=TMP\nProcessing object type TABLE_EXPORT\/TABLE\/TABLE_DATA\nProcessing object type TABLE_EXPORT\/TABLE\/INDEX\/STATISTICS\/INDEX_STATISTICS\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/TABLE_STATISTICS\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/MARKER\nProcessing object type TABLE_EXPORT\/TABLE\/TABLE\nProcessing object type TABLE_EXPORT\/TABLE\/INDEX\/INDEX\n. . exported \"DEMO\".\"DEMO\"                               5.054 KB       1 rows\nMaster table \"SYS\".\"SYS_EXPORT_TABLE_01\" successfully loaded\/unloaded\n******************************************************************************\nDump file set for SYS.SYS_EXPORT_TABLE_01 is:\n  \/tmp\/expdat.dmp\nJob \"SYS\".\"SYS_EXPORT_TABLE_01\" successfully completed at Wed Sep 6 19:14:44 2017 elapsed 0 00:00:09\n<\/code><\/pre>\n<p>And drop it:<\/p>\n<pre><code>\nSQL&gt; connect sys\/oracle@\/\/localhost\/pdb1 as sysdba\nConnected.\nSQL&gt; drop table demo.demo;\nTable dropped.\n<\/code><\/pre>\n<p>Now import metadata only (for example because I want to change NLS semantics before importing the data)<\/p>\n<pre><code>\nImport: Release 12.2.0.1.0 - Production on Wed Sep 6 19:21:28 2017\n&nbsp;\nCopyright (c) 1982, 2017, Oracle and\/or its affiliates.  All rights reserved.\n&nbsp;\nConnected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production\nMaster table \"SYS\".\"SYS_IMPORT_TABLE_01\" successfully loaded\/unloaded\nStarting \"SYS\".\"SYS_IMPORT_TABLE_01\":  \"sys\/********@\/\/localhost\/pdb1 AS SYSDBA\" tables=DEMO.DEMO directory=TMP content=metadata_only exclude=index\nProcessing object type TABLE_EXPORT\/TABLE\/TABLE\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/TABLE_STATISTICS\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/MARKER\nJob \"SYS\".\"SYS_IMPORT_TABLE_01\" successfully completed at Wed Sep 6 19:21:39 2017 elapsed 0 00:00:11\n<\/code><\/pre>\n<p>If I check the statistics:<\/p>\n<pre><code>\nSQL&gt; select owner,table_name,last_analyzed,stattype_locked,num_rows from dba_tab_statistics where owner='DEMO' and table_name='DEMO';\n&nbsp;\nOWNER      TABLE_NAME           LAST_ANALYZED        STATTYPE_LOCKED        NUM_ROWS\n---------- -------------------- -------------------- -------------------- ----------\nDEMO       DEMO                 06-SEP-17            ALL                           1\n<\/code><\/pre>\n<p>Stats are locked. I suppose that the idea is that you have the tables with same statistics as production for example, and you can load them with a subset of data but expect the same execution plans as in production. But this is not what I want for a migration.<\/p>\n<p>One possibility is to unlock the stats once you have imported the data.<\/p>\n<p>The other possibility is to import metadata without the statistics:<\/p>\n<pre><code>\nConnected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production\nMaster table \"SYS\".\"SYS_IMPORT_TABLE_01\" successfully loaded\/unloaded\nStarting \"SYS\".\"SYS_IMPORT_TABLE_01\":  \"sys\/********@\/\/localhost\/pdb1 AS SYSDBA\" tables=DEMO.DEMO directory=TMP content=metadata_only exclude=index exclude=table_statistics\nProcessing object type TABLE_EXPORT\/TABLE\/TABLE\nJob \"SYS\".\"SYS_IMPORT_TABLE_01\" successfully completed at Wed Sep 6 21:11:03 2017 elapsed 0 00:00:03\n<\/code><\/pre>\n<p>Then the table statistics are not locked:<\/p>\n<pre><code>\nOWNER      TABLE_NAME           LAST_ANALYZED        STATTYPE_LOCKED        NUM_ROWS\n---------- -------------------- -------------------- -------------------- ----------\nDEMO       DEMO\n<\/code><\/pre>\n<p>Once you have changed what you want on the tables, you import the data (table_exists_action=truncate) and then you import the remaining: indexes, ref_constraints, triggers.<br \/>\nThis is where you can also add include=table_statistics:<\/p>\n<pre><code>\nStarting \"SYS\".\"SYS_IMPORT_TABLE_01\":  \"sys\/********@\/\/localhost\/pdb1 AS SYSDBA\" tables=DEMO.DEMO directory=TMP table_exists_action=truncate include=index include=table_statistics\nProcessing object type TABLE_EXPORT\/TABLE\/INDEX\/INDEX\nProcessing object type TABLE_EXPORT\/TABLE\/INDEX\/STATISTICS\/INDEX_STATISTICS\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/TABLE_STATISTICS\nProcessing object type TABLE_EXPORT\/TABLE\/STATISTICS\/MARKER\n<\/code><\/pre>\n<p>So that you have the statistics from the source, unlocked.<\/p>\n<pre><code>\nOWNER      TABLE_NAME           LAST_ANALYZED        STATTYPE_LOCKED        NUM_ROWS\n---------- -------------------- -------------------- -------------------- ----------\nDEMO       DEMO                 06-SEP-17                                          1\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . With Oracle you can learn something every day. Today, preparing a migration to 12.2, I found all tables had locked statistics. I learned that it is the expected behavior since 10.2 when importing metadata_only including statistics, to avoid that the automatic job gathering comes and replaces the stats by &#8216;0 rows&#8217;.<\/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":[59],"tags":[240,96],"type_dbi":[],"class_list":["post-10456","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-data-pump","tag-oracle"],"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>impdp content=metadata_only locks the stats - 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\/impdp-contentmetadata_only-locks-the-stats\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"impdp content=metadata_only locks the stats\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . With Oracle you can learn something every day. Today, preparing a migration to 12.2, I found all tables had locked statistics. I learned that it is the expected behavior since 10.2 when importing metadata_only including statistics, to avoid that the automatic job gathering comes and replaces the stats by &#8216;0 rows&#8217;.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-06T18:20:38+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=\"4 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\/impdp-contentmetadata_only-locks-the-stats\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"impdp content=metadata_only locks the stats\",\"datePublished\":\"2017-09-06T18:20:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\"},\"wordCount\":259,\"commentCount\":0,\"keywords\":[\"Data pump\",\"Oracle\"],\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\",\"name\":\"impdp content=metadata_only locks the stats - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2017-09-06T18:20:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"impdp content=metadata_only locks the stats\"}]},{\"@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":"impdp content=metadata_only locks the stats - 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\/impdp-contentmetadata_only-locks-the-stats\/","og_locale":"en_US","og_type":"article","og_title":"impdp content=metadata_only locks the stats","og_description":"By Franck Pachot . With Oracle you can learn something every day. Today, preparing a migration to 12.2, I found all tables had locked statistics. I learned that it is the expected behavior since 10.2 when importing metadata_only including statistics, to avoid that the automatic job gathering comes and replaces the stats by &#8216;0 rows&#8217;.","og_url":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/","og_site_name":"dbi Blog","article_published_time":"2017-09-06T18:20:38+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"impdp content=metadata_only locks the stats","datePublished":"2017-09-06T18:20:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/"},"wordCount":259,"commentCount":0,"keywords":["Data pump","Oracle"],"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/","url":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/","name":"impdp content=metadata_only locks the stats - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2017-09-06T18:20:38+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/impdp-contentmetadata_only-locks-the-stats\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"impdp content=metadata_only locks the stats"}]},{"@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\/10456","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=10456"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/10456\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=10456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=10456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=10456"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=10456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}