Pages

Wednesday, January 18, 2023

How to copy stats from existing partition to a new partition

How to copy stats from existing partition to a new partition

--Copy Start from Old Partition to New partition
BEGIN
 DBMS_STATS.COPY_TABLE_STATS ('MY_OWNER', 'MY_TABLE', 'P_OLD', 'P_NEW', FORCE=>TRUE);
END;
/

--Lock stats. to avoid reset from scheduled stats collection
BEGIN
 DBMS_STATS.LOCK_TABLE_STATS('MY_OWNER','MY_TABLE');
END;
/

--Make stats incremental, when collecting stats. 
For big table, partitions were data was not changed, will not be involved again and again in stats collection, only partitions were data was changed, will be worked upon.
BEGIN
 DBMS_STATS.SET_TABLE_PREFS('MY_OWNER','MY_TABLE','INCREMENTAL','TRUE');
END;
/

--Gather table stats - on the table
BEGIN
 DBMS_STATS.gather_table_stats('MY_OWNER','MY_TABLE',CASCADE => TRUE);
END;
/

No comments:

Post a Comment