Home > Database > Mysql Tutorial > Oracle入门教程:统计信息的恢复和备份

Oracle入门教程:统计信息的恢复和备份

WBOY
Release: 2016-06-07 17:12:24
Original
1171 people have browsed it

oracle 11g 增加了系统信息的备份和恢复功能,分别是在系统级别,用户级别,表级别!当我们对oracle 系统对象进行统计信息收集时,为

Oracle 11g 增加了系统信息的备份和恢复功能,分别是在系统级别,用户级别,表级别!当我们对oracle 系统对象进行统计信息收集时,为了防止新的统计信息之后的执行计划不如之前的,我们可以利用
dbms_stats.export_(database/schema/table)_stats 导出统计信息到创建的表中
dbms_stats.import_(database/schema/table)_stats 导入统计信息到系统中
来进行恢复统计信息!
对统计信息的备份和恢复包括如下等级
1)数据库的统计信息备份恢复(只能是sys用户下)
exec dbms_stats.create_stat_table('sys','stat_sys');
exec dbms_stats.export_database_stats('stat_sys');
exec dbms_stats.import_database_stats('stat_sys');

2)方案的统计信息备份恢复(只能在方案拥有者的用户下,yang为用户名)
exec dbms_stats.create_stat_table('yang','stat_2');
exec dbms_stats.export_schema_stats('yang','stat_2');
exec dbms_stats.import_schema_stats('yang','stat_2');

3)表的统计信息备份恢复(只能在表拥有者的用户下)
exec dbms_stats.create_stat_table('yang','stat_3');
exec dbms_stats.export_table_stats('yang','T1',null,'stat_3');
exec dbms_stats.import_table_stats('yang','T1',null,'stat_3');

下面针对用户级别做一个测试!
1 创建统计信息备份存放的表
@linuxidc> exec dbms_stats.create_stat_table('yang','stat_4');
PL/SQL procedure successfully completed.

2 对用户yang 进行统计,并将统计信息导出到表里面!
@linuxidc> begin
  2  dbms_stats.gather_schema_stats(
  3  ownname          => 'yang',
  4  estimate_percent => 100,
  5  method_opt       => 'for all columns size auto',
  6  degree           => 2);
  7  end;
  8  /
PL/SQL procedure successfully completed.
@linuxidc> select table_name,last_analyzed from user_tables where table_name='T2';
TABLE_NAME                     LAST_ANALYZED
------------------------------ ------------------
T2                             27-FEB-12

@linuxidc> exec dbms_stats.export_schema_stats('yang','stat_4');
PL/SQL procedure successfully completed.
3 删除之前的统计信息并查询验证
@linuxidc> exec dbms_stats.delete_schema_stats('yang');
PL/SQL procedure successfully completed.
@linuxidc> select table_name,last_analyzed from user_tables where table_name='T2';
TABLE_NAME                     LAST_ANALYZED
------------------------------ ------------------
T2

4 将之前备份的统计信息从新导入
@linuxidc> exec dbms_stats.import_schema_stats('yang','stat_4');
PL/SQL procedure successfully completed.
查询yang 用户下的t2表的统计分析时间!
@linuxidc> select table_name,last_analyzed from user_tables where table_name='T2';
TABLE_NAME                     LAST_ANALYZED
------------------------------ ------------------
T2                             27-FEB-12

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template