Oracle Database - Enterprise Edition - Version 10.1.0.2 and later Oracle Database - Standard Edition - Version 10.1.0.2 and later Oracle Database - Personal Edition - Version 10.1.0.2 and later Information in this document applies to any platform.
PURPOSE
This document outlines the facility by which statistics may be restored following their removal. This facility is available from Orale 10g onwards.
SCOPE
Assist with restoring statistics in the event that they are overwritten.
DETAILS
Beginning with Oracle10G, when statistics are gathered for a table, the old statistics are retained so should there be any problem with performance of queries dependent on those statistics, the old ones can be restored.
How long does Oracle retain the statistics for ?
The default period for which statistics are retained is 31 days but this can be altered with:-
NOTE: There is an overhead of storage in the SYSAUX tablespace with statistics so care should be taken not to cause the tablespace to fill with the statistics
How do I know how many days the statistics are available for ?
select DBMS_STATS.GET_STATS_HISTORY_RETENTION from dual;
- will return the number of days stats are currently retained for.
select DBMS_STATS.GET_STATS_HISTORY_AVAILABILITY from dual;
- will return the date statistics have been purged up to (so only dates newer then this can possibly be restored to). Any request to restore stats from this date or older will fail with: "ORA-20006: Unable to restore statistics , statistics history not available"
How do I find the statistics history for a given table ?
select TABLE_NAME, STATS_UPDATE_TIME from dba_tab_stats_history
Will show the times statistics were regathered for a given table.
How do I restore the statistics ?
Having decided what date you know the statistics were good for, you can use:-
Statistics cannot be directly exported from one schema and imported into a different schema.The schema names much match exactly. If the target database schema is different from the source database schema, the schema name can be changed by updating column C5 of the STATS table:
update table STATS set c5 = '' where c5 = '' and statid = ;
8. Upgrading statistics table
When importing statistics from an earlier version into a later version of Oracle, the structure of the statistics table may have changed. Try executing DBMS_STATS.UPGRADE_STAT_TABLE to resolve this
Note: When exporting and importing database objects, Datapump Export and Import utilities will also export and import optimizer statistics along with the tables even when a column has system-generated names.
Importing statistics will overwrite any previous statistics that existed for the table having statistics imported. For example, if previously there were histogram statistics and you import statistics that do not include histograms, there will no longer be any histogram information.
Comments
Post a Comment
Oracle DBA Information