Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Release 2<br />Release 3<br />Base Release<br />Introducing and Demonstrating Oracle Database 11gR2's Killer FeatureEditio...
The Book Application - Version 1<br />
Application Version 1 on Database Edition Release 2<br />
Database Upgrade Base release to Release 2<br />Authors<br />New columns COUNTRY and BIOGRAPHY<br />Books<br />Drop column...
Application Version 2 (on Database Edition Release 2)<br />
Application Version 2 on Base Edition in the Database<br />
Release 2<br />Base Release<br />ALS Schema<br />
Availability<br />Availability = Performance * (Up or Down)<br />Up = !Down<br />Down = Unplanned Down + Planned Down<br /...
Maximum Availability Architecture<br />
Application Upgrade<br />Creation of new objects<br />Changing existing objects (alter and create or replace)<br />Add, Mo...
Compare with road maintenance<br />
Restructuring A12<br />Build new road next to current one (A12-B)<br />Same “functionality” as the old road<br />At the cu...
11gR2 Editioning is similar<br />Application Upgrade:<br />Prepare new release<br />Construct the release in parallel to t...
11gR2 Editions introduces a new dimension in the database<br />Release 3<br />Release 2<br />Base Release<br />
Editions introduce or inherit versions of objects<br />Release 2<br />Release 3<br />Base Release<br />
Editions are parallel universes<br />Database Objects are identified by<br />Object Type<br />Schema<br />Object Name<br /...
Database sessions run in a specific edition –one version of each object<br />Release 2<br />Release 3<br />Base Release<br...
Release 2<br />Base Release<br />ALS Schema<br />
Parallel Application Versions<br />Application X<br />VERSION 1<br />Application X<br />VERSION 2<br />Release 2<br />Rele...
The end of the big bang<br />After the release of a new edition – there is no reason why you cannot keep the previous one ...
Demo of Database Editions<br />Existing base application, in base edition<br />Create new edition – release_2<br />Create ...
CONNECT SYS/ORACLE as SYSDBA<br />CREATE EDITION release_2;<br />CREATE EDITION release_3 AS CHILD OF release_2;<br />SELE...
Some Rules for EBR (Edition Based Redefinition)<br />EBR acts on packages, functions, triggers, procedures, views, types a...
Editions and Tables<br />Tables cannot be versioned: there is only one definition of a table across all Editions<br />Data...
Editions and Tables<br />Application A<br />Application B<br />Table EMP<br />SAL<br />MGR<br />JOB<br />ENAME<br />HIREDA...
Editions and Tables<br />Application A<br />Application B<br />Editioning View EMP <br />Table EMP_BASE<br />SAL<br />MGR<...
Oracle guarantees:The Execution Plan for a SQL query that uses an Editioning View is identical to that for the same query ...
Migrate to Editioning Views<br />Rename Table (for example to <old table name>_BASE)<br />Constraints continue to refer to...
Demo<br />ALTER TABLE EMP RENAME TO EMP_BASE;<br />CREATE OR REPLACE EDITIONING VIEW EMP<br />AS<br />SELECT ...<br />FROM...
Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />Editionin...
Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />View EMP ...
Demo<br />CREATE EDITION R2 AS CHILD OF R1;<br />ALTER SESSION SET EDITION R2;<br />SHOW EDITION<br />ALTER TABLE EMP_BASE...
Demo<br />Rem Create Forward Crossedition Trigger<br />Rem Applies to DML operations on EMP_BASE from <br />Rem Earlier Ed...
Demo<br />Rem Use Forward Crossedition trigger to<br />Rem upgrade existing table records according to new table<br />Rem ...
Upgrade Table Definition<br />Make desired changes to the table<br />Add columns, modify Columns, … (online redefinition)<...
Cross Edition Triggers<br />If you remove a (mandatory) column from the current Editioning View…<br />a Reverse Crossediti...
Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R3<br />View EMP (1.1)<br />… (mi...
“Suggested (best) Practices”<br />Every application (release) sets the Edition it requires when it connects to a session<b...
“Suggested (best) Practices”<br />Applications should never access tables – all access should be through views<br />Only t...
Replacement Table Pattern<br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />EditioningView APP_DA...
Alternative Approach for Data Versioning<br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />View D...
Interesting EBR Tid-Bits<br />Drop Object in an Edition stops the inheritance from previous Edition. Object no longer is c...
Interesting EBR Tid-Bits<br />DB Links & Materialized Views currently not editionable<br />Objects of an editionable type ...
Summary<br />11gR2 Editions are parallel, co-existing universes with incarnations of database objects<br />The new release...
Conclusion<br />See our blog for Oracle Database 11gR2 articles (other topics as well)<br />http://technology.amis.nl/blog...
Upcoming SlideShare
Loading in …5
×

Introducing and Demonstrating Oracle Database 11gR2's Killer Feature – Edition- Based Redefinition for Developers and DBAs (ODTUG Kaleidoscope 2010)

2,548 views

Published on

Edition-based redefinition (EBR) in Oracle Database 11g Release 2 is spectacular, introducing a new dimension to the database which allows us to version objects within a schema. Through EBR, we achieve zero-downtime application upgrade and multiple application versions simultaneously against one schema. No more big-bang upgrade! This session introduces EBR, demonstrates the SQL, and shows the multi-version application. It dives into some complexities of data synchronization between editions and discusses best practices with EBR.

Published in: Technology
  • Be the first to comment

Introducing and Demonstrating Oracle Database 11gR2's Killer Feature – Edition- Based Redefinition for Developers and DBAs (ODTUG Kaleidoscope 2010)

  1. 1. Release 2<br />Release 3<br />Base Release<br />Introducing and Demonstrating Oracle Database 11gR2's Killer FeatureEdition- Based Redefinition for Developers and DBAs<br />ODTUG Kaleidoscope 2010<br />Lucas Jellema <br />AMIS, The Netherlands<br />
  2. 2. The Book Application - Version 1<br />
  3. 3. Application Version 1 on Database Edition Release 2<br />
  4. 4. Database Upgrade Base release to Release 2<br />Authors<br />New columns COUNTRY and BIOGRAPHY<br />Books<br />Drop column NUM_OF_PAGES<br />Modified column ISBN (10 to 20 characters)<br />New columns LANGUAGE and PUBLICATION_YEAR<br />
  5. 5. Application Version 2 (on Database Edition Release 2)<br />
  6. 6. Application Version 2 on Base Edition in the Database<br />
  7. 7. Release 2<br />Base Release<br />ALS Schema<br />
  8. 8. Availability<br />Availability = Performance * (Up or Down)<br />Up = !Down<br />Down = Unplanned Down + Planned Down<br />Planned Down???<br />System Maintenance<br />Power-supply, Hardware & Network, O/S upgrade<br />Database patching & Upgrade<br />Application Upgrades<br />
  9. 9. Maximum Availability Architecture<br />
  10. 10. Application Upgrade<br />Creation of new objects<br />Changing existing objects (alter and create or replace)<br />Add, Modify or Drop columns or constraints<br />Change packages and stored procedures<br />Recompile<br />Drop redundant objects<br />Convert or migrate data<br />Resume normal operations<br />Application is DOWN<br />
  11. 11. Compare with road maintenance<br />
  12. 12. Restructuring A12<br />Build new road next to current one (A12-B)<br />Same “functionality” as the old road<br />At the cut-over moment<br />Open new A12-B: <br />Newly arriving traffic travels on temporary road<br />Close A12 (original)<br />Cars already on old road keep going<br />
  13. 13. 11gR2 Editioning is similar<br />Application Upgrade:<br />Prepare new release<br />Construct the release in parallel to the existing<br />Operations in existing application ‘edition’ continue normally<br />From the cut-over point:<br />Have new sessions operate on new release<br />Existing sessions can continue to run on existing release<br />
  14. 14. 11gR2 Editions introduces a new dimension in the database<br />Release 3<br />Release 2<br />Base Release<br />
  15. 15. Editions introduce or inherit versions of objects<br />Release 2<br />Release 3<br />Base Release<br />
  16. 16. Editions are parallel universes<br />Database Objects are identified by<br />Object Type<br />Schema<br />Object Name<br />…. Edition!<br />(release, application version, stripe, parallel universe id)<br />Database Sessions run in the context of a specific edition <br />Using a specific collection of versions of objects<br />
  17. 17. Database sessions run in a specific edition –one version of each object<br />Release 2<br />Release 3<br />Base Release<br />The database as seen by a sessionrunning in the context of Release 3<br />3<br />2<br />3<br />B<br />2<br />2<br />3<br />3<br />2<br />
  18. 18. Release 2<br />Base Release<br />ALS Schema<br />
  19. 19. Parallel Application Versions<br />Application X<br />VERSION 1<br />Application X<br />VERSION 2<br />Release 2<br />Release 3<br />Base Release<br />
  20. 20. The end of the big bang<br />After the release of a new edition – there is no reason why you cannot keep the previous one going for some time<br />And multiple previous ones!<br />That means – END OF THE BIG BANG upgrade!<br />Multiple versions of the application can continue running to support various user groups (e.g. SaaS)<br />Without data migration and additional downtime upon later move over of user groups<br />
  21. 21. Demo of Database Editions<br />Existing base application, in base edition<br />Create new edition – release_2<br />Create and Alter database objects<br />Base application continues running<br />Cut-over point<br />New sessions run in release_2 edition<br />Current sessions continue in base<br />
  22. 22. CONNECT SYS/ORACLE as SYSDBA<br />CREATE EDITION release_2;<br />CREATE EDITION release_3 AS CHILD OF release_2;<br />SELECT * FROM DBA_EDITIONS;<br />CREATE USER SCOTTY identified by tiger;<br />ALTER USER SCOTTY ENABLE EDITIONS FORCE<br />GRANT USE ON EDITION release_2 TO SCOTTY<br />CONNECT SCOTTY/TIGER<br />ALTER SESSION SET EDITION = ORA$BASE<br />CREATE OR REPLACE FUNCTION HELLO_WORLD<br />ALTER SESSION SET EDITION = RELEASE_2<br />CREATE OR REPLACE FUNCTION HELLO_WORLD<br />ALTER SESSION SET EDITION = RELEASE_3<br />DROP FUNCTION HELLO_WORLD<br />Release 2<br />Release 3<br />Base Release<br />2<br />1<br />X<br />
  23. 23. Some Rules for EBR (Edition Based Redefinition)<br />EBR acts on packages, functions, triggers, procedures, views, types and synonyms<br />EBR does not apply to tables<br />Data is not versioned, cloned, migrated<br />Different incarnations of a table are suggested through editioningviews – there is only one table<br />Applications should never access tables directly!<br />
  24. 24. Editions and Tables<br />Tables cannot be versioned: there is only one definition of a table across all Editions<br />Data is not versioned: a record exists once and only once<br />The solution for managing changes to Tables: Editioning Views and Cross Edition Triggers<br />Editioning Views are defined on base table (no joins)<br />Editioning Views can have DML triggers defined (just like base table)<br />Using an editioning view in a query or DML statement does not impact the performance of the query or DML<br />
  25. 25. Editions and Tables<br />Application A<br />Application B<br />Table EMP<br />SAL<br />MGR<br />JOB<br />ENAME<br />HIREDATE<br />COMM<br />
  26. 26. Editions and Tables<br />Application A<br />Application B<br />Editioning View EMP <br />Table EMP_BASE<br />SAL<br />MGR<br />JOB<br />ENAME<br />HIREDATE<br />COMM<br />
  27. 27. Oracle guarantees:The Execution Plan for a SQL query that uses an Editioning View is identical to that for the same query based directly on the table<br />
  28. 28. Migrate to Editioning Views<br />Rename Table (for example to <old table name>_BASE)<br />Constraints continue to refer to the table<br />Create the Editioning View with the old table name<br />Using the ‘CREATE OR REPLACE EDITIONING VIEW <view name>’ statement<br />Reroute privileges – grant on view rather than table<br />Recompile the triggers on the table<br />These now become triggers on the Editioning View<br />Recompile all invalid PL/SQL program units and Views<br />They now refer to the Editioning View instead of the table<br />VPD policies are reassigned to the View<br />Regular auditing and FGA is on the table<br />
  29. 29. Demo<br />ALTER TABLE EMP RENAME TO EMP_BASE;<br />CREATE OR REPLACE EDITIONING VIEW EMP<br />AS<br />SELECT ...<br />FROM EMP_BASE<br />/<br />DROP TRIGGER EMP_BRI<br />/<br />Rem recreate trigger on Editioning View<br />@<EMP_BRI>.trg<br />Rem recompile invalid Views and PL/SQL units<br />
  30. 30. Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />Editioning View EMP <br />Editioning View EMP <br />Table EMP_BASE<br />SAL<br />MGR<br />JOB<br />ENAME<br />HIREDATE<br />COMM<br />
  31. 31. Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />View EMP (1.1)<br />…* Language <br />View EMP (1.0)<br />Table EMP_BASE<br />SAL<br />MGR<br />JOB<br />ENAME<br />LANGUAGE<br />HIREDATE<br />COMM<br />Forward CrosseditionTrigger<br />
  32. 32. Demo<br />CREATE EDITION R2 AS CHILD OF R1;<br />ALTER SESSION SET EDITION R2;<br />SHOW EDITION<br />ALTER TABLE EMP_BASE<br />ADD (LANGUAGE VARCHAR2(2) NULL);<br />Rem function for deriving value for language<br />CREATE OR REPLACE FUNCTION <br />GET_LANGUAGE( p_job in varchar2) return varchar2<br />is<br />begin<br /> return case p_job when 'MANAGER' then 'fr' <br /> else 'en' end;<br />end;<br />
  33. 33. Demo<br />Rem Create Forward Crossedition Trigger<br />Rem Applies to DML operations on EMP_BASE from <br />Rem Earlier Editions<br />CREATE OR REPLACE TRIGGER EMP_1_1_Fwd_Xed<br />BEFORE INSERT OR UPDATE ON EMP_BASE<br />FOR EACH ROW<br />FORWARD CROSSEDITION<br />DISABLE<br />BEGIN <br /> :new.language = get_language(:new.job);<br />END EMP_1_1_Fwd_Xed; <br />Rem Enable the Forward Crossedition Trigger<br />ALTER TRIGGEREMP_1_1_Fwd_Xed ENABLE; <br />
  34. 34. Demo<br />Rem Use Forward Crossedition trigger to<br />Rem upgrade existing table records according to new table<br />Rem version (for large # records use dbms_parallel_execute)<br />DECLARE <br /> c NUMBER := DBMS_SQL.OPEN_CURSOR(); <br /> x NUMBER; <br />BEGIN <br /> DBMS_SQL.PARSE<br /> ( c => c<br /> , Language_Flag => DBMS_SQL.NATIVE<br /> , Statement => 'UPDATE EMP_BASE SET EMPNO = EMPNO'<br />, Apply_Crossedition_Trigger => 'EMP_1_1_Fwd_Xed'<br /> );<br /> x := DBMS_SQL.EXECUTE(c); <br /> DBMS_SQL.CLOSE_CURSOR(c); <br />COMMIT; <br />END;<br />
  35. 35. Upgrade Table Definition<br />Make desired changes to the table<br />Add columns, modify Columns, … (online redefinition)<br />(Create Edition,) Set target Edition for session<br />Modify the Editioning View in the Edition <br />To reflect the table as its latest version should look<br />Perhaps hiding columns you eventually want to drop<br />(optional) Create Forward Crossedition Trigger on base table to have DML on previous Editions made valid<br />(optional) Create Reverse Crossedition Trigger on base table to have DML on current Edition synch back<br />
  36. 36. Cross Edition Triggers<br />If you remove a (mandatory) column from the current Editioning View…<br />a Reverse Crossedition Trigger ensures that new records get some value in that (invisible) column<br />If you add a (mandatory) column to the table (and the current Editioning View)…<br />a Forward Crossedition Trigger ensures that records DMLed through previous Editioning View versions are made valid<br />(optionally) Apply Forward Crossedition Trigger for all existing records (created in old edition of the table)<br />Use DBMS_SQL.parse (with parameter Apply_Crossedition_Trigger set to name of trigger)<br />Use DBMS_PARALLEL_EXECUTE<br />
  37. 37. Multiple versions of Editioning View <br />Application A<br />Application B<br />Edition R3<br />View EMP (1.1)<br />… (minus ENAME)* Language<br />o FIRST_NAME<br />* LAST_NAME<br />Edition R1<br />Edition R2<br />View EMP (1.1)<br />…* Language <br />View EMP (1.0)<br />Table EMP_BASE<br />Reverse Crossedition Trigger<br />SAL<br />MGR<br />JOB<br />ENAME<br />LANGUAGE<br />FIRSTNAME<br />LASTNAME<br />HIREDATE<br />COMM<br />Forward CrosseditionTrigger<br />
  38. 38. “Suggested (best) Practices”<br />Every application (release) sets the Edition it requires when it connects to a session<br />At the same time it calls dbms_application_info<br />And sets other Context details<br />Note: you could use multiple database service definitions to access the same database<br />For example: ORCL_BASE, ORCL_R2, ORCL_R3<br />JEE data sources can be configured for a specific service<br />A logon trigger can read the service name used to connect to the database and set edition accordingly<br />
  39. 39. “Suggested (best) Practices”<br />Applications should never access tables – all access should be through views<br />Only through views can the data structure itself be Editioned<br />Even triggers should be on the EditioningView<br />Except cross edition triggers<br />
  40. 40. Replacement Table Pattern<br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />EditioningView APP_DATA<br />EditioningView APP_DATA<br />Table APPLICATION_METADATA<br />APPLICATION_METADATA_R2<br />ORGID<br />USER<br />VALUE<br />KEY<br />Default<br />ORGID<br />USER<br />VALUE<br />KEY<br />Default<br />
  41. 41. Alternative Approach for Data Versioning<br />Application A<br />Application B<br />Edition R2<br />Edition R1<br />View DATA<br />select *from EDITIONED_DATAwhere <current_edition> betweenas_of_edition anduntil_edition<br />Table EDITIONED_DATA<br />* as_of_edition<br />* until_edition<br />… normal columns<br />
  42. 42. Interesting EBR Tid-Bits<br />Drop Object in an Edition stops the inheritance from previous Edition. Object no longer is carried forward<br />Edition can have only one child – no branches (yet)<br />DBMS_SQL.PARSE can be executed in a specific Edition<br />Use parameter edition to specify other than current edition<br />If no explicit edition is set for a session, the default edition is used<br />ALTER DATABASE DEFAULT EDITION = edition_name; <br />Hints in queries against Editionable Views are understood in terms of the underlying table<br />Logical EV column references are correctly mapped<br />
  43. 43. Interesting EBR Tid-Bits<br />DB Links & Materialized Views currently not editionable<br />Objects of an editionable type are not editionable when used by a non-editionableobject<br />PL/SQL Function used in Function Based Index or the definition of a Materialized View<br />ADT used as the base type for a column in a table<br />Data Dictionary Views<br />DBA_/ALL_EDITIONS – editions in the database<br />DBA_/ALL_OBJECTS – objects (inherited) in current edition<br />DBA_/ALL_OBJECTS_AE – actual objects across all editions<br />
  44. 44. Summary<br />11gR2 Editions are parallel, co-existing universes with incarnations of database objects<br />The new release can be constructed, tested and run in a new edition<br />The old edition can be switched off at cut-over <br />Editions also allow long time co-existence of multiple releases of an application<br />Application Upgrade no longer needs to disrupt the operation through planned downtime<br />By the way: EBR is available in all DB editions<br />
  45. 45. Conclusion<br />See our blog for Oracle Database 11gR2 articles (other topics as well)<br />http://technology.amis.nl/blog<br />This presentation and the demo scripts are on the blog too<br />Contact me: lucas.jellema@amis.nl<br />

×