Bloquear e desbloquear estatísticas de tabela/schema
OracleEstatísticasComando
-- Lock (the auto stats job and normal GATHER calls no longer touch them):
EXEC DBMS_STATS.LOCK_TABLE_STATS(ownname => 'CUSTOMER_APP', tabname => 'ORDERS');
EXEC DBMS_STATS.LOCK_SCHEMA_STATS(ownname => 'CUSTOMER_APP');
-- A single partition only: DBMS_STATS.LOCK_PARTITION_STATS('CUSTOMER_APP', 'SALE_PART', 'P2026_H1');
-- Locked objects:
SELECT owner, table_name, partition_name, stattype_locked
FROM dba_tab_statistics
WHERE owner = 'CUSTOMER_APP' AND stattype_locked IS NOT NULL;
-- Deliberate gathering while locked (instead of ORA-20005):
EXEC DBMS_STATS.GATHER_TABLE_STATS('CUSTOMER_APP', 'ORDERS', force => TRUE);
-- Unlock:
EXEC DBMS_STATS.UNLOCK_SCHEMA_STATS(ownname => 'CUSTOMER_APP');
EXEC DBMS_STATS.UNLOCK_TABLE_STATS(ownname => 'CUSTOMER_APP', tabname => 'ORDERS');O que faz
Bloqueia as estatísticas contra alterações; a tarefa automática ignora objetos bloqueados e uma chamada GATHER em nível de tabela gera ORA-20005. force=>TRUE coleta sem remover o bloqueio.
Quando usar
Para manter estatísticas representativas em tabelas de staging/voláteis que são esvaziadas e recarregadas durante o dia, proteger os planos de uma tabela crítica contra mudanças de estatísticas ou preservar valores definidos com DBMS_STATS.SET_TABLE_STATS.
Atenção
Não exige licença. Estatísticas bloqueadas se afastam da realidade com o tempo e causam erros de cardinalidade; reporte os objetos bloqueados regularmente. Um bloqueio de schema não cobre tabelas adicionadas ao schema depois. Em uma tabela bloqueada, CREATE/REBUILD INDEX também não coleta estatísticas do índice automaticamente.