denrepo

OracleStatistics

Tables and partitions with stale statistics

Application objects the optimizer considers stale. The flush at the top makes sure recent DML is counted before the check.

12c+

Not yet verified. How scripts are tested

ora-stale-stats.sql
1EXEC DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;2 3CLEAR COLUMNS4SET LINESIZE 160 PAGESIZE 200 TRIMOUT ON TAB OFF5COLUMN owner          FORMAT A206COLUMN table_name     HEADING "TABLE"     FORMAT A307COLUMN partition_name HEADING "PARTITION" FORMAT A258COLUMN object_type    HEADING "LEVEL"     FORMAT A129COLUMN analyzed       FORMAT A1010COLUMN num_rows       HEADING "ROWS"      FORMAT 999,999,999,99011 12SELECT owner, table_name, partition_name, object_type,13       TO_CHAR(last_analyzed, 'YYYY-MM-DD') AS analyzed, num_rows14FROM dba_tab_statistics15WHERE stale_stats = 'YES'16  AND owner NOT IN (SELECT username FROM dba_users WHERE oracle_maintained = 'Y')17ORDER BY owner, table_name, partition_name;

Save it as ora-stale-stats.sql and run it with SQL> @ora-stale-stats.

Open in denrepo

More Oracle scripts: Statistics