Hi,
as Carsten_Schmitz already explained we are using a "four" step method to get rid of these large tables. As far as I know this is the only working method for such highly frequently as well as large tables, since the typical one liner
dbms_redefinition.redef_table()
does not provide any possibility to change the timeout parameter. The documentation says that redef_table() is only passing more or less fixed arguments to the following procedures:
dbms_redefinition.can_redef_table()
dbms_redefinition.start_redef_table()
dbms_redefinition.copy_table_depents()
dbms_redefinition.finish_redef_table()
The only thing you additionally need is a temporary table that has the same column and lob definitions as the original table has.
1. Create DDL of the table you are going to reorg:
dbms_metadata.get_ddl('TABLE', 'RH', '<SCHEMANAME>') from dual;
2. Edit the DDL and remove all constraints and "not null" definitions. The edited DDL might look like this:
CREATE TABLE "<SCHEMANAME>"."RH"
( "RH_CLIENT" NUMBER(*,0),
"RH_AH_IDNR" NUMBER(*,0),
"RH_TYPE" VARCHAR2(4 CHAR),
"RH_TIMESTAMP1" DATE,
"RH_TIMESTAMP4" DATE,
"RH_DELETEFLAG" NUMBER(*,0),
"RH_ARCHIVEFLAG" NUMBER(*,0),
"RH_BLKSIZE" NUMBER(*,0),
"RH_TITLE" VARCHAR2(200 CHAR),
"RH_XMLFLAG" NUMBER(*,0),
"RH_FILEFULLPATH" VARCHAR2(512 CHAR),
"RH_FILEONAGENT" NUMBER(*,0),
"RH_FILEINDB" NUMBER(*,0),
"RH_USERSLOGIN" NUMBER(*,0),
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "<TABLESPACENAME>"
!!! Caution: When reorganizing tables containing LOBs you need to take care of the lob definition, because it might say "STORE AS SECUREFILE" even when you want BASICFILE to be used !!!
3. Rename the table within your ddl and create it. It will be used as interim table later in step 4 (i.e RH_GUIDE_$TEST)
4. Run the following PL/SQL block (and don't forget to change schema and tablespace names):
exec dbms_redefinition.can_redef_table (uname => '<SCHEMANAME>', tname => 'RH', options_flag => dbms_redefinition.cons_use_pk);
exec dbms_redefinition.start_redef_table (uname => '<SCHEMANAME>', orig_table => 'RH', int_table => 'RH_GUIDE_$TEST', options_flag => dbms_redefinition.cons_use_pk);
set serverout on size 1000000
declare
nr_errors number;
begin
nr_errors := 0;
dbms_redefinition.copy_table_dependents (uname => '<SCHEMANAME>', orig_table => 'RH', int_table => 'RH_GUIDE_$TEST', num_errors => nr_errors);
dbms_output.put_line ('ERRORS := '||to_char (nr_errors));
end;
/
exec dbms_redefinition.sync_interim_table (uname => '<SCHEMANAME>', orig_table => 'RH', int_table => 'RH_GUIDE_$TEST');
-- Here comes the part where regular dbms_redefinition.redef_table() exits with an error every time, so we set timeout to a higher value
exec dbms_redefinition.finish_redef_table (uname => '<SCHEMANAME>', orig_table => 'RH', int_table => 'RH_GUIDE_$TEST', dml_lock_timeout => 300);
--- Update: You can drop the interim table later on