dbi servicesEdition Based Redefinition                           Jérôme Witt                           Consultant - Oracle...
Edition Based RedefinitionAgenda                  Agenda                  i.       Introduction                  ii.      ...
Edition Based RedefinitionIntroduction Upgrading applications can be difficult Short or long downtimes can not be schedu...
Edition Based Redefinition       Introduction                             • Creation of new objectsApplication upgrade    ...
Edition Based RedefinitionAgenda                  Agenda                  i.       Introduction                  ii.      ...
Edition Based RedefinitionConcept(1) As of Oracle 11gR2 an object is identified by     His name and the schema it belong...
Edition Based RedefinitionConcept (2) Which objects are “editionable” ?      SYNONYM              All PL/SQL objects   ...
Edition Based RedefinitionConcept(3) Editions are organized hierarchically «parent-child»    ORA$BASE                  ED...
Edition Based RedefinitionConcept(4) Editions are organized hierarchically «parent-child»    ORA$BASE                  ED...
Edition Based RedefinitionAgenda                   Agenda                   i.       Introduction                   ii.   ...
Edition Based RedefinitionBasics (1) Creating editions      Database default edition «ORA$BASE»          Database creat...
Edition Based RedefinitionBasics (2) Granting editions     SQL> GRANT USE ON EDITION <ed_name> TO <schema>; Selecting ed...
Edition Based RedefinitionBasics (3) Enabling an edition database wide     SQL> ALTER DATABASE DEFAULT EDITION=<ed_name>;...
Edition Based RedefinitionBasics (4) Display all database editions      Views {DBA|ALL}_EDITIONS Display all objects ed...
Edition Based RedefinitionAgenda                   Agenda                   i.       Introduction                   ii.   ...
Edition Based RedefinitionRedefining objects(1)     SQL> BEGIN            raiseSalary(                p_title_in   => COM_...
Edition Based Redefinition Redefining objects(2)PROCEDURE raiseSalary(. . .) IS  . . .  CURSOR cur_emp IS SELECT * FROM EM...
Edition Based Redefinition Redefining objects(3)PROCEDURE raiseSalary(. . .) IS  . . .  CURSOR cur_emp IS    SELECT e.empl...
Edition Based RedefinitionRedefining objects(3) Typical EBR redefinition steps     1. Create the new edition     2. Set t...
Edition Based RedefinitionRedefining objects(4)20   www.dbi-services.com    08.11.2012 © dbi services
Edition Based RedefinitionAgenda                   Agenda                   i.       Introduction                   ii.   ...
Edition Based RedefinitionAdvanced functionalities(1) Views      Editionable (of course)      Support only INSTEAD OF t...
Edition Based RedefinitionAdvanced functionalities(2) Crossedition triggers      Propagate data changes made by the old ...
Edition Based RedefinitionAdvanced functionalities(3)                              New Edition : ED_V1          C_Pool    ...
Edition Based RedefinitionAdvanced functionalities(4)                                                  ED_V2              ...
Edition Based RedefinitionAdvanced functionalities(5)                                    New Edition : ED_V2          C_Po...
Edition Based RedefinitionAdvanced functionalities(2) Hot roll-over “bulk forward”      Wait for pending DMLs     DBMS_U...
Edition Based RedefinitionAgenda                   Agenda                   i.       Introduction                   ii.   ...
Edition Based RedefinitionLimits Performance & Tuning      Indexes & constraints must be added to the base table      T...
dbi servicesAny Questions? Please Do Ask!                            Jérôme Witt                            Consultant - O...
Upcoming SlideShare
Loading in …5
×

Tune my Code! Code-Versionen testen via Edition-Based Redef. - Jérôme Witt, dbi services

636 views

Published on

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Tune my Code! Code-Versionen testen via Edition-Based Redef. - Jérôme Witt, dbi services

  1. 1. dbi servicesEdition Based Redefinition Jérôme Witt Consultant - Oracle Certified Professional 11g Mobile +41 79 961 27 73 jerome.witt@dbi-services.com www.dbi-services.com1 www.dbi-services.com 08.11.2012 © dbi services
  2. 2. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits2 www.dbi-services.com 08.11.2012 © dbi services
  3. 3. Edition Based RedefinitionIntroduction 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 20093 www.dbi-services.com 08.11.2012 © dbi services
  4. 4. Edition Based Redefinition Introduction • Creation of new objectsApplication upgrade • Changing objects (alter and create or replace) • Drop redundant objects Downtime EBR • Convert or migrate data • Resume normal operations 4 www.dbi-services.com 08.11.2012 © dbi services
  5. 5. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits5 www.dbi-services.com 08.11.2012 © dbi services
  6. 6. Edition Based RedefinitionConcept(1) As of Oracle 11gR2 an object is identified by  His name and the schema it belongs to  And now also to an EDITION SQL> desc DBA_OBJECTS Name Null? Type ------------------ -------- ---------------- . . . EDITION_NAME VARCHAR2(30) Allows to support several copies of an object  Objects which might have copies are called “editioned objects” All other objects are “non editionable”6 www.dbi-services.com 08.11.2012 © dbi services
  7. 7. Edition Based RedefinitionConcept (2) Which objects are “editionable” ?  SYNONYM  All PL/SQL objects  VIEW  PACKAGE and PACKAGE BODY  PROCEDURE  FUNCTION  LIBRARY  TRIGGER  TYPE and TYPE BODY A non-editonable object cannot depend on an editonable object7 www.dbi-services.com 08.11.2012 © dbi services
  8. 8. Edition Based RedefinitionConcept(3) Editions are organized hierarchically «parent-child» ORA$BASE ED1 ED2 ED3 • OBJ_1 • OBJ_1 • OBJ_2 • OBJ_2 • OBJ_3 • OBJ_3 ED28 www.dbi-services.com 08.11.2012 © dbi services
  9. 9. Edition Based RedefinitionConcept(4) Editions are organized hierarchically «parent-child» ORA$BASE ED1 ED2 ED3 • OBJ_1 • OBJ_1 • OBJ_2 • OBJ_2 • OBJ_3 • OBJ_3 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”9 www.dbi-services.com 08.11.2012 © dbi services
  10. 10. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits10 www.dbi-services.com 08.11.2012 © dbi services
  11. 11. Edition Based RedefinitionBasics (1) Creating editions  Database default edition «ORA$BASE»  Database creation or upgrade to Oracle 11.2  Has no actual editioned objects SQL> CREATE EDITION <ed_name> {AS CHILD OF ora$base}; Enabling editions SQL> ALTER USER <schema> ENABLE EDITIONS {FORCE};  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 !11 www.dbi-services.com 08.11.2012 © dbi services
  12. 12. Edition Based RedefinitionBasics (2) Granting editions SQL> GRANT USE ON EDITION <ed_name> TO <schema>; Selecting editions SQL> ALTER SESSION SET EDITION =<ed_name>; Retrieving current and session edition SQL> SHOW EDITION; SQL> SELECT SYS_CONTEXT(USERENV, CURRENT_EDITION_NAME), SYS_CONTEXT(USERENV, SESSION_EDITION_NAME) FROM dual;12 www.dbi-services.com 08.11.2012 © dbi services
  13. 13. Edition Based RedefinitionBasics (3) Enabling an edition database wide SQL> ALTER DATABASE DEFAULT EDITION=<ed_name>; SQL> SELECT property_value FROM database_properties WHERE property_name = DEFAULT_EDITION; Selecting edition at connection time DBMS_SERVICE.CREATE_SERVICE( service_name => <ORACLE_SID.DB_DOMAIN>, . . . edition => <ed_name>); EBR integrated with  Oracle Call Interface  JDBC  Oracle Restart (srvctl)13 www.dbi-services.com 08.11.2012 © dbi services
  14. 14. Edition Based RedefinitionBasics (4) 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 …14 www.dbi-services.com 08.11.2012 © dbi services
  15. 15. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits15 www.dbi-services.com 08.11.2012 © dbi services
  16. 16. Edition Based RedefinitionRedefining objects(1) SQL> BEGIN raiseSalary( p_title_in => COM_DBISERVICES . . . , p_rate_in => 1.10, p_max_sal_in => 50000 ); END; /16 www.dbi-services.com 08.11.2012 © dbi services
  17. 17. Edition Based Redefinition Redefining objects(2)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; 17 www.dbi-services.com 08.11.2012 © dbi services
  18. 18. Edition Based Redefinition Redefining objects(3)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; 18 www.dbi-services.com 08.11.2012 © dbi services
  19. 19. Edition Based RedefinitionRedefining objects(3) 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 strategy19 www.dbi-services.com 08.11.2012 © dbi services
  20. 20. Edition Based RedefinitionRedefining objects(4)20 www.dbi-services.com 08.11.2012 © dbi services
  21. 21. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits21 www.dbi-services.com 08.11.2012 © dbi services
  22. 22. Edition Based RedefinitionAdvanced functionalities(1) 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) SQL> CREATE EDITIONING VIEW <name> AS SELECT ...;22 www.dbi-services.com 08.11.2012 © dbi services
  23. 23. Edition Based RedefinitionAdvanced functionalities(2) 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! SQL> CREATE OR REPLACE TRIGGER <trigger_name> BEFORE INSERT OR UPDATE ON <table_name> FOR EACH ROW FORWARD CROSSEDITION DISABLE BEGIN . . . END <trigger_name>; /23 www.dbi-services.com 08.11.2012 © dbi services
  24. 24. Edition Based RedefinitionAdvanced functionalities(3) New Edition : ED_V1 C_Pool ED_V1 EMPLOYEES First Last Phone Name Name Nbr EMPLOYEES_TAB EMPLOYEES First Last Phone Name Name Nbr24 www.dbi-services.com 08.11.2012 © dbi services
  25. 25. Edition Based RedefinitionAdvanced functionalities(4) ED_V2 New Edition : ED_V1 C_Pool ED_V1 EMPLOYEES EMPLOYEES First First Phone Last Last Phone Dial Int Name Name Name Name Nbr Nbr PhNbr Code FWD_TRG REV_TRG EMPLOYEES_TAB EMPLOYEES_TAB First First Phone Last Last Phone Int Dial Name Name Nbr Name Name Code Nbr PhNbr25 www.dbi-services.com 08.11.2012 © dbi services
  26. 26. Edition Based RedefinitionAdvanced functionalities(5) New Edition : ED_V2 C_Pool ED_V1 EMPLOYEES First Last Phone Dial Int Name Name Nbr Code PhNbr FWD_TRG REV_TRG EMPLOYEES_TAB C_Pool ED_V2 First Last Phone Dial Int Name Name Nbr Code PhNbr26 www.dbi-services.com 08.11.2012 © dbi services
  27. 27. Edition Based RedefinitionAdvanced functionalities(2) Hot roll-over “bulk forward”  Wait for pending DMLs DBMS_UTILITY.WAIT_ON_PENDING_DML( tables => <Base_Table>, timeout => timeout, scn => scn );  Apply transformation DBMS_SQL.PARSE( c => c, Language_Flag => DBMS_SQL.NATIVE, Statement=> UPDATE employees SET ID = ID, Apply_Crossedition_Trigger => <CRED_TRG_FWD> );27 www.dbi-services.com 08.11.2012 © dbi services
  28. 28. Edition Based RedefinitionAgenda Agenda i. Introduction ii. Concept iii. Basics iv. Redefining objects v. Advanced functionalities vi. Limits28 www.dbi-services.com 08.11.2012 © dbi services
  29. 29. Edition Based RedefinitionLimits 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 SQL> SELECT /*+ INDEX (edview1 idx1)*/ email FROM edview1 WHERE last_name=King; Can not drop retired editions!  Bugs (11.2.0.3) – do not drop edition ORA$BASE One of the least known Oracle database feature29 www.dbi-services.com 08.11.2012 © dbi services
  30. 30. dbi servicesAny Questions? Please Do Ask! Jérôme Witt Consultant - Oracle Certified Professional 11g Mobile +41 79 961 27 73 jerome.witt@dbi-services.com www.dbi-services.com „We look forward to working with you!“30 www.dbi-services.com 08.11.2012 © dbi services

×