Tales from a Parallel Universe:Using 11gR2’s Edition Based Redefinitions (in APEX)<br />Roel Hartman<br />
EBR and APEX?<br />Sorry, you can’t do it...<br />Questions?<br />John’s suggestion....<br />
Who am I?<br /><ul><li>Oracle since v5, Forms 2.3, Case*Designer etc
Presenter at UKOUG (3x), OOW (3x), ODTUG (2x)</li></ul>roelhartman.blogspot.com<br />No. 3<br />
Tom Kytesays:<br />
Unplanned Downtime<br />Physical Standby Database<br />Logical Standby Database<br />RAC<br />The Case<br />
Unplanned Downtime<br />
Planned Downtime<br />Database Upgrade<br />Streams<br />Rolling Upgrade using Logical Standby Database<br />Application M...
Planned Downtime<br />
Planned Downtime <br />Application Upgrade<br />Create objects<br />Replace objects<br />Drop objects<br />Recompilation<b...
Keep the Shop open<br />Prepare new Release <br />Cut over<br />Randall<br />Version 2<br />2<br />Boo<br />1<br />Version...
Edition<br />Schema<br />Object Type<br />Object Name<br />Session runs in the context of an Edition<br />Parallel Univers...
SQL>ALTER USER HR ENABLE EDITIONS;<br />USER ALTERED.<br />SQL> ALTER USER HR DISABLE EDITIONS;<br />ALTER USER HR DISABLE...
SQL> select * from all_editions;<br />EDITION_NAME PARENT_EDITION_NAME USA<br />------------ ------------------- ---<br />...
SQL> CREATE EDITION HR_RELEASE2 AS CHILD OF ORA$BASE;<br />Edition created.<br />SQL> CREATE EDITION OE_RELEASE2 AS CHILD ...
ORA$BASE<br />HR<br />OE<br />HR_RELEASE2<br />HR’<br />OE_RELEASE2<br />OE’<br />One Child – One Parent<br />
Editionable<br />PL/SQL Objects<br />Packages<br />Procedures<br />Functions<br />Triggers<br />Views<br />Synonyms<br />T...
Table X<br />Table Y<br />ORA$BASE<br />PL/SQL (A)<br />PL/SQL (B)<br />HR_RELEASE2<br />PL/SQL (A)<br />PL/SQL (B)<br />P...
“Instead-of-table”<br />Only one table in the from clause<br />No expressions, only columns<br />Can have “regular” table ...
Editioning View<br />Data is the same<br />View is different<br />Depends on your position / edition<br />
Table X_t<br />Table Y_t<br />ORA$BASE<br />Editioning View X<br />Editioning View Y<br />PL/SQL (A)<br />PL/SQL (B)<br />...
Old situation : One column NAME<br />New situation : FIRST_NAME / LAST_NAME<br />Cross Edition Triggers<br />Forward<br />...
Cross Edition Triggers<br />NAME<br />FIRST_NAME<br />LAST_NAME<br />“split”<br />“concat”<br />RELEASE 2<br />ORA$BASE<br...
Chain of forward / reverse Xedition triggers in decendent / ancestor editions<br />Forward Xedition DML fires Forward Xedi...
Forward Xedition isn’t fired in own edition<br />Fill FIRST_NAME / LAST_NAME from NAME<br />Fire the Xedition trigger only...
Apply changes - 2<br />CREATE OR REPLACE TRIGGER trigger1 BEFORE INSERT OR UPDATE ON table1<br />  FOR EACH ROW CROSSEDITI...
Rename your Tables<br />Create Editioning Views<br />Reroute Privileges<br />Recreate Triggers<br />Recompile all PL/SQL<b...
Prepare your Application<br />1<br />Renameyour tables<br />2<br />Createeditioning views<br />3<br />Reroute privileges<b...
grant use on edition to <user><br />alter database default edition=<x><br />alter session set edition=<x><br />dbms_sessio...
SQL>GRANT USE ON EDITION HR_RELEASE2 TO SCOTT;<br />Grant succeeded.<br />SQL> CONNECT SCOTT/TIGER<br />Connected.<br />SQ...
SQL>ALTER SESSION SET EDITION=HR_RELEASE2;<br />Session altered.<br />SQL> select sys_context('userenv', 'current_edition_...
Rolling back an upgrade<br />Retiring an Edition<br />Only the root or a leaf<br />No objects are inherited (anymore)<br /...
*_EDITIONS<br />*_EDITION_COMMENTS<br />*_VIEWS_AE<br />*_SOURCE_AE<br />*_OBJECTS_AE<br />*_ERRORS_AE<br />*_EDITIONING_V...
EBR and APEX - 1<br /><ul><li>ALTER SESSION SET EDITION
DBMS_SESSION.SET_EDITION_DEFERRED
Session Pooling</li></li></ul><li>dbms_epg.set_dad_attribute('APEX', 'database-edition', 'HR_RELEASE2');<br />in dads.conf...
Build on – views on - Editioning Views<br />Four (!) -tier architecture<br />Edition your Views or PL/SQL Functions<br />U...
Upcoming SlideShare
Loading in …5
×

Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefinition in combination with APEX

2,882 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,882
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
44
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 0:02 / 0:04Over 15 years experience in the Oracle field. Started with RDBMS v5, Oracle Case, Forms 2.3, RPT/RPF. All the way to the latest version of Designer, Developer, RDBMS (took part in the 11g beta test).Frequent contributor of Oracle APEX Forum – Not &gt; 4000 posts, but I’ve got work to do.BloggerWorking for Logica for over 13 years now as a Software Architect, NL-Lead Technical Architect OracleI set op the model for our Factory for Automated Migration of Oracle (u) Software. A repeatable solution for the migrations of Oracle Designer and Oracle Forms from earlier version to the latest version.Not a native English speaker – as you might have noticed (or will notice)APEX Experience?Forms Experience?APEX 2 Forms conversion experience?APEX 3.2 Early Adopters Release: article in Oghvisie &amp; Oracle Scene
  • 7 years!
  • 1. Physical Standby DatabaseStandby database is called “physical” if the physical structure of stand by exactly matches with stand by structure. Archived redo log transferred from primary database will be directly applied to the stand by database.2. Logical Standby DatabaseStand by database is called “logical”, the physical structure of both databases do not match and from the archived redo log we create SQL statements then these statements will be applied to stand by database.
  • Online Index Rebuild (9i):When the ONLINE keyword is used as part of the CREATE or ALTER syntax the current index is left intact while a new copy of the index is built, allowing DML to access the old index. Any alterations to the old index are recorded in a Index Organized Table known as a &quot;journal table&quot;. Once the rebuild is complete the alterations from the journal table are merged into the new index. This may take several passes depending on the frequency of alterations to the index. The process will skip any locked rows and commit every 20 rows. Once the merge operation is complete the data dictionary is updated and the old index is dropped. DML access is only blocked during the data dictionary updates, which complete very quickly.Online Table Redefinition (9i):Prior to Oracle9i table redefinition was only possible using export/import which meant the table was offline during the process, or the move syntax which locked DML during the operation. Neither of these methods is suitable for large OLTP tables as the downtime can be considerable. To solve this problem Oracle9i has introduced Online Table Redefinitions using the DBMS_REDEFINITION package.The process is similar to online rebuilds of indexes in that the original table is left online while a new copy of the table is built. DML operations on the original table are stored in an temporary table for interim updates. Once the new table is complete the interim updates are merged into it and the names of the original and the new table are swapped in the data dictionary. This step requires a DML lock but it is only held for a short time. At this point all DML is processed against the new table. The interim updates are automatically discarded, but the original table, with it&apos;s new name, has to be discarded manually
  • While Boo is implementing Version2, Sulley continues working in Version 1When Boo is finished, Randall starts a new session in Version 2, while Sulley stills does his thing in Version 1
  • NotEditionedTables X and Y are noteditionable, sothoseobjectsaren’t part of anyeditionBase ReleasePL/SQL Object A reads/writes to Table X and calls PL/SQL Object BPL/SQL Object B reads/writes to Table YRelease 2PL/SQL Object B is replacedby B’. PL/SQL Object A calls PL/SQL Object B’ nowPL/SQL Object B’ reads/writes to Table YPL/SQL Object A is “virtually present”
  • NotEditionedFor Release 2 column C is redundant and columns D and E are added.To keep the base release running column C isn’tdropped (yet).Youcan drop column C eventuallywheneveryone is using Release 2.Base ReleasePL/SQL Object A reads/writes to Editioning View XPL/SQL Object B reads/writes to Editioning View YRelease 2Edition View Y is replacedby Y’, without column C, butwith columns D and EPL/SQL Object B is replacedby B’. PL/SQL Object A calls PL/SQL Object B’ nowPL/SQL Object B’ reads/writes to Edition View Y’
  • Update in base ReleasefiresForwardCrossEditionTrigger in Release 2Update in Release 2FiresReverseCrossEditionTrigger in Release 2Update in Release 3FiresReverseCrossEditionTrigger in Release 2
  • Forward Xedition isn’t fired in own editionSo how to create the “new” information =&gt; FIRST_NAME and LAST_NAME from NAMEIGNORE_ROW_ON_DUPKEY_INDEX : Sort of Merge statement.CHANGE_DUPKEY_ERROR_INDEX : Changes an Duplicate Key error from ORA-00001 to ORA-38911
  • Forward Xedition isn’t fired in own editionSo how to create the “new” information =&gt; FIRST_NAME and LAST_NAME from NAMEIGNORE_ROW_ON_DUPKEY_INDEX HintWhen a statement of the form INSERT INTO target subquery runs, a unique key for some rows to be inserted might collide with existing rows. Suppose that you want your application to ignore such collisions and insert the rows that do not collide with existing rows.Before Release 11.2, you had to write a PL/SQL program which, in a block with a NULL handler for the DUP_VAL_ON_INDEX exception, selected the source rows and then inserted them, one at a time, into the target.As of Release 11.2, you do not have to write a PL/SQL program. You can use the IGNORE_ROW_ON_DUPKEY_INDEX hint in an INSERT statement, which is easier to write and runs much faster.CHANGE_DUPKEY_ERROR_INDEX HintWhen an INSERT or UPDATE statement runs, a unique key might collide with existing rows.Before Release 11.2, the collision caused error ORA-00001. You could tell that a collision had occurred, but you could not tell where.As of Release 11.2, you can use the CHANGE_DUPKEY_ERROR_INDEX hint in an INSERT or UPDATE statement, specifying that when a unique key violation occurs for a specified index or set of columns, ORA-38911 is reported instead of ORA-00001. This hint is especially helpful when implementing crossedition triggers.
  • alter database default edition = &lt;x&gt; -&gt; has as side effect : grant use on edition &lt;x&gt; to publicsys.dbms_sys_sql.parse(_as_user) has additional parameters: Editionapply_crossedition_triggerfire_apply_trigger
  • alter database default edition = &lt;x&gt; -&gt; has as side effect : grant use on edition &lt;x&gt; to publicsys.dbms_sys_sql.parse(_as_user) has additional parameters: Editionapply_crossedition_triggerfire_apply_trigger
  • * = ALL, USER or DBA
  • ALTER SESSION SET EDITION doesn’t work. Must be a top-level SQL statement. We can’t do that in APEX.DBMS_SESSION.SET_EDITION_DEFERRED sets the edition of yourcurrentsession (mightbe different fromyournextsession) select owner, object_name, object_id from all_objects where object_type = &apos;EDITION&apos;; select ses.sid, ses.username, ses.session_edition_id, obj.object_namefrom v_$sessionses, all_objectsobjwhere username in (‘ANONYMOUS’,’APEX_PUBLIC_USER’)And ses.session_edition_id = obj.object_id(ses_id.sql)
  • FAIL : /home/oracle/OraHome_1/Apache/Apache/bin/apachectl start: execinghttpdSyntax error on line 48 of /home/oracle/OraHome_1/Apache/modplsql/conf/dads.conf:Invalid command &apos;PlsqlDatabaseEdition&apos;, perhaps mis-spelled or defined by a module not included in the server configuration = BUG!!
  • That way we can separate the user-interface-layer (the way the information is rendered in the browser), the business-layer (what data is shown and what rules the input should comply to) and the data-layer (the editioning views and the tables itself). This way a three-tier-architecture is not sufficient: we even need a four-tier-architecture!
  • Tales from a Parallel Universe: Using Oracle 11gR2's Edition Based Redefinition in combination with APEX

    1. 1. Tales from a Parallel Universe:Using 11gR2’s Edition Based Redefinitions (in APEX)<br />Roel Hartman<br />
    2. 2. EBR and APEX?<br />Sorry, you can’t do it...<br />Questions?<br />John’s suggestion....<br />
    3. 3. Who am I?<br /><ul><li>Oracle since v5, Forms 2.3, Case*Designer etc
    4. 4. Presenter at UKOUG (3x), OOW (3x), ODTUG (2x)</li></ul>roelhartman.blogspot.com<br />No. 3<br />
    5. 5. Tom Kytesays:<br />
    6. 6.
    7. 7.
    8. 8.
    9. 9.
    10. 10.
    11. 11. Unplanned Downtime<br />Physical Standby Database<br />Logical Standby Database<br />RAC<br />The Case<br />
    12. 12. Unplanned Downtime<br />
    13. 13. Planned Downtime<br />Database Upgrade<br />Streams<br />Rolling Upgrade using Logical Standby Database<br />Application Maintenance<br />Online Index Rebuild<br />Online Table Redefinition<br />The Case<br />
    14. 14. Planned Downtime<br />
    15. 15. Planned Downtime <br />Application Upgrade<br />Create objects<br />Replace objects<br />Drop objects<br />Recompilation<br />The Case<br />
    16. 16.
    17. 17. Keep the Shop open<br />Prepare new Release <br />Cut over<br />Randall<br />Version 2<br />2<br />Boo<br />1<br />Version 1<br />Sulley<br />1<br />+ 2<br />
    18. 18. Edition<br />Schema<br />Object Type<br />Object Name<br />Session runs in the context of an Edition<br />Parallel Universes<br />
    19. 19. SQL>ALTER USER HR ENABLE EDITIONS;<br />USER ALTERED.<br />SQL> ALTER USER HR DISABLE EDITIONS;<br />ALTER USER HR DISABLE EDITIONS<br /> *<br />ERROR at line 1:<br />ORA-00922: missing or invalid option<br />SQL><br />
    20. 20. SQL> select * from all_editions;<br />EDITION_NAME PARENT_EDITION_NAME USA<br />------------ ------------------- ---<br />ORA$BASE YES<br />SQL><br />
    21. 21. SQL> CREATE EDITION HR_RELEASE2 AS CHILD OF ORA$BASE;<br />Edition created.<br />SQL> CREATE EDITION OE_RELEASE2 AS CHILD OF ORA$BASE;<br />CREATE EDITION OE_RELEASE2 AS CHILD OF ORA$BASE;<br />*<br />ERROR at line 1:<br />ORA-38807: Implementation restriction: an edition can have only one child<br />
    22. 22. ORA$BASE<br />HR<br />OE<br />HR_RELEASE2<br />HR’<br />OE_RELEASE2<br />OE’<br />One Child – One Parent<br />
    23. 23. Editionable<br />PL/SQL Objects<br />Packages<br />Procedures<br />Functions<br />Triggers<br />Views<br />Synonyms<br />Types<br />Not everything is editionable...<br />Not Editionable<br />Tables<br />Materialized Views<br />DB Links<br />
    24. 24. Table X<br />Table Y<br />ORA$BASE<br />PL/SQL (A)<br />PL/SQL (B)<br />HR_RELEASE2<br />PL/SQL (A)<br />PL/SQL (B)<br />PL/SQL (B’)<br />
    25. 25. “Instead-of-table”<br />Only one table in the from clause<br />No expressions, only columns<br />Can have “regular” table triggers<br />Same execution plan<br />Editioning Views are the new tables<br />Editioning Views are Editionable....<br />Editioning View<br />
    26. 26.
    27. 27. Editioning View<br />Data is the same<br />View is different<br />Depends on your position / edition<br />
    28. 28. Table X_t<br />Table Y_t<br />ORA$BASE<br />Editioning View X<br />Editioning View Y<br />PL/SQL (A)<br />PL/SQL (B)<br />HR_RELEASE2<br />Editioning View Y’<br />PL/SQL (A)<br />PL/SQL (B)<br />PL/SQL (B’)<br />
    29. 29. Old situation : One column NAME<br />New situation : FIRST_NAME / LAST_NAME<br />Cross Edition Triggers<br />Forward<br />Reverse<br />Only on a Table<br />Editionable<br />In the newedition!<br />How to handle Table changes?<br />
    30. 30. Cross Edition Triggers<br />NAME<br />FIRST_NAME<br />LAST_NAME<br />“split”<br />“concat”<br />RELEASE 2<br />ORA$BASE<br />RELEASE 3<br />ForwardCrossEditionTrigger<br />ReverseCrossEditionTrigger<br />Session A<br />Session B<br />Session C<br />
    31. 31. Chain of forward / reverse Xedition triggers in decendent / ancestor editions<br />Forward Xedition DML fires Forward Xedition triggers only (not regular triggers)<br />The same for Reverse Xedition DML<br />Xedition DML fires only other Xedition trigger (in same edition) if there is an ordering (follows xxx clause)<br />Advanced principles<br />
    32. 32. Forward Xedition isn’t fired in own edition<br />Fill FIRST_NAME / LAST_NAME from NAME<br />Fire the Xedition trigger only<br />Use dbms_utility.wait_on_pending_dml() to prevent “lost updates”<br />Use applying_crossedition_trigger function to prevent “collision”<br />Use IGNORE_ROW_ON_DUPKEY_INDEX / CHANGE_DUPKEY_ERROR_INDEX hint (mandate!) to prevent collision<br />Apply changes - 1<br />DBMS_Sql.Parse(<br />c => The_Cursor,<br />Language_Flag => DBMS_Sql.Native,<br />Statement => 'update emp set empno = empno',<br />Apply_Crossedition_Trigger => 'Fwd_Xed');<br />
    33. 33. Apply changes - 2<br />CREATE OR REPLACE TRIGGER trigger1 BEFORE INSERT OR UPDATE ON table1<br /> FOR EACH ROW CROSSEDITION<br />DECLARE<br />row_already_present EXCEPTION;<br /> PRAGMA EXCEPTION_INIT(row_already_present, -38911);<br />BEGIN<br /> IF APPLYING_CROSSEDITION_TRIGGER THEN<br /> /* Trigger is running because of serendipitous change.<br /> Insert new row into table2 unless it is already there. */<br /> INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(table2(key)) */<br /> INTO table2<br /> VALUES(:new.key, :new.value, to_date('1900-01-01', 'YYYY-MM-DD'));<br /> ELSE<br /> /* Trigger is running because you are applying transform.<br /> If tranform has not yet inserted new row in table2, insert new row;<br /> otherwise, update new row. */<br /> BEGIN<br /> INSERT /*+ CHANGE_DUPKEY_ERROR_INDEX(table2(key)) */<br /> INTO table2<br /> VALUES(:new.key, :new.value, SYSTIMESTAMP);<br /> EXCEPTION WHEN row_already_present<br /> THEN<br /> UPDATE table2<br /> SET value = :new.value, last_updated = SYSTIMESTAMP<br /> WHERE key = :new.key;<br /> END;<br /> END IF;<br />END;<br />
    34. 34. Rename your Tables<br />Create Editioning Views<br />Reroute Privileges<br />Recreate Triggers<br />Recompile all PL/SQL<br />Apply VPD Policies<br />Prepare your Application<br />Your last Planned Downtime<br />
    35. 35. Prepare your Application<br />1<br />Renameyour tables<br />2<br />Createeditioning views<br />3<br />Reroute privileges<br />Your last Planned Downtime<br />4<br />Recreatetriggers<br />5<br />Recompile PL/SQL<br />6<br />Apply<br />VPD policies<br />
    36. 36. grant use on edition to <user><br />alter database default edition=<x><br />alter session set edition=<x><br />dbms_session.set_edition_deferred( <x> )<br />sys.dbms_sys_sql.parse (_as_user)<br />sys_context<br />SQL*Plus : show edition<br />Opening up an Edition<br />
    37. 37. SQL>GRANT USE ON EDITION HR_RELEASE2 TO SCOTT;<br />Grant succeeded.<br />SQL> CONNECT SCOTT/TIGER<br />Connected.<br />SQL> select sys_context('userenv', 'current_edition_name') current_edition_name from dual; <br />CURRENT_EDITION_NAME<br />--------------------<br />ORA$BASE<br />
    38. 38. SQL>ALTER SESSION SET EDITION=HR_RELEASE2;<br />Session altered.<br />SQL> select sys_context('userenv', 'current_edition_name') current_edition_name from dual; <br />CURRENT_EDITION_NAME<br />--------------------<br />HR_RELEASE2<br />
    39. 39. Rolling back an upgrade<br />Retiring an Edition<br />Only the root or a leaf<br />No objects are inherited (anymore)<br />Not currently in use<br />Not the DB default edition<br />Recompile objects (reuse settings)<br />Dropping an Edition<br />
    40. 40. *_EDITIONS<br />*_EDITION_COMMENTS<br />*_VIEWS_AE<br />*_SOURCE_AE<br />*_OBJECTS_AE<br />*_ERRORS_AE<br />*_EDITIONING_VIEWS_AE<br />*_EDITIONING_VIEW_COLS_AE<br />DBMS_EDITIONS_UTILITIES.SET_EDITIONING_VIEWS_READ_ONLY<br />DBMS_SESSION.SET_EDITION_DEFERRED( <EDITION_NAME> )<br />New Database Stuff<br />
    41. 41. EBR and APEX - 1<br /><ul><li>ALTER SESSION SET EDITION
    42. 42. DBMS_SESSION.SET_EDITION_DEFERRED
    43. 43. Session Pooling</li></li></ul><li>dbms_epg.set_dad_attribute('APEX', 'database-edition', 'HR_RELEASE2');<br />in dads.conf : PlsqlDatabaseEdition*<br />apex_util.set_edition<br />sets CURRENT_EDITION<br />EBR and APEX - 2<br />Syntax error on line 48 of /home/oracle/OraHome_1/Apache/modplsql/conf/dads.conf:<br />Invalid command 'PlsqlDatabaseEdition', perhaps mis-spelled or defined by a module not included in the server <br />
    44. 44. Build on – views on - Editioning Views<br />Four (!) -tier architecture<br />Edition your Views or PL/SQL Functions<br />Use Authorization Schemes<br />EBR and APEX - 3<br />UI / APEX<br />(Regular) View<br />Editioning View<br />Table<br />
    45. 45. EBR and APEX – Cool demo<br />
    46. 46. SQLDeveloper support<br />
    47. 47. Applications never nevernever access tables<br />Application sets the edition<br />Alter DAD’s edition (EPG only)!<br />Be aware!!<br />Dropping objects drops inheritance<br />No branching<br />Best Practices<br />
    48. 48. Short time<br />Long(er) time<br />Only for a specific group<br />SaaS environment<br />Parallel Application Versions<br />
    49. 49. Different versions in the same schema<br />No more planned downtime!<br />Ease of maintenance<br />Less redo<br />Less risk<br />So saving $$$<br />Summary & conclusions<br />
    50. 50. Edition-Based Redefinition: Testing Live Application Upgrades (Without Actually Being Live) - Ms Melanie Caffrey<br />Today at 14:15<br />Other sessions @UKOUG<br />
    51. 51. Tom Kyte column(s) in Oracle Magazine Jan/Feb 2010 (http://www.oracle.com/technology/oramag/oracle/10-jan/o10asktom.html) <br />Bryn's Whitepaper "Edition-Based Redefinition a new capability in Oracle Database 11g Release 2 to support online application upgrade". July 2009 (http://www.oracle.com/technology/deploy/availability/pdf/edition_based_redefinition.pdf) <br />Documentation in "Oracle Database Advanced Application Developer's Guide 11g Release 2" (http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_editions.htm). <br />References<br />
    52. 52. Question Time<br />That’s all Folks!<br />My blog : http://roelhartman.blogspot.com<br />My e-mail : roel.hartman@logica.com<br />

    ×