Restore Oracle Optimizer Statistics 还原 统计信息

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

NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product. Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.

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:-
 

execute DBMS_STATS.ALTER_STATS_HISTORY_RETENTION (xx)

- where xx is the number of days to retain them

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:-
 

execute DBMS_STATS.RESTORE_TABLE_STATS ('owner','table',date)
execute DBMS_STATS.RESTORE_DATABASE_STATS(date)
execute DBMS_STATS.RESTORE_DICTIONARY_STATS(date)
execute DBMS_STATS.RESTORE_FIXED_OBJECTS_STATS(date)
execute DBMS_STATS.RESTORE_SCHEMA_STATS('owner',date)
execute DBMS_STATS.RESTORE_SYSTEM_STATS(date)


ie
 

execute dbms_stats.restore_table_stats ('SCOTT','EMP','25-JUL-07 12.01.20.766591 PM +02:00');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值