测试数据导入,采集统计信息的时候,提示错误信息,使用oerr检索错误号,无此错误号解释。
SQL exec dbms_stats.gather_table_stats(‘USER_A’,’A’,cascade=true);
BEGIN dbms_stats.gather_table_stats(‘USER_A’,’A’,cascade=true); END;
* ERROR at line 1: ORA-20005: object statistics are locked (stattype = ALL) ORA-06512: at "SYS.DBMS_STATS", line 24281 ORA-06512: at "SYS.DBMS_STATS", line 24332 ORA-06512: at line 1
检索MOS有这个错误号的信息,意思就是统计信息被锁了,
ORA-20005 reported on Queue Table Statistics Collection (文档 ID 558187.1)
“ORA-20005: object statistics are locked” Error When Executing gather_table_stats.sql Script (文档 ID 967050.1)
我们看下dba_tab_statistics视图,
SQL exec print_table(‘select owner, table_name, num_rows, blocks, sample_size, last_analyzed, stattype_locked from dba_tab_statistics where owner=’’USER_A’’’);
OWNER: USER_A TABLE_NAME: A NUM_ROWS: 151853523 BLOCKS: 2184641 SAMPLE_SIZE: 2000 LAST_ANALYZED: 10-jan-2018 16:07:51 STATTYPE_LOCKED: ALL -----------------
PL/SQL procedure successfully completed.
其中SAMPLE_SIZE只有2000,
STATTYPE_LOCKED值为ALL,
从官方手册了解,dbms_stats有对应加锁和解锁的方法,
其中加锁可以有两个维度,一个是锁schema,
另一个是锁表,
相应解锁schema,
相应的解锁表,
此处只需要解锁这张表,
SQL exec dbms_stats.unlock_table_stats(‘USER_A’,’A’);
PL/SQL procedure successfully completed.
再次检索,可以看出,此时STATTYPE_LOCKED值为’’,
SQL exec print_table(‘select owner, table_name, num_rows, blocks, sample_size, last_analyzed, stattype_locked from dba_tab_statistics where owner=’’USER_A’’’);
OWNER: USER_A TABLE_NAME: A NUM_ROWS: 159880353 BLOCKS: 2299340 SAMPLE_SIZE: 159880353 LAST_ANALYZED: 25-jan-2018 14:05:13 STATTYPE_LOCKED: -----------------
PL/SQL procedure successfully completed.
可以采集统计信息了,
SQL exec dbms_stats.gather_table_stats(‘USER_A’,’A’,cascade=true);
PL/SQL procedure successfully completed.
问题可以解决,但还是需要问,为何需要解锁统计信息?猜测可能的原因,就是原库用了lock锁定统计信息,其实导入的时候,若排除统计信息,可能也算是一种解决方案。
如果您觉得本文有帮助,欢迎关注转发:bisal的个人杂货铺,