Upload
dbi-services
View
331
Download
14
Tags:
Embed Size (px)
DESCRIPTION
Mit Edition-Based Redefinition (EBR) können Sie verschiedene Versionen des Applikations-Codes in ein und derselben Datenbank aufbewahren. Wir zeigen Ihnen, wie Sie mittels EBR unterschiedliche Code-Versionen testen können, um die Datenbank-Performance zu analysieren und zu verbessern. EBR erlaubt das Durchführen so genannter Online Application Upgrades: Datenbank-Komponenten können während des laufenden Betriebs der Applikation aktualisiert werden.
Citation preview
© dbi services © dbi services
dbi services
Edition Based Redefinition
www.dbi-services.com 1 08.11.2012
Jérôme Witt
Consultant - Oracle Certified Professional 11g
Mobile +41 79 961 27 73
www.dbi-services.com
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 2 08.11.2012
© dbi services © dbi services
Upgrading applications can be difficult
Short or long downtimes can not be scheduled
Implementation of online upgrades are desirable
As of Oracle Database 11gR2 with Oracle Edition Based Redefinition (aka. EBR) online application upgrades are now supported
Announced as “the killer feature” at the OOW 2009
Edition Based Redefinition
Introduction
www.dbi-services.com 3 08.11.2012
© dbi services © dbi services
• Creation of new objects
• Changing objects (alter and create or replace)
• Drop redundant objects
• Convert or migrate data
• Resume normal operations
Edition Based Redefinition
Introduction
www.dbi-services.com 4 08.11.2012
Ap
pli
cati
on
up
grad
e
Downtime
EBR
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 5 08.11.2012
© dbi services © dbi services
As of Oracle 11gR2 an object is identified by
His name and the schema it belongs to
And now also to an EDITION
Allows to support several copies of an object
Objects which might have copies are called “editioned objects”
All other objects are “non editionable”
Edition Based Redefinition
Concept(1)
www.dbi-services.com 6 08.11.2012
SQL> desc DBA_OBJECTS
Name Null? Type
------------------ -------- ----------------
. . .
EDITION_NAME VARCHAR2(30)
© dbi services © dbi services
Which objects are “editionable” ?
A non-editonable object cannot depend on an editonable object
Edition Based Redefinition
Concept (2)
www.dbi-services.com 7 08.11.2012
SYNONYM VIEW
All PL/SQL objects PACKAGE and PACKAGE BODY PROCEDURE FUNCTION LIBRARY TRIGGER TYPE and TYPE BODY
© dbi services © dbi services
Editions are organized hierarchically
Edition Based Redefinition
Concept(3)
www.dbi-services.com 8 08.11.2012
«parent-child»
ORA$BASE
ED1
• OBJ_1 • OBJ_2 • OBJ_3
ED2
• OBJ_2
ED3
• OBJ_1
• OBJ_3
ED2
© dbi services © dbi services
Editions are organized hierarchically
Inheritance
When an edition is created all objects associated with the parent are inherited by the child. They become «inherited»
Objects re-created or altered in an edition become “actualized” (i.e. objects OBJ_2 & OBJ_3 of the edition ED3)
Inherited & actual objects are “visible”
Edition Based Redefinition
Concept(4)
www.dbi-services.com 9 08.11.2012
«parent-child»
ORA$BASE
ED1
• OBJ_1 • OBJ_2 • OBJ_3
ED2
• OBJ_2
ED3
• OBJ_1
• OBJ_3
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 10 08.11.2012
© dbi services © dbi services
Creating editions
Database default edition «ORA$BASE»
Database creation or upgrade to Oracle 11.2
Has no actual editioned objects
Enabling editions
Editioned objects can only be owned by schemas that have been explicitly enabled
FORCE if schema has potentially editionable objects
By the way DISABLE EDTIONS doesn’t exists !
Edition Based Redefinition
Basics (1)
www.dbi-services.com 11 08.11.2012
SQL> ALTER USER <schema> ENABLE EDITIONS {FORCE};
SQL> CREATE EDITION <ed_name> {AS CHILD OF ora$base};
© dbi services © dbi services
Granting editions
Selecting editions
Retrieving current and session edition
Edition Based Redefinition
Basics (2)
www.dbi-services.com 12 08.11.2012
SQL> GRANT USE ON EDITION <ed_name> TO <schema>;
SQL> ALTER SESSION SET EDITION =<ed_name>;
SQL> SHOW EDITION;
SQL> SELECT
SYS_CONTEXT('USERENV', 'CURRENT_EDITION_NAME'),
SYS_CONTEXT('USERENV', 'SESSION_EDITION_NAME')
FROM dual;
© dbi services © dbi services
Enabling an edition database wide
Selecting edition at connection time
EBR integrated with
Oracle Call Interface
Oracle Restart (srvctl)
Edition Based Redefinition
Basics (3)
www.dbi-services.com 13 08.11.2012
SQL> ALTER DATABASE DEFAULT EDITION=<ed_name>;
SQL> SELECT property_value FROM database_properties
WHERE property_name = 'DEFAULT_EDITION';
DBMS_SERVICE.CREATE_SERVICE(
service_name => '<ORACLE_SID.DB_DOMAIN>',
. . .
edition => '<ed_name>');
JDBC
© dbi services © dbi services
Display all database editions
Views {DBA|ALL}_EDITIONS
Display all objects editions
Views {DBA|ALL|USER}_OBJECTS_AE
View current edition from an object
Views {DBA|ALL|USER}_OBJECTS.EDITION_NAME
And so on …
Edition Based Redefinition
Basics (4)
www.dbi-services.com 14 08.11.2012
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 15 08.11.2012
© dbi services © dbi services
Edition Based Redefinition
Redefining objects(1)
www.dbi-services.com 16 08.11.2012
SQL> BEGIN
raiseSalary(
p_title_in => 'COM_DBISERVICES . . . ',
p_rate_in => 1.10,
p_max_sal_in => 50000 );
END;
/
© dbi services © dbi services
Edition Based Redefinition
Redefining objects(2)
www.dbi-services.com 17 08.11.2012
PROCEDURE raiseSalary(. . .) IS
. . .
CURSOR cur_emp IS SELECT * FROM EMPLOYEES FOR UPDATE;
BEGIN
OPEN cur_emp;
LOOP
FETCH cur_emp INTO rec_emp;
. . .
SELECT upper(job_title) INTO v_cur_title FROM hr.jobs
WHERE job_id = rec_emp.job_id;
IF v_cur_title = v_title_in
AND rec_emp.salary*p_rate_in <= p_max_sal_in
THEN
-- Do some other checks on employee
UPDATE . . .
END IF;
END LOOP;
CLOSE cur_emp;
COMMIT;
END;
© dbi services © dbi services
Edition Based Redefinition
Redefining objects(3)
www.dbi-services.com 18 08.11.2012
PROCEDURE raiseSalary(. . .) IS
. . .
CURSOR cur_emp IS
SELECT e.employee_id from hr.employees e, hr.jobs j
WHERE e.job_id = j.job_id AND upper(j.job_title) = v_title_in
AND e.salary*p_rate_in <= p_max_sal_in;
BEGIN
OPEN cur_emp;
LOOP
FETCH cur_emp BULK COLLECT INTO v_empid_list LIMIT 1000;
EXIT WHEN v_empid_list.COUNT = 0;
-- Do some other checks on employee
FORALL i IN v_empid_list.FIRST .. v_empid_list.LAST
UPDATE hr.employees SET salary=salary*p_rate_in
WHERE employee_id=v_empid_list(i);
END LOOP;
CLOSE cur_emp; COMMIT;
END;
© dbi services © dbi services
Typical EBR redefinition steps
1. Create the new edition
2. Set the edition as session edition
3. Redefine the objects
4. Permanently switch to the new edition
To “redefine” objects it’s necessary to select the new edition and either re-compile or recreate objects
Consider application roll out strategy
Edition Based Redefinition
Redefining objects(3)
www.dbi-services.com 19 08.11.2012
© dbi services © dbi services
Edition Based Redefinition
Redefining objects(4)
www.dbi-services.com 20 08.11.2012
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 21 08.11.2012
© dbi services © dbi services
Views
Editionable (of course)
Support only INSTEAD OF triggers
Editioning views
Selects a subset of the columns from a single base table
Optionally, provide aliases for columns
Doesn’t support indexes nor constraints
No performance penalty for accessing base table
Support any type of triggers (especially CROSSEDITION TRIGGERS)
Edition Based Redefinition
Advanced functionalities(1)
www.dbi-services.com 22 08.11.2012
SQL> CREATE EDITIONING VIEW <name> AS SELECT ...;
© dbi services © dbi services
Crossedition triggers
Propagate data changes made by the old edition into the new edition’s columns, or vice-versa.
From type FORWARD or REVERSE
They are temporary!
Edition Based Redefinition
Advanced functionalities(2)
www.dbi-services.com 23 08.11.2012
SQL> CREATE OR REPLACE TRIGGER <trigger_name>
BEFORE INSERT OR UPDATE ON <table_name>
FOR EACH ROW
FORWARD CROSSEDITION
DISABLE
BEGIN
. . .
END <trigger_name>;
/
© dbi services © dbi services
Edition Based Redefinition
Advanced functionalities(3)
www.dbi-services.com 24 08.11.2012
C_Pool ED_V1
EMPLOYEES_TAB
First Name
Last Name
Phone Nbr
EMPLOYEES
First Name
Last Name
Phone Nbr
EMPLOYEES
First Name
Last Name
Phone Nbr
New Edition : ED_V1
© dbi services © dbi services
EMPLOYEES
First Name
Last Name
Phone Nbr
Edition Based Redefinition
Advanced functionalities(4)
www.dbi-services.com 25 08.11.2012
C_Pool ED_V1
New Edition : ED_V1 New Edition : ED_V2
FWD_TRG
REV_TRG
EMPLOYEES_TAB
First Name
Last Name
Phone Nbr
EMPLOYEES_TAB
First Name
Last Name
Phone Nbr
Dial Code
Int PhNbr
EMPLOYEES
First Name
Last Name
Phone Nbr
Dial Code
Int PhNbr
© dbi services © dbi services
Edition Based Redefinition
Advanced functionalities(5)
www.dbi-services.com 26 08.11.2012
C_Pool ED_V1
EMPLOYEES_TAB
First Name
Last Name
Phone Nbr
Dial Code
Int PhNbr
EMPLOYEES
First Name
Last Name
Phone Nbr
Dial Code
Int PhNbr
C_Pool ED_V2
FWD_TRG
REV_TRG
New Edition : ED_V2
© dbi services © dbi services
Hot roll-over “bulk forward”
Wait for pending DMLs
Apply transformation
Edition Based Redefinition
Advanced functionalities(2)
www.dbi-services.com 27 08.11.2012
DBMS_UTILITY.WAIT_ON_PENDING_DML(
tables => '<Base_Table>',
timeout => timeout,
scn => scn
);
DBMS_SQL.PARSE(
c => c,
Language_Flag => DBMS_SQL.NATIVE,
Statement=> 'UPDATE employees SET ID = ID',
Apply_Crossedition_Trigger => '<CRED_TRG_FWD>'
);
© dbi services © dbi services
Agenda Agenda
Edition Based Redefinition
Agenda
i. Introduction
ii. Concept
iii. Basics
iv. Redefining objects
v. Advanced functionalities
vi. Limits
www.dbi-services.com 28 08.11.2012
© dbi services © dbi services
Performance & Tuning
Indexes & constraints must be added to the base table
To limit negative performance impact specify an INDEX hint within the crossedition triggers
Editioning views accept SQL optimizer hints
Logical column names must be mapped to an index on the corresponding physical column in the base table
Can not drop retired editions!
Bugs (11.2.0.3) – do not drop edition ORA$BASE
One of the least known Oracle database feature
Edition Based Redefinition
Limits
www.dbi-services.com 29 08.11.2012
SQL> SELECT /*+ INDEX (edview1 idx1)*/ email
FROM edview1 WHERE last_name='King';
© dbi services © dbi services
dbi services
Any Questions? Please Do Ask!
www.dbi-services.com 30 08.11.2012
„We look forward to working with you!“
Jérôme Witt
Consultant - Oracle Certified Professional 11g
Mobile +41 79 961 27 73
www.dbi-services.com