常用场景:
1.生产环境的统计信息导入到测试环境使得执行计划的产生能极大程度上等同于生产环境。
2.割接测试环境的统计信息快速导入生产,替代生产库统计信息的收集操作,减少停机时间。
两种方式:
1.expdp/exp STATISTICS,impdp/imp
2.exec dbms_stats.export_schema_stats('SCOTT','STATS_TABLE','SCOTT')/dbms_stats.import_schema_stats
dbms_stats.export_table_stats/dbms_stats.import_table_stats
一般用在割接时间特别紧的时候,快速实现导入替代统计信息的收集操作:大库的收集时间较长。
alter session set parallel_force_local=true;
alter session set workarea_size_policy=manual;
alter session set sort_area_size=1073741820;
alter session set sort_area_retained_size=1073741820;
alter session set db_file_multiblock_read_count=128;
exec DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>'OGGSELET',ESTIMATE_PERCENT=>100,method_opt=>'for all columns size 1',cascade=>true,force=>true,degree=>64);
dbms_stats.export_table_stats例子:
生产库和测试库检查:
select TABLE_NAME,COLUMN_NAME,NUM_BUCKETS from DBA_TAB_COL_STATISTICS WHERE TABLE_NAME='DES_SERVICEORDER'
select table_name,num_rows from user_tables where table_name not like 'TEMP%' and table_name not like 'TR_TMP%' and num_rows is null order by table_name
测试库:
创建临时统计表:
exec dbms_stats.create_stat_table(ownname => 'GISTAR',stattab => 'stat_table') ;
=====以下配合生产库的import需反复操作====
truncate table stat_table;
exec dbms_stats.export_table_stats(ownname => 'GISTAR',tabname => 'DES_SERVICEORDER',stattab => 'stat_table');
生产库:
准备tnsnames.ora
oracle@zydb1:/db/product/11.2/db_1/network/admin(lnzy1)>vi tnsnames.ora
LNZYCS2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.14.21.36)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = lnzycs)
)
)
SQL> conn /as sysdba
Connected.
SQL> create public database link gistar_lnzycs2 connect to GISTAR identified by xxx using 'lnzycs2';
Database link created.
SQL> select * from dual@gistar_lnzycs2;
D
X
========以下配合测试库的export反复操作
drop table stat_table;
create table stat_table as select * from stat_table@gistar_lnzycs2;
exec dbms_stats.import_table_stats(ownname => 'GISTAR',tabname => 'DES_SERVICEORDER',stattab => 'stat_table');
其它参考: