Prligence Empowering Intelligence 1 Painless Master Table Alter In Replication Paper # 524 Arup...

Post on 15-Dec-2015

219 views 3 download

Tags:

Transcript of Prligence Empowering Intelligence 1 Painless Master Table Alter In Replication Paper # 524 Arup...

1

pr ligence Empowering Intelligence

Painless Master Table Alter In Replication

Paper # 524

Arup Nandapr ligence

Empowering Intelligence

2

pr ligence Empowering Intelligence

Question

Two Most Important Objectives of Living Organisms

Surviving

Reproducing!

3

pr ligence Empowering Intelligence

Replication Options Revisited

MASTER COPY

4

pr ligence Empowering Intelligence

Multi-Master

MASTER COPY

TriggerTrigger

SnapshotLogs

ROW1 ROW1

pushROW2

TriggerTrigger

SnapshotLogs

ROW2

Primary Secondary

5

pr ligence Empowering Intelligence

Multi-Master contd.

• Can be Used in Disaster Recovery• Can be SYNCHRONOUS • Secondary Copy Useful for Transactions• Bidirectional Flow of Data _

Changes are PUSHED to secondaryAdvantages

6

pr ligence Empowering Intelligence

Multi-Master contd.

• Continuosly Available Link Required• Conflict Resolution Logic Needed• Can Strain the Database _

Disadvantages

7

pr ligence Empowering Intelligence

Updateable Snapshot

MASTER SNAPSHOT

TriggerTrigger

SnapshotLogs

ROW1 ROW1

pull

ROW2

TriggerTrigger

SnapshotLogs

ROW2

push

CREATE SNAPSHOT MYSNAP

FOR UPDATE AS

SELECT * FROM MASTER@MAINDB

8

pr ligence Empowering Intelligence

Updateble Snapshots contd.

• Changes are PULLED rather than pushedAdvantages• Controlled from Secondary Side• Continuous Link Not Needed• Can be Used in Disaster Recovery _

9

pr ligence Empowering Intelligence

Updateable Snapshots contd.

Disadvantages• Conflict Management• Difficult Setup and Administration• Strain on Resources• Cannot be SYNCHRONOUS• Reporting Requirements – Overkill _

10

pr ligence Empowering Intelligence

Read Only Snapshot

MASTER SNAPSHOT

TriggerTrigger

SnapshotLogs

ROW1 ROW1

pull

Primary Secondary

11

pr ligence Empowering Intelligence

Read Only Snapshots contd.

PULLEDControlled by SecondaryDisadvantages

Cannot be Used in Disaster RecoveryAdvantages• No Conflict Management• Simple Setup• Less Strain on Resources• Continuous Link Not Needed _

12

pr ligence Empowering Intelligence

Altering The Master Table

EMPNO ENAME SAL

1 CHARLIE 1000

2 DAN 1500

COMM

100

120

PROD

REPL

Not captured in Refresh Process

EMPNO ENAME SAL COMM

1 CHARLIE 1000 100

2 DAN 1500 120

EMPNO ENAME SAL

1 CHARLIE 1000

2 DAN 1500

13

pr ligence Empowering Intelligence

Documented

EMPNO ENAME SAL COMM

1 CHARLIE 1000 100

2 DAN 1500 120

PROD

REPL

EMPNO ENAME SAL

1 CHARLIE 1000

2 DAN 1500XDrop the Snasphot

14

pr ligence Empowering Intelligence

Documented

EMPNO ENAME SAL COMM

1 CHARLIE 1000 100

2 DAN 1500 120

PROD

REPL

EMPNO ENAME SAL COMM

1 CHARLIE 1000 100

2 DAN 1500 120

Recreate the Snapshot

15

pr ligence Empowering Intelligence

Documented Process

• Drop Snapshot (Snapsite)• Add Column to Master Table (Master)• Create Snapshot (Snapsite)• Refresh Snapshot (Snapsite)

16

pr ligence Empowering Intelligence

Problem

• Time Consuming• Rollback Segment Space Needed• ORA-1555• Temporary Segment Space Needed• Space Needed in Target Tablespace

17

pr ligence Empowering Intelligence

Database Example

• Schema Owner : ANANDA• Table TEST1

– COL1 CHAR(1)– COL2 CHAR(1)

18

pr ligence Empowering Intelligence

Prepping the Master Site

Creating the Snapshot LogAs user ANANDACREATE SNAPSHOT LOG ON TEST1TABLESPACE USER_DATAWITH PRIMARY KEYINCLUDING NEW VALUES;

19

pr ligence Empowering Intelligence

Create Repl Group

As REPADMIN UserDBMS_REPCAT. CREATE_MASTER_REPGROUP (GNAME=>'TEST1',QUALIFIER=>'',GROUP_COMMENT=>’TEST SNAPSHOT’

);

Group Name

20

pr ligence Empowering Intelligence

Generate Master RepObject

DBMS_REPCAT.CREATE_MASTER_REPOBJECT(GNAME=>'TEST1',

TYPE=>'TABLE', ONAME=>'TEST1', SNAME=>'ANANDA');

Group Name

Table Name

Schema Name

21

pr ligence Empowering Intelligence

Generate Repl Support

DBMS_REPCAT.GENERATE_REPLICATION_SUPPORT(SNAME=>'ANANDA',ONAME=>'TEST1',TYPE=>'TABLE',

MIN_COMMUNICATION=>TRUE);

Schema Name

Object Name

22

pr ligence Empowering Intelligence

Resume Master Activity

DBMS_REPCAT.RESUME_MASTER_ACTIVITY( GNAME=>'TEST1');

Group Name

23

pr ligence Empowering Intelligence

Make the Refresh Group

At Database REPL as user MVADMIN

DBMS_REFRESH.MAKE(NAME=>'MVADMIN.TEST1',NEXT_DATE=>SYSDATE+5/(24*60),INTERVAL=>'SYSDATE+5/(24*60)'

);

Group Name

24

pr ligence Empowering Intelligence

Make the Snapshot Group

At Database REPL as user MVADMIN

DBMS_REPCAT.CREATE_SNAPSHOT_REPGROUP(GNAME=>'TEST1',MASTER=>'PROD',PROPAGATION_MODE=> ‘ASYNCHRONOUS’

);

Group Name

Master Database

25

pr ligence Empowering Intelligence

Create the Snapshot

At Database REPL as user ANANDA

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

26

pr ligence Empowering Intelligence

Add Snapshot to Group

At Database REPL as user ANANDA

DBMS_REFRESH.ADD (NAME=>'MVADMIN.TEST1',LIST=>'ANANDA.TEST1'

);

Group Name

Object Name

27

pr ligence Empowering Intelligence

Generate Repl Support

At Database REPL as user MVADMIN

DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(

GNAME =>'TEST1',SNAME =>'ANANDA',ONAME =>'TEST1',TYPE =>'SNAPSHOT'

)

Group Name

Schema Name

Object Name

28

pr ligence Empowering Intelligence

Most Expensive

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

29

pr ligence Empowering Intelligence

Prebuilt Table

PROD

TEST1

SNAPSHOTLOGS

TEST1

EXPORT/IMPORT

SQL*LOADER DIRECT PATH

DIRECT PATH INSERT

CREATE TABLE AS SELECT

REPL

SNAPSHOTLOGS

SNAPSHOT

FAST REFRESH

30

pr ligence Empowering Intelligence

Usual Method

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

31

pr ligence Empowering Intelligence

Prebuilt Table

CREATE SNAPSHOT TEST1ON PREBUILT TABLEREFRESH FASTASSELECT * FROM TEST1@PROD

32

pr ligence Empowering Intelligence

Needed Changes

• Add a column COL3 CHAR(1)• Modify column COL2 CHAR(1000)

As user ANANDA in PROD Database

ALTER TABLE TEST1 ADD (COL3 CHAR(1);

ALTER TABLE TEST1 MODIFY (COL2 CHAR(1000));

33

pr ligence Empowering Intelligence

Snapshot on Prebuilt Table

TEST1TABLE

SNAPSHOT

TEST1 is a TABLECREATE SNASPSHOT TEST1

ON PREBUILT TABLEAS ….

DROP SNASPHOT TEST1TEST1 is a TABLE again!

34

pr ligence Empowering Intelligence

SNAPSHOT IS CREATED ON

PREBUILT TABLE

SNAPSHOT IS DROPPED

COL3 IS ADDED TO THE TABLE

SNAPSHOT IS RECREATED ON

THE TABLE

Segment State

COL1 CHAR(1)COL2 CHAR(1)

SNAPSHOT

ROW3

ROW2

ROW1

TEST1

COL3 CHAR(1)

SNAPSHOT

35

pr ligence Empowering Intelligence

Segment State Analysis

• Snapshot is Dropped• Segment Reverts to Table• Column Is Added• Snapshot is Recreated• Segment Becomes Snapshot

TIM

E

The state of the segment, i.e. the data is the same

at these two points intime; only the additional

column is different.

Therefore, a FULL Refresh Is NOT Needed!

36

pr ligence Empowering Intelligence

Stop Any Refresh

SELECT JOB FROM USER_REFRESH WHERE RNAME = 'TEST1';

EXEC DBMS_JOB.BROKEN(<JOBNUMBER>,TRUE);

COMMIT;SELECT SID FROM

DBA_JOBS_RUNNINGWHERE JOB = <JOBNUMBER>;

37

pr ligence Empowering Intelligence

Add the Columns

DROP SNAPSHOT TEST1;Snapshot dropped; Table remains

ALTER TABLE TEST1 ADD (COL4 CHAR(1);

ALTER TABLE TEST1 MODIFY (COL3 CHAR(1000));

38

pr ligence Empowering Intelligence

Potential Problem

When a SNAPSHOT is Created on a Master Table, the Snashot Logs Entries are Erased

Need to Capture Snapshot Log EntriesMLOG$_<first 20 Chars of Table Name>

Table Name:THIS_IS_A_LONG_TABLE_NAME

Snap Log Name: MLOG$_THIS_IS_A_LONG_TABLE

39

pr ligence Empowering Intelligence

Preserve the LogAs User ANANDACOL PART_TAB_NAME NOPRINT NEW_VALUE PART_TAB_VALSELECT SUBSTR(‘&TABNAME',1,20) PART_TAB_NAMEFROM DUAL/DROP TABLE MLOG_BAK/CREATE TABLE MLOG_BAKASSELECT * FROM MLOG$_&&PART_TAB_VAL.@PROD/

Table to Preserve

Snapshot Log

40

pr ligence Empowering Intelligence

Recreate the Snapshot

• Build the Snapshot• Add the Snapshot to the Refresh Group• Build Replication Support for the Group

41

pr ligence Empowering Intelligence

Snapshot Log Table

Reinstate the Log Entries

INSERT INTO MLOG$_&&PART_TAB_VAL.@PROD

SELECT * FROM MLOG_BAK/COMMIT/

Table We Preserved the Snapshot Logs In

42

pr ligence Empowering Intelligence

Test the Refresh

• Do a Fast Refreshexecute dbms_snapshot.refresh('TEST1','F')

• Re-run the Jobexecute dbms_job.run(<jobnumber>)

43

pr ligence Empowering Intelligence

Dare to Compare?Elapsed Time

USUAL APPROACH RECOMMENDED APPROACH

•1m•1m•5m•10 hr•1m•1m

•1m

•5m•1m

•Drop the Snapshot and Table•Add Columns in Master•NO NEED•Recreate the Table•Build the Snapshot•Add the Snapshot to the Refresh Group•Build Replication Support for the Group•NO NEED•Check Refresh

•Drop the Snapshot•Add Columns in Master•Preserve Snapshot Logs •NO NEED•Build the Snapshot•Add the Snapshot to the Refresh Group•Build Replication Support for the Group•Reinstate Logs•Check Refresh

10 hours6 minutes

16 minutes

44

pr ligence Empowering Intelligence

Conclusion

• Elapsed Time Reduced As Much As 99%• Resource Utilization Low• All Processes Supported by Oracle• No Data Dictionary Manipluation, No Underscore

Parameters

pr ligence Empowering Intelligence45

Thank You!

Painless Master Table Alter In Replication

Paper # 524by Arup Nanda

www.proligence.cowww.proligence.comm