Wednesday 15 June 2011

Copy statistics from one Oracle schema to another

Sometimes statistics are needed to optimize an initial workflow or data load in an empty Oracle schema when large volumes of data are about to be processed. To accomplish this you can import statistics from another schema where said workflow has already run.

Assuming the schema where you will store the stats to be imported is called "TEMP_STATS_SCHEMA" and you have a source schema called "SOURCE_SCHEMA" and a target schema called "TARGET_SCHEMA", the command syntax is as follows:

exec dbms_stats.create_stat_table(ownname => 'TEMP_STATS_SCHEMA', stattab => 'TEMP_STATS_TABLE');
exec dbms_stats.export_schema_stats(statown=> 'TEMP_STATS_SCHEMA', stattab => 'TEMP_STATS_TABLE', ownname => 'SOURCE_SCHEMA');
update TEMP_STATS_SCHEMA.TEMP_STATS_TABLE set c5 = 'TARGET_SCHEMA' where c5 = 'SOURCE_SCHEMA';
commit;
exec dbms_stats.import_schema_stats(statown=> 'TEMP_STATS_SCHEMA', stattab => 'TEMP_STATS_TABLE', ownname => 'TARGET_SCHEMA');

No comments: