The powerhouse PL/SQL upgrade option: Edition-Based Redefinition (EBR) Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OakTable Network OCP DBA (7, 8, 8i, 9i, 10g, 11g) OCP Advanced PL/SQL Developer Oracle Database: SQL Certified Expert http://www.oracle-base.com Books Oracle PL/SQL Tuning Oracle Job Scheduling http://www.oracle-base.com
Why should we care about EBR? Application upgrades with no downtime. Run multiple versions of apps simultaneously. Gradual ramp-up. http://www.oracle-base.com
Editions Version label (sort-of) for some objects in schema. Only apply to: PL/SQL Objects: Functions, Libraries, Packages, Procedures, Triggers, Types Also: Synonyms, Views Objects identified by: owner object_name object_type edition http://www.oracle-base.com
New and Amended Dictionary Views *_EDITIONS *_EDITION_COMMENTS *_OBJECTS *_OBJECTS_AE *_ERRORS *_ERRORS_AE *_USERS *_VIEWS *_EDITIONING_VIEWS *_EDITIONING_VIEWS_AE *_EDITIONING_VIEW_COLS *_EDITIONING_VIEW_COLS_AE * = DBA / ALL / USER http://www.oracle-base.com
What about tables? Tables NOT editionable. Use “Editioning Views” to see subsets and rename columns. CREATE OR REPLACE EDITIONING VIEW view-name AS SELECT col1, col2, col4 AS new_name FROM table-name; Apps access EViews, not tables. http://www.oracle-base.com
Editioning Views Schema Edition: release_v1 Edition: release_v2 http://www.oracle-base.com
Performance Oracle guarantee execution plan will match for same query against editioning view and table. No performance impact. http://www.oracle-base.com
Do base tables have missing data? Yes, but there is a solution. Use Cross-Edition Triggers to keep base table consistent. Similar to regular triggers. Transient. http://www.oracle-base.com
Demo setup.sql http://www.oracle-base.com
Managing Editions Editions are created using CREATE EDITION. CREATE EDITION ed-name; CREATE EDITION ed-name AS CHILD OF ed-name; Currently only 1 child per parent. Attempt to branch results in error. ORA-38807: Implementation restriction: an edition can have only one child v1 v2 v3 v1.5 http://www.oracle-base.com
Managing Editions (continued) Unreferenced leaf editions removed using DROP EDITION. Attempt to drop non-leaf edition results in error ORA-38810: Implementation restriction: cannot drop edition that has a parent and a child Query DBA_EDITIONS. manage_editions.sql v1 v2 ✗ v3 ✔ http://www.oracle-base.com
User Setup Editioning must be turned on for a user. ALTER USER username ENABLE EDITIONS; No off switch! Specific editions must be associated with users. GRANT USE ON EDITION ed-name TO username; user_setup.sql http://www.oracle-base.com
Switching between editions Any Session: (switch_editions.sql) ALTER SESSION SET EDITION = ed-name; ALTER DATABASE DEFAULT EDITION = ed-name; SQL*Plus: $ export ORA_EDITION=ed-name C:> set ORA_EDITION=ed-name $ sqlplus username/password@service edition=ed-name SQL> CONNECT username/password@service EDITION=ed-name http://www.oracle-base.com
Switching between editions (continued) Services: Editions associated with services (11.2.0.2) BEGIN DBMS_SERVICE.modify_service( service_name => 'DB11G.WORLD', edition => 'RELEASE_V1', modify_edition => TRUE); END; / When you switch to a new edition, all editionable objects in schema are automatically inherited from the previous edition. Altering or dropping an object breaks inheritance for that object. http://www.oracle-base.com
Preparing existing app for editions. Rename base tables. Create editioning views matching original table structures and names. PL/SQL objects will recompile against editioning view. Drop any triggers and compile them against editioning views, rather than base tables. If necessary, apply VPD policies against editioning views, rather than base tables. Revoke all privileges against tables and recreate them against the editioning views. http://www.oracle-base.com
Create new application Build editioning views over tables. Code references editioning views, not tables. Triggers and VPD policies reference editioning views. (create_app.sql) http://www.oracle-base.com
Upgrade application Amend base tables. Switch edition. Build new editioning views and new app. Build cross edition triggers and update missing data. (upgrade_app.sql) http://www.oracle-base.com
Summary Application upgrades with no downtime. Run multiple versions of apps simultaneously. Gradual ramp-up. Not just a PL/SQL feature. Java apps use tables too. http://www.oracle-base.com
The End… Download slides at: http://www.oracle-base.com/workshops Article: http://www.oracle-base.com/articles/11g/EditionBasedRedefinition_11gR2.php http://www.oracle-base.com