<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrew Fraser DBA &#187; Stats</title>
	<atom:link href="http://andrewfraserdba.com/category/stats/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewfraserdba.com</link>
	<description>Oracle DBA (plus SQL Server)</description>
	<lastBuildDate>Wed, 18 Jan 2012 15:25:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ORA-38029 Object Statistics Are Locked &#8211; due to import with rows=n</title>
		<link>http://andrewfraserdba.com/2011/03/08/ora-38029-object-statistics-are-locked-due-to-import-with-rowsn/</link>
		<comments>http://andrewfraserdba.com/2011/03/08/ora-38029-object-statistics-are-locked-due-to-import-with-rowsn/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 19:03:20 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Stats]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=527</guid>
		<description><![CDATA[A strange one &#8211; but it is a documented feature in oracle. If you import specifying option &#8216;rows=n&#8217;, then statistics for all imported tables will be locked after the import operation is finished. That is only for import &#8211; an &#8230; <a href="http://andrewfraserdba.com/2011/03/08/ora-38029-object-statistics-are-locked-due-to-import-with-rowsn/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A strange one &#8211; but it is a documented feature in oracle.</p>
<p>If you import specifying option &#8216;rows=n&#8217;, then statistics for all imported tables will be locked after the import operation is finished.</p>
<p>That is only for import &#8211; an export with &#8216;rows=n&#8217; is fine, doesn&#8217;t lock anything.</p>
<p>That&#8217;s probably not what you want to happen &#8211; it means that &#8216;dbms_stats gather&#8217; operations and &#8216;analyze&#8217; operations will not update optimizer statistics on those tables.</p>
<p>Avoid this by either:</p>
<ul>
<li>Specifying option &#8216;rows=n&#8217; on the export only, not on the import (what I always do anyway); or</li>
<li>Using DBMS_STATS.UNLOCK_[SCHEMA|TABLE]_STATS to correct after the import is finished.</li>
</ul>
<p>This is true for all versions from 10gR2 onwards, and it is documented:</p>
<ul>
<li><a href="http://download.oracle.com/docs/cd/E11882_01/server.112/e16536/original_import.htm#SUTIL1728">11gR2 Utilities Manual</a></li>
<li><a href="http://download.oracle.com/docs/cd/B28359_01/server.111/b28319/exp_imp.htm#sthref2618">11gR1 Utilities Manual</a></li>
<li><a href="http://download.oracle.com/docs/cd/B19306_01/readmes.102/b14233/toc.htm#sthref108">10gR2 Database Readme</a></li>
</ul>
<p>It&#8217;s not just old style import &#8211; data pump import behaves similarly.</p>
<p>You can see what optimizer statistics are locked in your database with:</p>
<pre class="brush:sql">select owner, table_name, stattype_locked
from dba_tab_statistics
where stattype_locked is not NULL
order by 1,2 ;</pre>
<p>Use DBMS_STATS.UNLOCK_[SCHEMA|TABLE]_STATS and DBMS_STATS.LOCK_[SCHEMA|TABLE]_STATS to switch on and off outside import.</p>
<p>Shell script to demonstrate this:<span id="more-527"></span></p>
<pre class="brush:bash, shell">echo Create table
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
create table myschema.demo1 ( x number) ;
select stattype_locked from dba_tab_statistics where owner = 'MYSCHEMA' and table_name = 'DEMO1' ;
END_SQL

echo Export
exp \"/ as sysdba\" tables=myschema.demo1 rows=n

echo Drop table
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
drop table myschema.demo1 ;
END_SQL

echo Import - stats ok
imp \"/ as sysdba\" full=y rows=n
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
select stattype_locked from dba_tab_statistics where owner = 'MYSCHEMA' and table_name = 'DEMO1' ;
END_SQL

echo Drop table again
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
drop table myschema.demo1 ;
END_SQL

echo Import this time with rows=n - now stats are locked
imp \"/ as sysdba\" full=y
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
select stattype_locked from dba_tab_statistics where owner = 'MYSCHEMA' and table_name = 'DEMO1' ;
END_SQL

echo Tidy up
sqlplus -s "/ as sysdba" &lt;&lt;END_SQL
drop table myschema.demo1 ;
END_SQL</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2011/03/08/ora-38029-object-statistics-are-locked-due-to-import-with-rowsn/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Purge and regather all optimizer stats</title>
		<link>http://andrewfraserdba.com/2010/05/13/purge-and-regather-all-optimizer-stats/</link>
		<comments>http://andrewfraserdba.com/2010/05/13/purge-and-regather-all-optimizer-stats/#comments</comments>
		<pubDate>Thu, 13 May 2010 15:46:45 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Stats]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=252</guid>
		<description><![CDATA[Purge and regather all optimizer stats with: exec dbms_stats.delete_database_stats exec dbms_stats.delete_system_stats exec dbms_scheduler.run_job('GATHER_STATS_JOB') That works provided statistics level has not been changed to none show parameter statistics_level You can gather more detailed system stats with: exec dbms_stats.gather_system_stats('START') exec dbms_stats.gather_system_stats('STOP') You &#8230; <a href="http://andrewfraserdba.com/2010/05/13/purge-and-regather-all-optimizer-stats/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Purge and regather all optimizer stats with:</p>
<pre class="brush:sql">exec dbms_stats.delete_database_stats
exec dbms_stats.delete_system_stats
exec dbms_scheduler.run_job('GATHER_STATS_JOB')</pre>
<p>That works provided statistics level has not been changed to none</p>
<pre class="brush:sql">show parameter statistics_level</pre>
<p>You can gather more detailed system stats with:</p>
<pre class="brush:sql">exec dbms_stats.gather_system_stats('START')
exec dbms_stats.gather_system_stats('STOP')</pre>
<p>You can see the system stats with:</p>
<pre class="brush:sql">set pages 9999 lines 112
col pval2 form a20
select * from sys.aux_stats$;</pre>
<p>You can check automatic stats gathering job is scheduled with:</p>
<pre class="brush:sql">select state, last_start_date from dba_scheduler_jobs where job_name = 'GATHER_STATS_JOB';</pre>
<p><strong>This has changed for 11g</strong>.<br />
To check if it is scheduled in 11g:
<pre class="brush:sql">select status, max_duration_last_7_days from dba_autotask_client where client_name = 'auto optimizer stats collection' ;</pre>
<p>And to run it in 11g: </p>
<pre class="brush:sql">exec dbms_stats.gather_database_stats_job_proc</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/05/13/purge-and-regather-all-optimizer-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dbms_stats export import optimizer statistics</title>
		<link>http://andrewfraserdba.com/2010/04/07/dbms_stats-export-import-optimizer-statistics/</link>
		<comments>http://andrewfraserdba.com/2010/04/07/dbms_stats-export-import-optimizer-statistics/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 15:40:14 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Stats]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=234</guid>
		<description><![CDATA[Examples of syntax to export/import dbms_stats: exec dbms_stats.create_stat_table ( ownname => user , stattab => 'temp_stats' ) ; exec dbms_stats.export_table_stats ( ownname => user , stattab => 'temp_stats', tabname => 'mytable', statid => 'Taken_7Apr2010') ; exec dbms_stats.import_table_stats ( ownname => &#8230; <a href="http://andrewfraserdba.com/2010/04/07/dbms_stats-export-import-optimizer-statistics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Examples of syntax to export/import dbms_stats:</p>
<pre class="brush:sql">exec dbms_stats.create_stat_table ( ownname => user , stattab => 'temp_stats' ) ;
exec dbms_stats.export_table_stats ( ownname => user , stattab => 'temp_stats', tabname => 'mytable', statid => 'Taken_7Apr2010') ;
exec dbms_stats.import_table_stats ( ownname => user , stattab => 'temp_stats', tabname => 'adm_fact' )</pre>
<p>Similarly for schema:</p>
<pre class="brush:sql">exec DBMS_STATS.EXPORT_SCHEMA_STATS ( ownname => 'myowner' , stattab => 'temp_stats', statown => user )</pre>
<p>A bug in 10g prevents spaces being passed into the &#8220;statid&#8221; variable, hence the underscores in the above example.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/04/07/dbms_stats-export-import-optimizer-statistics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic gather stats job</title>
		<link>http://andrewfraserdba.com/2010/03/05/automatic-gather-stats-job/</link>
		<comments>http://andrewfraserdba.com/2010/03/05/automatic-gather-stats-job/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 10:48:45 +0000</pubDate>
		<dc:creator>Andrew Fraser</dc:creator>
				<category><![CDATA[Performance tuning]]></category>
		<category><![CDATA[Stats]]></category>

		<guid isPermaLink="false">http://andrewfraserdba.com/?p=213</guid>
		<description><![CDATA[check it is on with: select state, last_start_date from dba_scheduler_jobs where job_name = 'GATHER_STATS_JOB' ; Switch it on and off with: exec dbms_scheduler.disable('GATHER_STATS_JOB') exec dbms_scheduler.enable('GATHER_STATS_JOB')]]></description>
			<content:encoded><![CDATA[<p>check it is on with:</p>
<pre class="brush:sql">select state, last_start_date from dba_scheduler_jobs where job_name = 'GATHER_STATS_JOB' ;</pre>
<p>Switch it on and off with:</p>
<pre class="brush:sql">exec dbms_scheduler.disable('GATHER_STATS_JOB')
exec dbms_scheduler.enable('GATHER_STATS_JOB')</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewfraserdba.com/2010/03/05/automatic-gather-stats-job/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

