ora-20005:object statistics are locked(stattype=all)的原因及解决方法

    xiaoxiao2022-07-12  178

    RDBMS 11.2.0.4

    今天查询发现有个分区表的统计信息一直都没有收集过,通过命令行收集的时候,提示ora-20005:object statistics are locked(stattype=all),ORA-06512 等错误。

    关于这个产生的原因,MOS上有篇文章说的比较详细。MOS上也有其他文章是描述这个错误的(但是只是说怎么解决)。

    ORA-38029 "Object Statistics Are Locked" - Possible Causes (文档 ID 433240.1)

    根据MOS文档,列出了以下原因:

    Possible Cause #1: DBMS_STATS.LOCK_[SCHEMA|TABLE]_STATS has been used to lock statistics on the table. Possible Cause #2: Using import (imp) or data pump import (impdp) to import a table without data results in the table's statistics being locked in 10gR2.  

    Oracle� Database Readme 10g Release 2 (10.2) Part Number B14233-04 39.5Original Export/Import

    After an IMPORT is finished for which ROWS=N, the statistics for all tables imported will be locked.

     

    Possible Cause #3: If the table is a queue table then the statistics are intended to be empty and locked so that dynamic sampling will be used due to the table's volatility. During an upgrade to 10gR2 statistics on queue tables are deleted and then locked. In 10gR2 when a queue table is created statistics are locked while still empty.

     

    MOS上提出的解决该问题的方法

    如果是队列表的话,直接unlock统计信息(队列表日常工作中用的不多,当然也可以直接unlock后再收集统计信息),或者直接在收集统计信息的时候加上force命令 。

    If the table is a queue table, then the statistics should remain empty and locked so that dynamic sampling is used due to the volatility of queue tables. If the table is not a queue table, unlock the statistics using following:

    DBMS_STATS.UNLOCK_[SCHEMA|TABLE]_STATS

    Or gather statistics on the table using following:

    DBMS_STATS.GATHER_[SCHEMA|TABLE|INDEX]_STATS and the force=>true parameter

    To prevent import (imp) from locking the table's statistics when importing a table without the rows (rows=n), use statistics=none. To prevent data pump import (impdp) from locking the table's statistics when importing a table without the rows (content=metadata_only), use exclude=(table_statistics,index_statistics).

    官方文档上关于force参数的说明(这里查看的是19C的文档,11G的文档上也有这个参数)

    https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_STATS.html#GUID-CA6A56B9-0540-45E9-B1D7-D78769B7714C

    force

    Gather statistics of table even if it is locked

     END

    -- 补充,一个比较有意思的情况,ora-20005这个错误代码居然没有的。到时ora-38029倒是有。

    [oracle@redhat762100 ~]$ oerr ora 38029 38029, 00000, "object statistics are locked" // *Cause: An attept was made to modify optimizer statistics of the object. // *Action: Unlock statistics with the DBMS_STATS.UNLOCK_TABLE_STATS procedure // on base table(s). Retry the operation if it is okay to update statistics. [oracle@redhat762100 ~]$ oerr ora 20005 [oracle@redhat762100 ~]$

    查询统计信息有没有被锁,查询表dba_tab_statistics 中的列  stattype_locked。

    最新回复(0)