Mar 9, 2020

ORA-20005: object statistics are locked

While gather stats for a index, I got below error. It is not a problem, Some reason, may be statistics collection stopped. But once you unlocked, you able to do. Please go through this workaround:

Command Executed:

execute dbms_stats.gather_index_stats(ownname => 'SCOTT', indname => 'IDX_DOJ', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE);

*
ERROR at line 1:
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 26193
ORA-06512: at line 1


SQL> col owner for a15
SQL> col TABLE_NAME for a30
SQL> col STATTYPE_LOCKED for a30
SQL> select owner,table_name,STATTYPE_LOCKED 
from dba_ind_statistics where index_name='IDX_DOJ' and owner='SCOTT';

OWNER           TABLE_NAME                STATTYPE_LOCKED
--------------- --------------------- ------------------------------
SCOTT       EMPLOYEE                       ALL

SQL>

Remember:
STATTYPE_LOCKED – ALL -> stats are locked for the table
STATTYPE_LOCKED – NULL – > stats are not locked

Now unlock the table to collect statistics:

SQL> EXEC DBMS_STATS.unlock_table_stats('SCOTT','EMPLOYEE');

PL/SQL procedure successfully completed.

SQL> execute dbms_stats.gather_index_stats(ownname => 'SCOTT', indname => 'IDX_DOJ', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE);

PL/SQL procedure successfully completed.

SQL>

In case of table, you can do like below:

SQL> EXEC DBMS_STATS.unlock_table_stats('SCOTT','TEST');

PL/SQL procedure successfully completed.

SQL> select owner,table_name,STATTYPE_LOCKED from dba_tab_statistics where table_name='TEST' and owner='SCOTT';


OWNER      TABLE_NAME STATTYPE_LOCKED
---------- ---------- ----------------------------------
SCOTT    TEST

Similarly we can unlock stats for a schema also.

SQL> EXEC DBMS_STATS.unlock_schema_stats('SCOTT');

PL/SQL procedure successfully completed.


2 comments:

  1. Jackpot City Hotel & Casino | MapYRO
    Find 경상남도 출장마사지 Jackpot City Hotel & Casino, 김해 출장샵 New Orleans (NY) 태백 출장마사지 location, revenue, industry 의정부 출장샵 and 광양 출장샵

    ReplyDelete
  2. Have you been a victim of crypto wallet attacks? Here’s a way to quickly recover your crypto wallet and assets if you’ve been in similar situation, I was recently a victim of crypto wallet attacks and I lost access to my BTC and ETH funds. I was drowning in debt, until I approached a legal firm who recommended I contacted MorphoHack, a data recovery and funds recovery team, who helped me trace and regained access to my crypto wallet with my funds fully recovered. MorphoHack are simply magnificent individuals, with a professional direct approach to the situation, and countless others have been able to recover their crypto, funds lost due to scam, data, personal data recovery. MorphoHack are truly ethical hackers, with well advanced technology to help in any case. I highly recommend their service and fortunately, MorphoHack can be reached easily via email below
    morphohack@cyberservices.com

    ReplyDelete

Translate >>