<?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>惜分飞 &#187; PERFSTAT.STATS$SQL_SUMMARY_PK</title>
	<atom:link href="https://www.xifenfei.com/tag/perfstat-statssql_summary_pk/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Wed, 04 Nov 2026 15:33:30 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated</title>
		<link>https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-perfstat-statssql_summary_pk-violated.html</link>
		<comments>https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-perfstat-statssql_summary_pk-violated.html#comments</comments>
		<pubDate>Thu, 05 Apr 2012 12:03:00 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[ORA-xxxxx]]></category>
		<category><![CDATA[ORA-00001]]></category>
		<category><![CDATA[PERFSTAT.STATS$SQL_SUMMARY_PK]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=2848</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-perfstat-statssql_summary_pk-violated.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-perfstat-statssql_summary_pk-violated.html" target="_blank">ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>出现如下错误(ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated)</p>
<pre class="brush: bash; title: ; notranslate">
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.6.0 - Production
ORACLE_HOME = /oracle9/app/product/9.2.0
System name:    AIX
Node name:      zwq_bill_1
Release:        1
Version:        6
Machine:        00F64FF34C00
Instance name: bill1
Redo thread mounted by this instance: 1
Oracle process number: 30
Unix process pid: 46531060, image: oracle@zwq_bill_1 (J000)

*** SESSION ID:(218.47085) 2012-04-02 19:30:45.561
*** 2012-04-02 19:30:45.561
ORA-12012: error on auto execute of job 1
ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated
ORA-06512: at &quot;PERFSTAT.STATSPACK&quot;, line 1361
ORA-06512: at &quot;PERFSTAT.STATSPACK&quot;, line 2471
ORA-06512: at &quot;PERFSTAT.STATSPACK&quot;, line 91
ORA-06512: at line 1
</pre>
<p>这个是oracle的一个Bug 2784796,提供解决方法有<br />
<strong>1.run the statspack at level 0<br />
2.restart the instance<br />
3.set cursor sharing to exact (probably not feasible)<br />
4.禁用主键，创建合适非唯一index</strong></p>
<pre class="brush: sql; title: ; notranslate">ALTER TABLE PERFSTAT.STATS$SQL_SUMMARY MODIFY 
CONSTRAINT STATS$SQL_SUMMARY_PK DISABLE NOVALIDATE;</pre>
<p><strong>5.修改STATS$V_$SQLXS视图</strong><br />
分析思路如下:<br />
1)根据主键冲突找到主键包含列(spctab.sql)</p>
<pre class="brush: sql; title: ; notranslate">
create table          STATS$SQL_SUMMARY
(snap_id              number(6)        not null
,dbid                 number           not null
,instance_number      number           not null
,text_subset          varchar2(31)     not null
,sql_text             varchar2(1000)
,sharable_mem         number
,sorts                number
,module               varchar2(64)
,loaded_versions      number
,fetches              number
,executions           number
,loads                number
,invalidations        number
,parse_calls          number
,disk_reads           number
,buffer_gets          number
,rows_processed       number
,command_type         number
,address              raw(8)
,hash_value           number
,version_count        number
,cpu_time             number
,elapsed_time         number
,outline_sid          number
,outline_category     varchar2(64)
,child_latch          number
--注意下面5列构成主键
,constraint STATS$SQL_SUMMARY_PK primary key
    (snap_id, dbid, instance_number, hash_value, text_subset)
 using index tablespace &amp;&amp;tablespace_name
   storage (initial 1m next 1m pctincrease 0)
,constraint STATS$SQL_SUMMARY_FK foreign key (snap_id, dbid, instance_number)
                references STATS$SNAPSHOT on delete cascade
)tablespace &amp;&amp;tablespace_name
storage (initial 1m next 1m pctincrease 0) pctfree 5 pctused 40;
</pre>
<p>2)找到该表插入数据(spcpkg.sql)</p>
<pre class="brush: sql; title: ; notranslate">
insert into stats$sql_summary
            ( snap_id
            , dbid
            , instance_number
            , text_subset
            , sharable_mem
            , sorts
            , module
            , loaded_versions
            , fetches
            , executions
            , loads
            , invalidations
            , parse_calls
            , disk_reads
            , buffer_gets
            , rows_processed
            , command_type
            , address
            , hash_value
            , version_count
            , cpu_time
            , elapsed_time
            , outline_sid
            , outline_category
            , child_latch
            )
       select l_snap_id
            , p_dbid
            , p_instance_number
            , substrb(sql_text,1,31)
            , sharable_mem
            , sorts
            , module
            , loaded_versions
            , fetches
            , executions
            , loads
            , invalidations
            , parse_calls
            , disk_reads
            , buffer_gets
            , rows_processed
            , command_type
            , address
            , hash_value
            , version_count
            , cpu_time
            , elapsed_time
            , outline_sid
            , outline_category
            , child_latch
         from stats$v$sqlxs
        where is_obsolete = 'N'
          and (   buffer_gets   &gt; l_buffer_gets_th
               or disk_reads    &gt; l_disk_reads_th
               or parse_calls   &gt; l_parse_calls_th
               or executions    &gt; l_executions_th
               or sharable_mem  &gt; l_sharable_mem_th
               or version_count &gt; l_version_count_th
              );
</pre>
<p>3)找出stats$v$sqlxs对象(spcusr.sql)</p>
<pre class="brush: sql; title: ; notranslate">
create or replace view STATS$V_$SQLXS as
select max(sql_text)        sql_text
     , sum(sharable_mem)    sharable_mem
     , sum(sorts)           sorts
     , min(module)          module
     , sum(loaded_versions) loaded_versions
     , sum(fetches)         fetches
     , sum(executions)      executions
     , sum(loads)           loads
     , sum(invalidations)   invalidations
     , sum(parse_calls)     parse_calls
     , sum(disk_reads)      disk_reads
     , sum(buffer_gets)     buffer_gets
     , sum(rows_processed)  rows_processed
     , max(command_type)    command_type
     , address              address
     , hash_value           hash_value
     , count(1)             version_count
     , sum(cpu_time)        cpu_time
     , sum(elapsed_time)    elapsed_time
     , max(outline_sid)     outline_sid
     , max(outline_category) outline_category
     , max(is_obsolete)     is_obsolete
     , max(child_latch)     child_latch
  from v$sql
 group by hash_value, address;
create or replace public synonym STATS$V$SQLXS for STATS$V_$SQLXS;
</pre>
<p>4)通过这里可以看出，要是的STATS$SQL_SUMMARY主键不重复，只要是的STATS$V_$SQLXS查询出来的记录唯一，所以解决方案就是在STATS$V_$SQLXS视图中增加下列条件，确保查询出来的记录唯一，从而不会发生主键冲突</p>
<pre class="brush: sql; title: ; notranslate">
where 
( plan_hash_value &gt; 0 
or executions &gt; 0
or parse_calls &gt; 0
or disk_reads &gt; 0
or buffer_gets &gt; 0
)
</pre>
<p>该bug在10g中修复，对于不能及时升级的数据库，建议采用第五种方法解决问题，比较治标治本，对业务基本上无影响</p>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/02/oracle-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9a%e4%bd%8d%e9%87%8d%e8%a6%81%e6%b6%88%e8%80%97%e8%b5%84%e6%ba%90%e5%a4%9a%e7%9a%84sql.html" rel="bookmark" class="crp_title">oracle 中如何定位重要(消耗资源多)的SQL</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2010/08/oracle%e4%b9%8b%e7%ba%a6%e6%9d%9f.html" rel="bookmark" class="crp_title">oracle之约束</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/02/%e9%80%9a%e8%bf%87sql%e8%af%ad%e5%8f%a5%e8%8e%b7%e5%8f%96awrstatspack%e9%80%bb%e8%be%91%e8%af%bb%e7%89%a9%e7%90%86%e8%af%bb.html" rel="bookmark" class="crp_title">通过sql语句获取awr/statspack逻辑读/物理读</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/01/%e8%b7%b3%e8%bf%87obj%e5%9d%8f%e5%9d%97%e6%96%b9%e6%b3%95.html" rel="bookmark" class="crp_title">跳过obj$坏块方法</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/02/statspack%e6%8a%a5%e5%91%8a%e4%b8%ad%e9%80%bb%e8%be%91%e8%af%bb%e4%b8%ba%e8%b4%9f%e5%80%bc.html" rel="bookmark" class="crp_title">statspack报告中逻辑读为负值</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/02/%e6%b8%85%e9%99%a4%e6%8e%89shared-pool%e4%b8%ad%e6%9f%90%e6%9d%a1sql%e8%af%ad%e5%8f%a5%e6%96%b9%e6%b3%95.html" rel="bookmark" class="crp_title">清除掉shared pool中某条sql语句方法</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/11/%e8%a7%a3%e5%86%b3statspack%e6%8a%a5%e5%91%8a%e6%97%b6snap-id%e4%b8%ba.html" rel="bookmark" class="crp_title">解决Statspack报告时Snap Id为&#8221;#####&#8221;</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/04/9i%e4%b8%ad%e6%b8%85%e9%99%a4%e7%89%b9%e5%ae%9a%e8%a1%a8%e7%9b%b8%e5%85%b3%e6%89%a7%e8%a1%8c%e8%ae%a1%e5%88%92.html" rel="bookmark" class="crp_title">9I中清除特定表相关执行计划</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/08/oracle%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e5%90%8eawr%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86.html" rel="bookmark" class="crp_title">ORACLE异常恢复后awr异常处理</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/05/%e4%bd%bf%e7%94%a8dbms_metadata-get_ddl%e5%87%ba%e7%8e%b0ora-31605%e9%94%99%e8%af%af.html" rel="bookmark" class="crp_title">使用dbms_metadata.get_ddl出现ORA-31605错误</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/05/sql_id%e5%92%8chash-value%e7%9a%84%e9%83%a8%e5%88%86%e8%bd%ac%e6%8d%a2.html" rel="bookmark" class="crp_title">sql_id和hash value的部分转换</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-sys-i_job_job-violated.html" rel="bookmark" class="crp_title">ORA-00001 Unique Constraint SYS.I_JOB_JOB Violated</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2012/04/ora-00001-unique-constraint-perfstat-statssql_summary_pk-violated.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
