I don't really understand how to delete columns using the dbms_redefinition utility. All the time there are some strange errors and data overwriting. Disabled foreign keys appear in other tables and are not deleted. Indexes are duplicated... If anyone understands how to use this utility, then please help. I would also like to hear about the pitfalls, if there are any and an explanation of each step
I use the following sequence:
First, I mark the columns in table
Aas unused (ALTER TABLE A SET UNUSED (...))Generating DDL to create a new table without unused columns (
SELECT DBMS_METADATA.GET_DDL('TABLE', 'A') FROM dual) and create tableA_temporaryAnd finally I use dbms_redefinition:
DECLARE p_owner varchar2(30) := 'user'; orig_table varchar2(30) := 'A'; int_table varchar2(30) := 'A_temporary'; BEGIN DBMS_REDEFINITION.START_REDEF_TABLE(p_owner, orig_table, int_table, NULL, dbms_redefinition.cons_use_pk); END; / DECLARE p_owner varchar2(30) := 'user'; orig_table varchar2(30) := 'A'; int_table varchar2(30) := 'A_temporary'; num_errors PLS_INTEGER; BEGIN DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(p_owner, orig_table, int_table, dbms_redefinition.cons_orig_params, TRUE, TRUE, TRUE, TRUE, num_errors); END; / SELECT OBJECT_NAME, BASE_TABLE_NAME, DDL_TXT FROM DBA_REDEFINITION_ERRORS; DECLARE p_owner varchar2(30) := 'user'; orig_table varchar2(30) := 'A'; int_table varchar2(30) := 'A_temporary'; BEGIN DBMS_REDEFINITION.SYNC_INTERIM_TABLE(p_owner, orig_table, int_table); END; / DECLARE p_owner varchar2(30) := 'user'; orig_table varchar2(30) := 'A'; int_table varchar2(30) := 'A_temporary'; BEGIN DBMS_REDEFINITION.FINISH_REDEF_TABLE(p_owner, orig_table, int_table); END; / DROP TABLE A_temporary CASCADE CONSTRAINTS PURGE /
I took this instruction from here. Is everything okay in it in the three steps that I take and I shouldn't have any problems, or am I using it incorrectly and you have any comments?
The purpose of the idea is to achieve fast physical deletion of columns
P.S. The table I'm doing this for has a lot of relationships with other tables and takes up a lot of disk space (about 200 GB)
alter table moveto remove an unused col from the data blocks and free up the space. It's then gone both logically and physically.alter table .. move parallel (degree 16) update indexes onlinethat does not block DMLs, except that it requires a brief exclusive lock at the very end to swap the segments.