dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/oracle/#70
Script #70
oracle
Maintenanceread-onlyMin Version: 11g

Oracle Stale Optimizer Statistics

Finds tables with stale or missing statistics. Catches the most common cause of bad execution plans.

#statistics#stale-stats#optimizer
oracle · sql
SELECT owner, table_name, num_rows, last_analyzed, stale_stats
FROM   dba_tab_statistics
WHERE  owner NOT IN ('SYS','SYSTEM','XDB','MDSYS','CTXSYS')
  AND  object_type = 'TABLE'
  AND  (stale_stats = 'YES' OR last_analyzed IS NULL)
ORDER  BY num_rows DESC NULLS LAST;
Operational Notes & Remediation Guidance

Tables with stale statistics produce sub-optimal execution plans; gather stats via `DBMS_STATS.GATHER_TABLE_STATS`.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 11g).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.