0% found this document useful (0 votes)
215 views

Purge Script

The document describes steps to purge historical records from a large, non-partitioned table to reduce downtime. It involves creating a temporary table with records not to be deleted, renaming the original table, recreating indexes on the renamed table, and granting privileges. This process completed in 1.5 hours compared to an estimated 24 hours for a direct delete, saving significant downtime for the application.

Uploaded by

JP Vijaykumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
215 views

Purge Script

The document describes steps to purge historical records from a large, non-partitioned table to reduce downtime. It involves creating a temporary table with records not to be deleted, renaming the original table, recreating indexes on the renamed table, and granting privileges. This process completed in 1.5 hours compared to an estimated 24 hours for a direct delete, saving significant downtime for the application.

Uploaded by

JP Vijaykumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

PURGE SCRIPT Author JP Vijaykumar Oracle DBA Date January 4th 2013 Modidfied January 5th 2013 In one

of our application schemas, historical records are to be deleted from a n on-partitioned large table. During an earlier delete operation of about 1 billion rows from thi s table, it took 11:30 hrs. The application was down during this massive delete operation . The data has grown and the application has to delete about 2 billion rows from t his large table. It is estimated, the delete operation will take around 24 hrs, during which time the applciation will be down.(This estimate is based on the current hardware configuration of th e database, and other operational considerations on the large table). The following are the structural details of our large table: 01 No foreign key constraints defined on this large table referencing other tabl es. 02 No foreign key constraints defined on other tables referencing this large tab le. 03 No triggers created on this large table. 04 No procedures accessing this large table. 05 No views/materialized views created on this large table. 06 No private /public synonyms created on this large table. 07 Primary key constraints/unique key constraints were defined on this large tab le. 08 Privileges on this large table were granted to roles. 09 This large table is NOT PARTITIONED. The following steps detail the purge operation on the large table: 01 the business provides the condition to delete rows from our large table. 02 created a temporary table(with suffix "_o") with rows that are NOT TO BE dele ted from the large table. care is to be taken while incorporating the delete logic into table creation script. check & verify the table creation is actually holding records that are not to be deleted. for safety, do not drop the renamed original large table for some more time. once the business confirms, the data in the new large table is ok, then drop the renamed table. 03 generated index creation ddls from the large table for future use. 04 generated script to grant privileges on the large table. 05 renamed the original large table as a dummy table(with suffix "_t"). 06 renamed all the indexes on the large tables as dummy indexes(with suffix "_t" ). 07 renamed the temporary table(from step 02) as the large table(suffix ".._o" wa s removed). 08 created all the necessary indexes from the ddls generated in step 03 on the r enamed table. 09 executed the script granting privileges on the renamed large table, captured in step 04. The operation completed under 1:30 hours, saving the business about 22:30 hrs of

downtime. Proof read the script, test it few times, once comfortable with the script, then only implement it. The following pl/sql procedure generates the required script to perform the reor g. This script only works on the above detailed structural definition of the large table. The script is to be modified, if there are any structural differences in your en vironment. As a precaution, the original large table is renamed ONLY. Once the business verifies the purge operation in the new large table and sign o ff, the renamed large table can be dropped safely at a later date. set serverout on size 1000000 timing on long 10000 linesize 120 pagesize 100 declare /**************************************** ORIGINAL REQUIREMENT TO DELETE ROWS FROM THE LARGE TABLE, PROVIDED BY BUSINESS Delete from .................... ****************************************/ v_tab varchar2(30):='VEEKSHA'; v_str varchar2(32000); begin dbms_output.put_line('create table '||v_tab||'_o nologging parallel(degree 4) as select * from '||v_tab||' a '); dbms_output.put_line('where not exists '); dbms_output.put_line('............business provided delete condition............ ............................. '); dbms_output.put_line('rename '||v_tab||' to '||v_tab||'_t;'); dbms_output.put_line('rename '||v_tab||'_o to '||v_tab||';'); for c1 in (select index_name from user_indexes where table_name=v_tab)loop begin dbms_output.put_line('alter index '||c1.index_name||' rename to '||c1.index_name ||'_t;'); execute immediate 'select dbms_metadata.get_ddl('''||'INDEX'||''','''||c1.index_name||''') from du al' into v_str ; dbms_output.put_line(v_str||' nologging parallel(degree 4);'); exception when others then dbms_output.put_line(sqlerrm); end; end loop; for c2 in (select privilege,grantee from user_tab_privs where table_name=v_tab) loop dbms_output.put_line('grant '||c2.privilege||' on '||v_tab||' to '||c2.grantee|| ';'); end loop; dbms_output.put_line('--PLS DROP THE TABLE '||v_tab||'_T AFTER ONE WEEK'); end; /

create table VEEKSHA_o nologging parallel(degree 4) as select * from VEEKSHA a where not exists ............business provided delete condition.................................. ....... rename VEEKSHA to VEEKSHA_t; rename VEEKSHA_o to VEEKSHA; alter index VEEKSHA_INDEX rename to VEEKSHA_INDEX_t; CREATE UNIQUE INDEX "VEEKSHA"."VEEKSHA_INDEX" ON "VEEKSHA"."VEEKSHA" ("NUM", " SEQ_NUM", "VEEKSHA_NUM","VEEKSHA_SEQ_NUM") PCTFREE 40 INITRANS 10 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VEEKSHADATA" nologging parallel(degree 4); alter index VEEKSHA_INDEX2 rename to VEEKSHA_INDEX2_t; CREATE INDEX "VEEKSHA"."VEEKSHA_INDEX2" ON "VEEKSHA"."VEEKSHA" ("NUM", "SEQ_NU M", "NUM_PROFILE", "VEEKSHA_SEQ_NUM") PCTFREE 40 INITRANS 10 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VEEKSHADATA" nologging parallel(degree 4); alter index VEEKSHA_INDEX4 rename to VEEKSHA_INDEX4_t; CREATE INDEX "VEEKSHA"."VEEKSHA_INDEX4" ON "VEEKSHA"."VEEKSHA" ("NUM", "VEEKSH A_DATE", "STATUS") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "VEEKSHADATA" nologging parallel(degree 4); grant SELECT on VEEKSHA to APP_READONLY; grant DELETE on VEEKSHA to APP_USER; grant INSERT on VEEKSHA to APP_USER; grant SELECT on VEEKSHA to APP_USER; grant UPDATE on VEEKSHA to APP_USER; grant SELECT on VEEKSHA to APP_RO_VEEKSHA; grant DELETE on VEEKSHA to APP_RW_VEEKSHA; grant INSERT on VEEKSHA to APP_RW_VEEKSHA; grant SELECT on VEEKSHA to APP_RW_VEEKSHA; grant UPDATE on VEEKSHA to APP_RW_VEEKSHA; grant SELECT on VEEKSHA to DAS_RO_VEEKSHA; grant DELETE on VEEKSHA to DAS_RW_VEEKSHA; grant INSERT on VEEKSHA to DAS_RW_VEEKSHA; grant SELECT on VEEKSHA to DAS_RW_VEEKSHA; grant UPDATE on VEEKSHA to DAS_RW_VEEKSHA; --PLS DROP THE TABLE VEEKSHA_T AFTER ONE WEEK PL/SQL procedure successfully completed. Elapsed: 00:00:12.20 The above output from the adhoc procedure's should be executed interactively.

You might also like