Script rebuilds the schema with minimal downtime

Script rebuilds the schema with minimal downtime

CREATE OR REPLACE PROCEDURE schema_rebuild authid current_user IS
CURSOR obj_list IS
SELECT decode( segment_type, 'TABLE', segment_name, table_name ) order_col1,
decode( segment_type, 'TABLE', 1, 2 ) order_col2,
decode( segment_type, 'TABLE', ' move ', ' rebuild ' ) m_or_r,segment_type,segment_name
FROM user_segments, (SELECT table_name, index_name FROM user_indexes )
WHERE segment_type IN ( 'TABLE', 'INDEX' )
AND segment_name = index_name (+) ORDER BY 1, 2 ;

reb_str VARCHAR2(200) ;
username varchar2(20);


BEGIN
username:=user;
FOR i IN OBJ_LIST LOOP
IF i.segment_type = 'INDEX' THEN
reb_str := 'alter ' || i.segment_type || ' ' || i.segment_name ||' '|| i.m_or_r ||' online';
ELSE
reb_str := 'alter ' || i.segment_type || ' ' || i.segment_name ||' '|| i.m_or_r;
END IF;
EXECUTE IMMEDIATE reb_str;
reb_str := '';
END LOOP ;
dbms_stats.gather_schema_stats (ownname=>username, method_opt=>'FOR ALL INDEXED COLUMNS', cascade=>TRUE);
END ;
/

Comments

Popular posts from this blog

How to make partitioning in Oracle more Quickly

Copy files between Unix and Windows with rcp

ORA-04062: timestamp of procedure has been changed