You are on page 1of 3

sp========================================================

-- Step 1. Request access for dbms_redefinition package and views from DBA
Check if the table can be redefined
========================================================
EXEC Dbms_Redefinition.Can_Redef_Table('APP_OWNER','APP_TABLE',DBMS_REDEFINITION
.CONS_USE_ROWID);
If no errors are reported it is safe to use dbms_redefinition to migrate this ta
ble
========================================================
-- Step 2. Create Interim table. (APP_OWNER)
========================================================
CREATE TABLE APP_TABLE_INTERMEDIATE TABLESPACE DATA_ENC_TS as (select * from APP
_TABLE where 1=2)
========================================================
-- Step 3. Check the dependencies for that table :
========================================================
SQL> select owner,index_name,index_type from user_indexes where TABLE_NAME='APP_
TABLE';
OWNER
INDEX_NAME
INDEX_TYPE
------------------------------ ------------------------------ -------------------------APP_OWNER
APP_TABLE_UPD_IDX
NORMAL
APP_OWNER
APP_TABLE_LOG_UPD_IDX
NORMAL
APP_OWNER
APP_TABLE_UNIQUE_ADDR_UK
NORMAL
APP_OWNER
APP_TABLE_DT_IDX
NORMAL

SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_OWNER,INDEX_NAME,STATUS from u


ser_constraints where TABLE_NAME='APP_TABLE';
CONSTRAINT_NAME

C INDEX_OWNER
INDEX_NAME
STATUS
------------------------------ - ------------------------------ ----------------------------- -------SYS_C00297379
C
ENABLED
SYS_C00297380
C
ENABLED
SQL> select name,owner,type from user_dependencies where REFERENCED_NAME='APP_TA
BLE';
NAME
-----------------------------APP_PACKAGE
DELETE_CBOX_REPORT

OWNER
TYPE
------------------------------ -----------------APP_OWNER
PACKAGE BODY
APP_OWNER
PROC

========================================================
-- Step 4. Start the Redefintion Process

========================================================
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE(
uname
=> 'APP_OWNER',
orig_table => 'APP_TABLE',
int_table => 'APP_TABLE_INTERMEDIATE',
options_flag => DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/
========================================================
-- Step 5. Copy the dependent objects - After all rows are migrated
If there are lot of indexes which have PII columns you might want to
skip this Step and rebuild indexes as part of Step 11.
Decide on this Setup based on the number of indexes with PII. You can skip this
step and rebuild all indexes at the end.
========================================================

VARIABLE NUM_ERRORS NUMBER;


BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('APP_OWNER','APP_TABLE','APP_TAB
LE_INTERMEDIATE',dbms_redefinition.cons_orig_params,TRUE,TRUE,TRUE,TRUE,:NUM_ERR
ORS,FALSE);
END;
/
Check for the errors :set long 20000
select object_name, base_table_name, ddl_txt fro
m DBA_REDEFINITION_ERRORS
/
========================================================
-- Step 6. resynchronize the interim table
========================================================
BEGIN
dbms_redefinition.sync_interim_table(
uname
=> 'APP_OWNER',
orig_table => 'APP_TABLE',
int_table => 'APP_TABLE_INTERMEDIATE');
END;
/
Before executing Step 7, you need to make sure that there is an application down
time. If you cannot give application downtime, you need to make sure that no one
is accessing the table APP_TABLE during the time, till Step 7 is complete.
========================================================
-- Step 7. Complete the Redefintion Process
========================================================
BEGIN
dbms_redefinition.finish_redef_table(
uname
=> 'APP_OWNER',

orig_table => 'APP_TABLE',


int_table => 'APP_TABLE_INTERMEDIATE');
END;
/
Collect the fresh statistics for the table APP_OWNER. APP_TABLE
exec DBMS_STATS.GATHER_TABLE_STATS(ownname=>'APP_OWNER', tabname=>'APP_TABLE', g
ranularity =>'ALL', cascade=>true,method_opt => 'for all columns size 1',degree=
> 4,estimate_percent=>31,force=>TRUE, no_invalidate=> false);
========================================================
-- Step 8. Validate
========================================================
SQL> select owner,index_name,index_type,status from user_indexes where TABLE_NAM
E='APP_TABLE';
9. Validate Constraints
select CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_OWNER,INDEX_NAME,STATUS from user_c
onstraints where TABLE_NAME='APP_TABLE';
10. Validate Dependencies
SQL> select name,owner,type from user_dependencies where REFERENCED_NAME='APP_TA
BLE';
NAME
-----------------------------APP_PACKAGE
APP_PROCEDURE

OWNER
TYPE
------------------------------ -----------------APP_OWNER
PACKAGE BODY
APP_OWNER
PROC

11. Move only the index having PII column to the encrypted tablespace : (Only if
you haven t executed step 5 to move all the indexes)
ALTER INDEX APP_TABLE_unique_addr_uk REBUILD ONLINE TABLESPACE enc_data_ts;
12. Start the application .

You might also like