Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

ORA-20005: object statistics are locked (stattype = ALL)

$
0
0
ORA-20005: object statistics are locked (stattype = ALL) - Solution
ERROR

During tuning a query, I found one table has stale statistics. While running gather stats for that table, got below error. Let me demonstrate with a demo table:

SQL> execute dbms_stats.gather_table_stats(ownname => 'HR', tabname => 'EMPLOYEE', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO');

BEGIN dbms_stats.gather_table_stats(ownname => 'HR', tabname => 'EMPLOYEE', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO'); END;

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

Analysis:
Verify whether statistics is locked for that table or not.
SQL> col OWNER for a12
SQL> col table_name for a30
SQL> col STATTYPE_LOCKED for a15
SQL> select owner,table_name,STATTYPE_LOCKED from dba_tab_statistics where table_name='EMPLOYEE' and owner='HR';

OWNER        TABLE_NAME                     STATTYPE_LOCKED
------------ ------------------------------ ---------------
HR           EMPLOYEE                           ALL
SQL>

So, the column "stattype_locked" value is showing "ALL", that means statistics is locked for that table.

Solution :

SQL> EXEC DBMS_STATS.unlock_table_stats('HR','EMPLOYEE');
PL/SQL procedure successfully completed.
SQL>

Now try to run stats again:

SQL> execute dbms_stats.gather_table_stats(ownname => 'HR', tabname => 'EMPLOYEE', estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO');

PL/SQL procedure successfully completed.

SQL>

Similarly we can unlock stats for a schema also.

SQL> EXEC DBMS_STATS.unlock_schema_stats('HR');
PL/SQL procedure successfully completed.

Viewing all articles
Browse latest Browse all 1640

Trending Articles