[20120607]restore 舊的統計資訊.txt
今天測試一下,如何restore舊的統計:
select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create table t as select rownum id1 ,rownum id2 ,'test' name from dual connect by level<=100 ;
--建立表僅僅100條記錄.
SQL> exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'T',method_opt=>'for all columns size 1');
PL/SQL procedure successfully completed.
2.刪除一些資料,在分析:
SQL> delete from t where id1<=50;
50 rows deleted.
SQL> exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'T',method_opt=>'for all columns size 1');
PL/SQL procedure successfully completed.
3.restore看看.
select status_update_time from user_tab_stats_history;
SQL> select * from user_tab_stats_history where table_name='T';
TABLE_NAME PARTITION_NAME SUBPARTITION_NAME STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
T 2012-06-05 17:35:25.887572
T 2012-06-05 17:36:38.553086
SQL> select num_rows from user_tables where table_name='T';
NUM_ROWS
----------
50
--可以發現現在的統計僅僅50條.
SQL> exec dbms_stats.restore_table_stats(ownname=>user,tabname=>'T', as_of_timestamp=>' 2012-06-05 17:35:25.887572');
PL/SQL procedure successfully completed.
--注意時間的格式!我定義環境變數:
export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
export NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'
export NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'
SQL> select num_rows from user_tables where table_name='T';
NUM_ROWS
----------
100
SQL> select * from user_tab_stats_history where table_name='T';
TABLE_NAME PARTITION_NAME SUBPARTITION_NAME STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
T 2012-06-05 17:35:25.887572
T 2012-06-05 17:36:38.553086
T 2012-06-05 17:41:17.564189
select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create table t as select rownum id1 ,rownum id2 ,'test' name from dual connect by level<=100 ;
--建立表僅僅100條記錄.
SQL> exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'T',method_opt=>'for all columns size 1');
PL/SQL procedure successfully completed.
2.刪除一些資料,在分析:
SQL> delete from t where id1<=50;
50 rows deleted.
SQL> exec dbms_stats.gather_table_stats(ownname=>user, tabname=>'T',method_opt=>'for all columns size 1');
PL/SQL procedure successfully completed.
3.restore看看.
select status_update_time from user_tab_stats_history;
SQL> select * from user_tab_stats_history where table_name='T';
TABLE_NAME PARTITION_NAME SUBPARTITION_NAME STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
T 2012-06-05 17:35:25.887572
T 2012-06-05 17:36:38.553086
SQL> select num_rows from user_tables where table_name='T';
NUM_ROWS
----------
50
--可以發現現在的統計僅僅50條.
SQL> exec dbms_stats.restore_table_stats(ownname=>user,tabname=>'T', as_of_timestamp=>' 2012-06-05 17:35:25.887572');
PL/SQL procedure successfully completed.
--注意時間的格式!我定義環境變數:
export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
export NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'
export NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS.FF'
SQL> select num_rows from user_tables where table_name='T';
NUM_ROWS
----------
100
SQL> select * from user_tab_stats_history where table_name='T';
TABLE_NAME PARTITION_NAME SUBPARTITION_NAME STATS_UPDATE_TIME
------------------------------ ------------------------------ ------------------------------ ---------------------------------------------------------------------------
T 2012-06-05 17:35:25.887572
T 2012-06-05 17:36:38.553086
T 2012-06-05 17:41:17.564189
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-731981/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 備份恢復統計資訊 backup and restore statsREST
- 【ASK_ORACLE】Oracle如何恢復舊的統計資訊Oracle
- 統計資訊過舊導致SQL無法執行出來SQL
- 【統計資訊】Oracle統計資訊Oracle
- 【統計資訊】Oracle常用的收集統計資訊方式Oracle
- ORACLE表統計資訊與列統計資訊、索引統計資訊Oracle索引
- [20171204]guaranteed restore point.txtREST
- [20151226]統計資訊的儲存時間.txt
- date列統計資訊陳舊導致sql沒有選擇最優執行計劃SQL
- Oracle的統計資訊Oracle
- ORACLE表統計資訊與列統計資訊Oracle
- 利用dbms_stats.gather_database_stats包快速確定統計資訊為空或陳舊的物件Database物件
- 實驗-審計資訊的清理和策略關閉.txt
- 修改oracle 的統計資訊Oracle
- [20180322]檢視統計資訊的儲存歷史.txt
- 【統計資訊】全面檢視錶所有統計資訊SQLSQL
- Oracle 統計資訊Oracle
- MySQL 統計資訊MySql
- Oracle統計資訊Oracle
- 系統統計資訊的儲存位置
- 統計資訊的查詢方法
- Oracle系統統計資訊Oracle
- [統計資訊系列7] Oracle 11g的自動統計資訊收集Oracle
- [20190228]Backup Restore Throttle sleep.txtREST
- Oracle收集統計資訊Oracle
- Oracle 統計資訊收集Oracle
- 收集oracle統計資訊Oracle
- ORACLE 收集統計資訊Oracle
- oracle統計資訊(四)Oracle
- oracle統計資訊(三)Oracle
- oracle統計資訊(二)Oracle
- oracle統計資訊(一)Oracle
- redis 伺服器的統計資訊Redis伺服器
- 處理鎖住的統計資訊
- 收集統計資訊的簡單操作
- ORACLE 統計資訊的收集與管理Oracle
- 統計資訊收集不完的解決
- [sqlserver] 檢視錶的統計資訊SQLServer