统计信息导出导入
1.創建用於存儲統計信息表
BEGIN
DBMS_STATS.create_stat_table (ownname => 'SAILY', stattab => 'ST_TEST01');
END;
/
2.收集待導出表統計信息
EXECUTE dbms_stats.gather_table_stats(ownname => 'SAILY',tabname => 'TEST01' ,estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,method_opt => 'for all columns size auto' ,cascade => true ,degree=>6);
3.導出表統計信息
/* Formatted on 2022-03-22 08:42:35 (QP5 v5.163.1008.3004) */
BEGIN
DBMS_STATS.export_table_stats (ownname => 'SAILY',
tabname => 'TEST01',
statown => 'SAILY',
stattab => 'ST_TEST01',
statid => 'TEST01');
END;
/
用時3秒多
4.目標數據庫新建統計表
BEGIN
DBMS_STATS.create_stat_table (ownname => 'MONKEY', stattab => 'ST_TEST01');
END;
/
5.統計信息遷移至目標數據庫
導入導出或者DBLINK都可以
INSERT INTO MONKEY.ST_TEST01 SELECT * FROM SAILY.ST_TEST01@MONKEYDB;
6.創建待導入測試表
導入的表欄位和索引名字要和導出表一致(表owner,表名,分區名可不一樣)
7.修改統計信息表的OWNER和分區名
/*總表統計信息*/
UPDATE MONKEY.ST_TEST01 SET C5='MONKEY' WHERE C2 IS NULL;
/*分區統計信息*/
UPDATE MONKEY.ST_TEST01 SET C5='MONKEY' WHERE C2 = 'PAT_201507';
UPDATE MONKEY.ST_TEST01 SET C2='PAT_202203' WHERE C2 = 'PAT_201507';
8.導入統計信息
/* Formatted on 2022-03-23 09:58:09 (QP5 v5.163.1008.3004) */
BEGIN
DBMS_STATS.import_table_stats (ownname => 'MONKEY',
tabname => 'TEST01',
statown => 'MONKEY',
stattab => 'ST_TEST01',
statid => 'TEST01');
END;
/