+ All Categories
Home > Documents > Painless Master Table Alter In Replication Paper # 524

Painless Master Table Alter In Replication Paper # 524

Date post: 10-Jan-2016
Category:
Upload: jarah
View: 30 times
Download: 0 times
Share this document with a friend
Description:
Painless Master Table Alter In Replication Paper # 524. Arup Nanda. pr. ligence. Empowering Intelligence. Question. Two Most Important Objectives of Living Organisms Surviving Reproducing!. Replication Options Revisited. MASTER. COPY. Primary. Secondary. Multi-Master. MASTER. COPY. - PowerPoint PPT Presentation
45
1 pr ligence Empowering Intelligence Painless Master Table Alter In Replication Paper # 524 Arup Nanda pr ligence Empowering Intelligence
Transcript
Page 1: Painless Master Table Alter In Replication Paper # 524

1

pr ligence Empowering Intelligence

Painless Master Table Alter In Replication

Paper # 524

Arup Nandapr ligence

Empowering Intelligence

Page 2: Painless Master Table Alter In Replication Paper # 524

2

pr ligence Empowering Intelligence

Question

Two Most Important Objectives of Living Organisms

Surviving

Reproducing!

Page 3: Painless Master Table Alter In Replication Paper # 524

3

pr ligence Empowering Intelligence

Replication Options Revisited

MASTER COPY

Page 4: Painless Master Table Alter In Replication Paper # 524

4

pr ligence Empowering Intelligence

Multi-Master

MASTER COPY

TriggerTrigger

SnapshotLogs

ROW1 ROW1

pushROW2

TriggerTrigger

SnapshotLogs

ROW2

Primary Secondary

Page 5: Painless Master Table Alter In Replication Paper # 524

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

Page 6: Painless Master Table Alter In Replication Paper # 524

6

pr ligence Empowering Intelligence

Multi-Master contd.

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

Disadvantages

Page 7: Painless Master Table Alter In Replication Paper # 524

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

Page 8: Painless Master Table Alter In Replication Paper # 524

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 _

Page 9: Painless Master Table Alter In Replication Paper # 524

9

pr ligence Empowering Intelligence

Updateable Snapshots contd.

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

Page 10: Painless Master Table Alter In Replication Paper # 524

10

pr ligence Empowering Intelligence

Read Only Snapshot

MASTER SNAPSHOT

TriggerTrigger

SnapshotLogs

ROW1 ROW1

pull

Primary Secondary

Page 11: Painless Master Table Alter In Replication Paper # 524

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 _

Page 12: Painless Master Table Alter In Replication Paper # 524

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

Page 13: Painless Master Table Alter In Replication Paper # 524

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

Page 14: Painless Master Table Alter In Replication Paper # 524

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

Page 15: Painless Master Table Alter In Replication Paper # 524

15

pr ligence Empowering Intelligence

Documented Process

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

Page 16: Painless Master Table Alter In Replication Paper # 524

16

pr ligence Empowering Intelligence

Problem

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

Page 17: Painless Master Table Alter In Replication Paper # 524

17

pr ligence Empowering Intelligence

Database Example

• Schema Owner : ANANDA• Table TEST1

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

Page 18: Painless Master Table Alter In Replication Paper # 524

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;

Page 19: Painless Master Table Alter In Replication Paper # 524

19

pr ligence Empowering Intelligence

Create Repl Group

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

);

Group Name

Page 20: Painless Master Table Alter In Replication Paper # 524

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

Page 21: Painless Master Table Alter In Replication Paper # 524

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

Page 22: Painless Master Table Alter In Replication Paper # 524

22

pr ligence Empowering Intelligence

Resume Master Activity

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

Group Name

Page 23: Painless Master Table Alter In Replication Paper # 524

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

Page 24: Painless Master Table Alter In Replication Paper # 524

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

Page 25: Painless Master Table Alter In Replication Paper # 524

25

pr ligence Empowering Intelligence

Create the Snapshot

At Database REPL as user ANANDA

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

Page 26: Painless Master Table Alter In Replication Paper # 524

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

Page 27: Painless Master Table Alter In Replication Paper # 524

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

Page 28: Painless Master Table Alter In Replication Paper # 524

28

pr ligence Empowering Intelligence

Most Expensive

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

Page 29: Painless Master Table Alter In Replication Paper # 524

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

Page 30: Painless Master Table Alter In Replication Paper # 524

30

pr ligence Empowering Intelligence

Usual Method

CREATE SNAPSHOT TEST1REFRESH FASTASSELECT * FROM TEST1@PROD

Page 31: Painless Master Table Alter In Replication Paper # 524

31

pr ligence Empowering Intelligence

Prebuilt Table

CREATE SNAPSHOT TEST1ON PREBUILT TABLEREFRESH FASTASSELECT * FROM TEST1@PROD

Page 32: Painless Master Table Alter In Replication Paper # 524

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));

Page 33: Painless Master Table Alter In Replication Paper # 524

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!

Page 34: Painless Master Table Alter In Replication Paper # 524

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

Page 35: Painless Master Table Alter In Replication Paper # 524

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!

Page 36: Painless Master Table Alter In Replication Paper # 524

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>;

Page 37: Painless Master Table Alter In Replication Paper # 524

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));

Page 38: Painless Master Table Alter In Replication Paper # 524

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

Page 39: Painless Master Table Alter In Replication Paper # 524

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

Page 40: Painless Master Table Alter In Replication Paper # 524

40

pr ligence Empowering Intelligence

Recreate the Snapshot

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

Page 41: Painless Master Table Alter In Replication Paper # 524

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

Page 42: Painless Master Table Alter In Replication Paper # 524

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>)

Page 43: Painless Master Table Alter In Replication Paper # 524

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

Page 44: Painless Master Table Alter In Replication Paper # 524

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

Page 45: Painless Master Table Alter In Replication Paper # 524

pr ligence Empowering Intelligence45

Thank You!

Painless Master Table Alter In Replication

Paper # 524by Arup Nanda

www.proligence.cowww.proligence.comm


Recommended