Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead
-
Upload
denise-calhoun -
Category
Documents
-
view
21 -
download
0
description
Transcript of Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead
![Page 1: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/1.jpg)
1
Don’t Shut Down That Database!
Use Oracle 9i Online Object Redefinition Instead
Chris LawsonPerformance Solutions
Roger SchragDatabase Specialists, Inc.
![Page 2: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/2.jpg)
2
Session Topics
What is “online object redefinition”? Why is this feature important? The dbms_redefinition package The online redefinition process Examples Restrictions Lessons learned
![Page 3: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/3.jpg)
3
Online Object Redefinition
Oracle 8i provided some online capabilities for IOTs.
Oracle 9i enables a wider range of online maintenance for almost all types of tables.
The ability to change the definition of a database object without restricting the ability of users to query and update data
![Page 4: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/4.jpg)
4
Things You Can Do With Online Redefinition
Move a table or index to a new tablespace Change a table’s organization (partitioning,
index-organized, etc.) Add, remove, or rename columns in a table Change the data type of a column in a table Add new indexes to a table Change constraint definitions on a table
![Page 5: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/5.jpg)
5
Why Do We Need This Feature?
Databases are getting larger and more complex.
DBAs are being given less down time to perform maintenance.
Companies often insist on no downtime. This feature makes it possible to perform
many important maintenance tasks online.
![Page 6: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/6.jpg)
6
The dbms_redefinition Package
CAN_REDEF_TABLE START_REDEF_TABLE FINISH_REDEF_TABLE ABORT_REDEF_TABLE SYNC_INTERIM_TABLE
Use the five procedures in this package to redefine an object online.
![Page 7: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/7.jpg)
7
Permissions Required To Redefine A Table Online EXECUTE on the dbms_redefinition package CREATE ANY TABLE ALTER ANY TABLE DROP ANY TABLE LOCK ANY TABLE SELECT ANY TABLE
Typically, you’ll want to use a DBA account to redefine objects online.
![Page 8: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/8.jpg)
8
Overview Of The Online Redefinition Process
Step 1: Verify the table is eligible for online redefinition.
Step 2: Create an interim table.Step 3: Associate the interim table with the
table to be redefined.Step 4: Add constraints, indexes, triggers, and
grants to the interim table.Step 5: Complete the online redefinition.
![Page 9: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/9.jpg)
9
Step 1: Verify The Table Is Eligible For Online Redefinition
Confirms table to be redefined meets requirements for online object redefinition
Call the CAN_REDEF_TABLE procedure in the dbms_redefinition package:EXECUTE dbms_redefinition.can_redef_table ('FINANCE', 'RATE');
Table qualifies if no exception is raised Exception will be raised if table does not qualify:
ORA‑12089: Cannot online redefine table with no primary key
![Page 10: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/10.jpg)
10
Step 2: Create An Interim Table
Online redefinition uses an interim table to change the object definition without restricting user access
Create interim table using exact column names, data types, organization, tablespace assignment, and storage clause that the redefined table should have
![Page 11: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/11.jpg)
11
Step 2: Create An Interim Table
Declare primary key on interim table, but do not create any other indexes, constraints, or triggers
Oracle will copy rows from the original table into the interim table during the redefinition process
Oracle will swap the names of the two tables at the end so the interim table will become the production table and vice versa
![Page 12: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/12.jpg)
12
Step 3: Associate The Interim Table With The Table To Be
Redefined Call the START_REDEF_TABLE procedure:
EXECUTE dbms_redefinition.start_redef_table ('FINANCE', 'RATE', 'STAGING');
Oracle creates a materialized view and log in order to populate the interim table from the production table and track subsequent updates to the production table. All rows in the production table are copied to the interim table
![Page 13: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/13.jpg)
13
Step 3: Associate The Interim Table With The Table To Be
Redefined A column mapping must be specified when calling
START_REDEF_TABLE if any columns are being added or removed, if any data types are being changed, or if any data is being modified
Could take a long time if production table has many rows
Users have full query and update capability
![Page 14: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/14.jpg)
14
Step 4: Add Constraints, Indexes, Triggers, And Grants To Interim
Table Create constraints, indexes, database triggers,
and grants on interim table desired on the production table at the end of the online redefinition process
Features on the production table, but not the interim table, will disappear from the redefined table in the next step
Create foreign keys with the DISABLE keyword
![Page 15: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/15.jpg)
15
Step 5: Complete The Online Redefinition
Interim table has organization, column definitions, indexes, constraints, triggers, and grants desired on redefined table. Interim table also has all of the rows of the production table except for updates occurring since Step 3 began
Call the FINISH_REDEF_TABLE procedure:
EXECUTE dbms_redefinition.finish_redef_table ('FINANCE', 'RATE', 'STAGING');
![Page 16: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/16.jpg)
16
Step 5: Complete The Online Redefinition
Oracle uses the materialized view log to propagate pending updates to interim table
Oracle locks production and interim tables briefly and swaps their names in data dictionary
Oracle drops the materialized view and log and enables disabled foreign keys
Redefinition is complete. Interim table (which used to be the production table) may be dropped
![Page 17: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/17.jpg)
17
Step 5: Complete The Online Redefinition
Step usually runs quickly (unless users have updated a lot of rows in the production table between the time Step 3 began and the time this step began)
Tables are locked only briefly. At all other times during the entire process, users have complete query and update ability on the table undergoing online redefinition
![Page 18: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/18.jpg)
18
Aborting An Online Redefinition
You may cancel an online redefinition process at any time before calling the FINISH_REDEF_TABLE procedure.
Abort the online redefinition by calling the ABORT_TABLE_REDEF procedure. Oracle drops the materialized view and log definitions, if they had been created.
You may drop the interim table if you wish.
![Page 19: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/19.jpg)
19
Examples Of Online Object Redefinition
1. Move a table to a new tablespace and add two new indexes.
2. Massage values in one column of a table and change the data type of another column.
![Page 20: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/20.jpg)
20
Example #1: Move A Table To A New Tablespace And Add Two
New Indexes
ALTER TABLE...MOVE locks the table. Export / Import makes the table read-only during
export and inaccessible during import. CREATE INDEX locks the table. Online redefinition allows full query and update
access.
Move the accts_payable table in the finance schema to a new tablespace. At the same time, add indexes on the vendor_name and vendor_po columns.
![Page 21: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/21.jpg)
21
Step 1: Verify The Table Is Eligible For Online
RedefinitionSQL> BEGIN 2 dbms_redefinition.can_redef_table 3 ('FINANCE', 'ACCTS_PAYABLE'); 4 END; 5 / PL/SQL procedure successfully completed SQL>
![Page 22: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/22.jpg)
22
Step 2: Create An Interim Table
SQL> CREATE TABLE accts_payable_stage 2 ( 3 account_id VARCHAR2(20), 4 vendor_name VARCHAR2(50) NOT NULL, 5 vendor_address VARCHAR2(50), 6 vendor_po VARCHAR2(20), 7 invoice_date DATE NOT NULL, 8 invoice_amount NUMBER NOT NULL, 9 CONSTRAINT accts_payable_pk PRIMARY KEY (account_id) 10 USING INDEX TABLESPACE accts_pay_ind 11 ) 12 TABLESPACE accts_pay_tab; Table created. SQL>
![Page 23: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/23.jpg)
23
Step 2: Create An Interim Table
Same column names and data types as production table
Primary key declared, but no other indexes or constraints
Desired tablespaces, storage clauses, and organization specified
![Page 24: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/24.jpg)
24
Step 3: Associate The Interim Table With The Table To Be
RedefinedSQL> BEGIN 2 dbms_redefinition.start_redef_table 3 ('FINANCE', 'ACCTS_PAYABLE', 4 'ACCTS_PAYABLE_STAGE'); 5 END; 6 / PL/SQL procedure successfully completed. SQL>
![Page 25: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/25.jpg)
25
Step 3: Associate The Interim Table With The Table To Be
Redefined No column mapping provided because no column information changed in this example
Step could take a long time if accts_payable table has many rows
Users will have full query and update ability
![Page 26: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/26.jpg)
26
Step 4: Add Constraints, Indexes, Triggers, And Grants
To Interim TableSQL> CREATE INDEX accts_payable_n1 ON accts_payable_stage (vendor_name) 2 TABLESPACE accts_pay_ind; Index created. SQL> CREATE INDEX accts_payable_n2 ON accts_payable_stage (vendor_po) 2 TABLESPACE accts_pay_ind; Index created. SQL> CREATE INDEX accts_payable_n3 ON accts_payable_stage (invoice_date) 2 TABLESPACE accts_pay_ind; Index created. SQL>
![Page 27: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/27.jpg)
27
Step 4: Add Constraints, Indexes, Triggers, And Grants
To Interim Table Add to interim table whatever features are
desired on redefined table Could be quite different from what exists on
original table (new indexes, different constraints, etc.)
![Page 28: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/28.jpg)
28
Step 5: Complete The Online Redefinition
SQL> BEGIN
2 dbms_redefinition.finish_redef_table
3 ('FINANCE', 'ACCTS_PAYABLE',
4 'ACCTS_PAYABLE_STAGE');
5 END;
6 /
PL/SQL procedure successfully completed.
SQL>
![Page 29: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/29.jpg)
29
Step 5: Complete The Online Redefinition
Could take a long time if many updates occurred after Step 3 began
Production table locked briefly near end of step
Production and interim table names are swapped
Drop interim table (old production table) manually after online redefinition is complete
![Page 30: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/30.jpg)
30
Example #2: Massage Values In One Column Of A Table And
Change The Data Type Of Another Column
SQL> DESCRIBE invoices Name Null? Type ---------------- -------- ---- INVOICE_ID NOT NULL VARCHAR2(20) LINE_ITEM NOT NULL NUMBER DESCRIPTION VARCHAR2(200) VENDOR_ID NOT NULL NUMBER INVOICE_AMT NOT NULL NUMBER
Strip trailing blanks from all values in the description column of the invoices table. Also, change the data type of the vendor_id column.
![Page 31: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/31.jpg)
31
Step 1: Verify The Table Is Eligible For Online
RedefinitionSQL> BEGIN 2 dbms_redefinition.can_redef_table 3 ('FINANCE', 'INVOICES'); 4 END; 5 / PL/SQL procedure successfully completed SQL>
![Page 32: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/32.jpg)
32
Step 2: Create An Interim Table
SQL> CREATE TABLE invoices_stage 2 ( 3 invoice_id VARCHAR2(20), 4 line_item NUMBER NOT NULL, 5 description VARCHAR2(200), 6 vendor_id VARCHAR2(20) NOT NULL, 7 invoice_amt NUMBER NOT NULL, 8 CONSTRAINT invoices_pk PRIMARY KEY (invoice_id) 9 USING INDEX TABLESPACE ind 10 ) 11 TABLESPACE tab; Table created. SQL>
![Page 33: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/33.jpg)
33
Step 2: Create An Interim Table
Data type of vendor_id column has changed from NUMBER to VARCHAR2(20)
Tablespaces specified even though we are not moving table or index to new tablespace
![Page 34: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/34.jpg)
34
Step 3: Associate The Interim Table With The Table To Be
RedefinedSQL> BEGIN 2 dbms_redefinition.start_redef_table 3 ('FINANCE', 'INVOICES', 'INVOICES_STAGE', 4 'INVOICE_ID INVOICE_ID, LINE_ITEM LINE_ITEM, ' || 5 'RTRIM (DESCRIPTION) DESCRIPTION, ' || 6 'TO_CHAR (VENDOR_ID) VENDOR_ID, ' || 7 'INVOICE_AMT INVOICE_AMT'); 8 END; 9 / PL/SQL procedure successfully completed. SQL>
![Page 35: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/35.jpg)
35
Step 3: Associate The Interim Table With The Table To Be
Redefined Column mapping provided due to data massaging and type conversion
RTRIM function to strip trailing blanks from description column
TO_CHAR function to convert numeric vendor_id to VARCHAR2
Invoice descriptions and vendor IDs are transformed as rows are copied to interim table
![Page 36: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/36.jpg)
36
Step 4: Add Constraints, Indexes, Triggers, And Grants
To The Interim Table For simplicity, the invoices table in this
example does not have any constraints, indexes, triggers, or grants other than the primary key declared when the interim table was created.
![Page 37: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/37.jpg)
37
Step 5: Complete The Online Redefinition
SQL> BEGIN
2 dbms_redefinition.finish_redef_table
3 ('FINANCE', 'INVOICES', 'INVOICES_STAGE');
4 END;
5 /
PL/SQL procedure successfully completed.
SQL>
![Page 38: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/38.jpg)
38
Step 5: Complete The Online Redefinition
At the end of the online redefinition, the description column is free of trailing blanks and the data type of the vendor_id column has been changed:
SQL> DESCRIBE invoices Name Null? Type ---------------- -------- ---- INVOICE_ID NOT NULL VARCHAR2(20) LINE_ITEM NOT NULL NUMBER DESCRIPTION VARCHAR2(200) VENDOR_ID NOT NULL VARCHAR2(20) INVOICE_AMT NOT NULL NUMBER SQL>
![Page 39: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/39.jpg)
39
Limitations Of The Online Redefinition Feature
Table eligibility requirements Limitations of column mapping Row selectivity
![Page 40: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/40.jpg)
40
Not Eligible For Online Redefinition
Tables without a declared primary key Tables that are the basis of a materialized
view Tables belonging to a cluster Temporary tables Tables in the SYS or SYSTEM schema Tables with FILE, LONG, or user-defined
data types
![Page 41: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/41.jpg)
41
Column Mapping Limitations
Simple functions and expressions only– Allowed: Changing the case of a string of text or
multiplying a numeric value by a constant– Not allowed: Subqueries or non-deterministic
functions
Mandatory columns must get values derived from existing columns
![Page 42: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/42.jpg)
42
Row Selectivity Limitation
Cannot eliminate rows from a table during online redefinition
Redefined table will have all of the rows in the original table
![Page 43: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/43.jpg)
43
Lessons Learned
Testing with the interim table Constraint validation Handling foreign keys Column mapping Speeding up the FINISH_REDEF_TABLE
call
![Page 44: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/44.jpg)
44
Testing With The Interim Table
Verify column mapping Validate data transformation Test new indexes Abort the redefinition if problems are
discovered—without impacting production
You can validate your object redefinition against the interim table before calling the FINISH_REDEF_TABLE procedure.
![Page 45: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/45.jpg)
45
Constraint Validation
Foreign keys declared on the redefined table are enabled but not validated at end of redefinition
Existing rows not tested for compliance Validating existing rows must be done
manually if validation desired
The Oracle 9i documentation fails to mention this point!
![Page 46: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/46.jpg)
46
Handling Foreign Keys
Recall that at the end of an online object redefinition, the names of the original production table and the interim table are swapped.
This means that after an online redefinition, foreign keys on other tables that used to reference the production table will now reference the interim table.
Redefining a table that is a parent to foreign keys declared on other tables presents a special problem.
![Page 47: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/47.jpg)
47
Redefining A Table That Is A Parent To Foreign Keys Declared
On Other Tables Declare new foreign keys in disabled state
that reference the interim table. When redefinition is complete, the new
foreign keys will reference the live table. Drop original foreign keys that now
reference the interim table. Plan for locks and resources required if you
wish new constraints to be validated.
![Page 48: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/48.jpg)
48
Column Mapping Specify column map in call to
START_REDEF_TABLE if any column names, data types, or values are changed
Single string consisting of comma-delimited expression / name pairs:– An expression is a formula to derive column
values from the existing production table.– A name is the name of a column in the interim
table to be loaded with the value.
![Page 49: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/49.jpg)
49
SQL Syntax Refresher
Strings are delimited by single quotes. Include a single quote in a string by
specifying two single quotes in a row. Concatenate two strings with the || operator.
![Page 50: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/50.jpg)
50
Column Mapping ExampleAppend an “A” to each invoice number while redefining the invoices table.
SQL> BEGIN 2 dbms_redefinition.start_redef_table 3 ('FINANCE', 'INVOICES', 'INVOICES_INTERIM', 4 'INVOICE_ID INVOICE_ID, VENDOR_ID VENDOR_ID, ' || 5 'INVOICE_DATE INVOICE_DATE, AMOUNT AMOUNT, ' || 6 'INVOICE_NUMBER || ''A'' INVOICE_NUMBER'); 7 END; 8 / PL/SQL procedure successfully completed. SQL>
![Page 51: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/51.jpg)
51
Speeding Up The FINISH_REDEF_TABLE Call Materialized view log catches all updates to
production table after START_REDEF_TABLE call All pending changes are propagated to interim
table during FINISH_REDEF_TABLE call Can call SYNC_INTERIM_TABLE any time before
FINISH_REDEF_TABLE to propagate all pending changes
Does not speed up the overall redefinition process
![Page 52: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/52.jpg)
52
Wrapping Up Oracle Corporation recognizes the need for high
availability. By and large, the online redefinition feature of
Oracle 9i is pretty easy to use. Tricky issues, such as foreign key handling, stem
from the complexities of changing a table while users are querying and updating it.
As with any new Oracle feature, test thoroughly before using!
![Page 53: Don’t Shut Down That Database! Use Oracle 9i Online Object Redefinition Instead](https://reader035.fdocuments.net/reader035/viewer/2022062722/5681392e550346895da0d6fe/html5/thumbnails/53.jpg)
53
Contact InformationChris LawsonPerformance SolutionsTel: 925/829-7496Email: [email protected] Web: www.oraclemagician.com
Roger SchragDatabase Specialists, Inc.Tel: 415/344-0500Email: [email protected]: www.dbspecialists.com