Online Reorganisation with DBMS_REDEFINITION



Similar documents
Dictionary (catálogo)

5. CHANGING STRUCTURE AND DATA

Database Extensions Visual Walkthrough. PowerSchool Student Information System

A basic create statement for a simple student table would look like the following.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

New York Oracle Users Group (NYOUG) Long Island SIG. Oracle Data Integrator (ODI) Best Practices Do You Know How Flexible ODI Is?

D B M G Data Base and Data Mining Group of Politecnico di Torino

Managing Objects with Data Dictionary Views. Copyright 2006, Oracle. All rights reserved.

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

SQL. Short introduction

Table Backup and Recovery using SQL*Plus

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

An Esri White Paper February 2011 Best Practices for Storing the ArcGIS Data Reviewer Workspace in an Enterprise Geodatabase for Oracle

14 Triggers / Embedded SQL

? Oracle Deutschland

Expert Oracle. Database Architecture. Techniques and Solutions. 10gr, and 11g Programming. Oracle Database 9/, Second Edition.

Introduction to Triggers using SQL

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC

Programming with SQL

Part 5: More Data Structures for Relations

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

PERFORMANCE TIPS FOR BATCH JOBS

Netezza S's. Robert Hartevelt 31 October IBM Corporation IBM Corporation IBM Corporation

Data Masking. Procedure

SQL NULL s, Constraints, Triggers

Oracle Database 10g Express

2. Oracle SQL*PLUS Winter Some SQL Commands. To connect to a CS server, do:

3.GETTING STARTED WITH ORACLE8i

Oracle DBA Course Contents

Eliminating Required Waste and Non-Value Added Processing in Data Warehousing a Six Sigma LEAN Perspective

PeopleSoft DDL & DDL Management

types, but key declarations and constraints Similar CREATE X commands for other schema ëdrop X name" deletes the created element of beer VARCHARè20è,

Instant SQL Programming

D B M G Data Base and Data Mining Group of Politecnico di Torino

Recognizing PL/SQL Lexical Units. Copyright 2007, Oracle. All rights reserved.

High-Performance Oracle: Proven Methods for Achieving Optimum Performance and Availability

Oracle Data Redaction is Broken

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

CON5604 Upgrade from Siebel CRM 7.7 to 8.1 in Germany s Largest Loyalty Program Moscone West /01/14, 11:30-12:15

CSC 443 Data Base Management Systems. Basic SQL

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Porting from Oracle to PostgreSQL

Oracle Database 11 g Performance Tuning. Recipes. Sam R. Alapati Darl Kuhn Bill Padfield. Apress*

Introduction to SQL and database objects

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

An Oracle White Paper January Advanced Compression with Oracle Database 11g

<Insert Picture Here> Edition-based redefinition: the key to online application upgrade

Using SQL Server Management Studio

Keep It Simple - Common, Overlooked Performance Tuning Tips. Paul Jackson Hotsos

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Database Query 1: SQL Basics

EECS 647: Introduction to Database Systems

Note: The where clause of the SUBSET statement is sent "as is" to Oracle, so it must contain correct Oracle syntax.

Databases What the Specification Says

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Secure Test Data Management with ORACLE Data Masking

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

BCA. Database Management System

Best Practices for Storing the ArcGIS Data Reviewer Workspace in an Enterprise Geodatabase for Oracle. An Esri White Paper October 2013

ATTACHMENT 6 SQL Server 2012 Programming Standards

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Teach Yourself InterBase

The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

SQL Server Database Coding Standards and Guidelines

Oracle Database: SQL and PL/SQL Fundamentals NEW

LOBs were introduced back with DB2 V6, some 13 years ago. (V6 GA 25 June 1999) Prior to the introduction of LOBs, the max row size was 32K and the

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

USING SAS WITH ORACLE PRODUCTS FOR DATABASE MANAGEMENT AND REPORTING

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Database Administration with MySQL

news from Tom Bacon about Monday's lecture

Guide to SQL Programming: SQL:1999 and Oracle Rdb V7.1

Automatic Data Optimization

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Oracle 11gR2 : Recover dropped tablespace using RMAN tablespace point in time recovery

Oracle For Beginners Page : 1

The Relational Model. Why Study the Relational Model?

Oracle Database 10g: Introduction to SQL

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

ORACLE 10g Lab Guide

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

David Dye. Extract, Transform, Load

Data Modeling. Database Systems: The Complete Book Ch ,

2. Which of the following declarations is invalid? Mark for Review (1) Points

StreamServe Persuasion SP5 Oracle Database

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

An Oracle White Paper November Hybrid Columnar Compression (HCC) on Exadata

1 Triggers. 2 PL/SQL Triggers

5.1 Database Schema Schema Generation in SQL

Oracle PL/SQL Language. CIS 331: Introduction to Database Systems

Relational databases and SQL

Conventional Files versus the Database. Files versus Database. Pros and Cons of Conventional Files. Pros and Cons of Databases. Fields (continued)

Transcription:

Online Reorganisation with DBMS_REDEFINITION Abstract This paper demonstrates how to reorganize a main table with customer data of a Siebel system after a substantial amount of records have been deleted and row chaining is occurring. Contents - Steps 1 Checks if online redefinition is possible 2 Initial creation oft the interim table 3 Start of Redef 4 Creation of SQL for registration of constraints 5 Copy of dependencies (Trigger, Grants) 6 Creation of primary indexes 7 Intermediate sync 8 Creation of other indexes 9 Registration of indexes 10 Intermediate sync 11 Optimizer Statistics 12 Ending of Redefinition Step 1 - Checks if online redefinition is possible By executing DBMS_REDEFINITION.CAN_REDEF you can check whether the object is capable of being online redefined. If the table is not supported for redefinition, an error is reported. Online_Redefinition_Oracle_10gR2.pdf Page 1 of 9

There are 2 options for online redefinition: by using primary keyunique keys (default) by using Oracle rowid set serveroutput on dbms_redefinition.can_redef_table( uname => 'SIEBEL', tname => 'S_CONTACT', options_flag => dbms_redefinition.cons_use_pk); Step 2 - Initial creation oft the interim table Next, the interim table is created. This is the target segment of the table. This means, that if you wish to modify column list or partition the target table, this is where the definition has to be changed. In my example, I have added the string _REDEF to the original table name. CREATE TABLE "SIEBEL"."S_CONTACT_REDEF" ( "ROW_ID" VARCHAR2(15 CHAR) NOT NULL ENABLE, "CREATED" DATE DEFAULT sysdate NOT NULL ENABLE, "CREATED_BY" VARCHAR2(15 CHAR) NOT NULL ENABLE, "LAST_UPD" DATE DEFAULT sysdate NOT NULL ENABLE, "LAST_UPD_BY" VARCHAR2(15 CHAR) NOT NULL ENABLE, "DCKING_NUM" NUMBER(22,7) DEFAULT 0, "MODIFICATION_NUM" NUMBER(10,0) DEFAULT 0 NOT NULL ENABLE, "CONFLICT_ID" VARCHAR2(15 CHAR) DEFAULT '0' NOT NULL ENABLE, "PAR_ROW_ID" VARCHAR2(15 CHAR) DEFAULT 'x' NOT NULL ENABLE, "ACTIVE_FLG" CHAR(1 CHAR) DEFAULT 'Y' NOT NULL ENABLE, "BU_ID" VARCHAR2(15 CHAR) DEFAULT '0-R9NH' NOT NULL ENABLE, "COURT_PAY_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "DISA_CLEANSE_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "DISP_IMG_AUTH_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "EMAIL_SR_UPD_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "EMP_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "FST_NAME" VARCHAR2(50 CHAR) NOT NULL ENABLE, "INVSTGTR_FLG" CHAR(1 CHAR) DEFAULT 'N' NOT NULL ENABLE, "LAST_NAME" VARCHAR2(50 CHAR) NOT NULL ENABLE, "WORK_PH_NUM" VARCHAR2(40 CHAR), SUPPLEMENTAL LOG GROUP "LP_S_CONTACT_REDEF" ("ROW_ID") ALWAYS, SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS, SUPPLEMENTAL LOG DATA (UNIQUE INDEX) COLUMNS, SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS ) PCTFREE 20 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 134217728 NEXT 134217728 MINEXTENTS 1 MAXEXTENTS 2147483645 TABLESPACE "TSD128M_01" ; Step 3 Start of Redef I suspected that the start of the redefinition would take a long time and consume many resources, so I have wrapped the command inside a procedure and executed Online_Redefinition_Oracle_10gR2.pdf Page 2 of 9

the procedure via DBMS_SCHEDULER during off-peak hours. Theoretically, it is possible to reorder the rows with the orderby_cols parameter. On a production system I would not recommend to reorder the rows of this main Siebel table without thorough testing. CREATE OR REPLACE PROCEDURE MDDB."START_REDEF" is execute immediate 'ALTER SESSION ENABLE PARALLEL DML'; execute immediate 'ALTER SESSION FORCE PARALLEL DML PARALLEL 4'; execute immediate 'ALTER SESSION FORCE PARALLEL QUERY PARALLEL 4'; execute immediate 'ALTER SESSION SET DB_FILE_MULTIBLOCK_READ_COUNT=128'; dbms_redefinition.start_redef_table(uname => 'SIEBEL', orig_table => 'S_CONTACT', int_table => 'S_CONTACT_REDEF', options_flag => dbms_redefinition.cons_use_pk, orderby_cols => 'LAST_NAME,FST_NAME'); end start_redef; BEGIN sys.dbms_scheduler.create_job( job_name => '"MD"."REDEF_S_CONTACT"', job_type => 'STORED_PROCEDURE', job_action => '"MD"."START_REDEF"', start_date => sysdate+(624), job_class => '"DEFAULT_JOB_CLASS"', auto_drop => TRUE, enabled => TRUE); END; select * from dba_scheduler_job_run_details where job_name = 'REDEF_S_CONTACT' 4 Creation of SQL for registration of constraints The next step is to register the constraints. I have used the following dynamic SQL statement to generate a list of SQL commands for registration: select 'DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT (SIEBEL,S_CONTACT,S_CONTACT_REDEF,3, SIEBEL, a.constraint_name, b.constraint_name );' from (select * from dba_cons_columns where table_name = 'S_CONTACT') a, (select * from dba_cons_columns where table_name = 'S_CONTACT_REDEF') b where a.column_name = b.column_name Online_Redefinition_Oracle_10gR2.pdf Page 3 of 9

BEGIN _REDEF',3, 'SIEBEL', 'SYS_C00168731','SYS_C00169292'); _REDEF',3, 'SIEBEL', 'SYS_C00168730','SYS_C00169291'); _REDEF',3, 'SIEBEL', 'SYS_C00168729','SYS_C00169290'); END; 5 Copy of dependencies (Trigger, Grants) With the next step, I have copied Triggers and Grants from the source table to the interim table. set serveroutput on DECLARE nr_errors PLS_INTEGER; BEGIN DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS( uname => 'SIEBEL', orig_table => 'S_CONTACT', int_table => 'S_CONTACT_REDEF', copy_indexes => 0, copy_triggers => TRUE, copy_constraints => FALSE, copy_privileges => TRUE, ignore_errors => FALSE, num_errors => nr_errors, copy_statistics => FALSE); dbms_output.put_line(nr_errors); END; 6 Creation of primary indexes I have decided to manually create the indexes. Therefore in the previous command, the parameter copy_indexes is set to zero. I start with the main index which happens to be called _P1 by Siebel. I have decided to add the postfix _R to the index names. ALTER SESSION SET DB_FILE_MULTIBLOCK_READ_COUNT=128; CREATE UNIQUE INDEX "SIEBEL"."S_CONTACT_P1_R" ON "SIEBEL"."S_CONTACT_REDEF" ("ROW_ID") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 5242880 MINEXTENTS 1 MAXEXTENTS 2147483645 TABLESPACE "TSI128M_01" PARALLEL 2; ALTER INDEX "SIEBEL"."S_CONTACT_P1_R" NOPARALLEL; Online_Redefinition_Oracle_10gR2.pdf Page 4 of 9

7 Intermediate sync It is important to create the unique index before executing the sync_interim_table command. dbms_redefinition.sync_interim_table( uname => 'SIEBEL', orig_table => 'S_CONTACT',int_table => 'S_CONTACT_REDEF'); 8 Creation of other indexes Now, the remaining indexes can be created. If the creation takes a long time, then it is advisable to run sync_interim_table before the next create index statement. CREATE INDEX "SIEBEL"."S_CONTACT_DB01_X_R" ON "SIEBEL"."S_CONTACT_REDEF" ("CON_CD", "LAST_NAME", "FST_NAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 5242880 MINEXTENTS 1 MAXEXTENTS 2147483645 TABLESPACE "TSI128M_01" PARALLEL 2; CREATE INDEX "SIEBEL"."S_CONTACT_DB02_X_R" ON "SIEBEL"."S_CONTACT_REDEF" ("CALL_FLG") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 5242880 MINEXTENTS 1 MAXEXTENTS 2147483645 TABLESPACE "TSI5M_01" PARALLEL 2; CREATE INDEX "SIEBEL"."S_CONTACT_DB04_X_R" ON "SIEBEL"."S_CONTACT_REDEF" ("BIRTH_DT", "LAST_NAME", "FST_NAME") PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 5242880 NEXT 5242880 MINEXTENTS 1 MAXEXTENTS 2147483645 TABLESPACE "TSI128M_01" PARALLEL 2; etc. ALTER INDEX.. NOPARALLEL; 9 Registration of indexes Now with REGISTER_DEPENDENT_OBJECT, we can tell Oracle which index name on the interim table matches which index on the source table. select 'DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT(SIEBEL,S_CONTACT,S_CONTACT_RED EF,2, SIEBEL, i1.index_name, i2.index_name );' from dba_indexes i1, dba_indexes i2 where i1.owner = i2.owner and Online_Redefinition_Oracle_10gR2.pdf Page 5 of 9

i2.index_name = i1.index_name '_R' and i1.owner = 'SIEBEL' and i1.table_name = 'S_CONTACT' and i2.table_name = 'S_CONTACT_REDEF' BEGIN _REDEF',2, 'SIEBEL', 'S_CONTACT_M15','S_CONTACT_M15_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M16','S_CONTACT_M16_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M17','S_CONTACT_M17_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M18','S_CONTACT_M18_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M19','S_CONTACT_M19_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M20','S_CONTACT_M20_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M21','S_CONTACT_M21_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M22','S_CONTACT_M22_R'); _REDEF',2, 'SIEBEL', 'S_CONTACT_M3','S_CONTACT_M3_R'); --- and more END; 10 Intermediate sync Now we are ready for one last intermediate sync. dbms_redefinition.sync_interim_table(uname => 'SIEBEL',orig_table => 'S_CONTACT',int_table => 'S_CONTACT_REDEF'); 11 Optimizer Statistics Perhaps one of the most important steps is the creation of the optimizer statistics for the interim table. One way to gather stats is by setting COPY_STATS to yes when calling DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS. However this results in ANALYZE TABLE COMPUTE STATISTICS, which is not how we want to gather stats. In fact, I have decided to clone the statistics from the source table to the interim table. This has several reasons but the main reason is that I want to avoid SQL Plan changes because of this reorganization. You can find a description for the stattab table fields in this document: http:www.centrexcc.comsql%20tuning%20with%20statistics.ppt.pdf drop table MDECKER.S_CONTACT_REDEF_STATTAB; drop table MDECKER.S_CONTACT_STATTAB; Online_Redefinition_Oracle_10gR2.pdf Page 6 of 9

dbms_stats.create_stat_table( ownname => 'MDECKER', stattab => 'S_CONTACT_REDEF_STATTAB'); dbms_stats.create_stat_table( ownname => 'MDECKER', stattab => 'S_CONTACT_STATTAB'); dbms_stats.export_table_stats(ownname => 'SIEBEL', tabname => 'S_CONTACT_REDEF', stattab => 'S_CONTACT_REDEF_STATTAB', cascade => true, statown => 'MDECKER'); dbms_stats.export_table_stats(ownname => 'SIEBEL', tabname => 'S_CONTACT', stattab => 'S_CONTACT_STATTAB', cascade => true, statown => 'MDECKER'); SELECT * from MDECKER.S_CONTACT_STATTAB WHERE TYPE = 'T' update MDECKER.S_CONTACT_STATTAB set c1 = 'S_CONTACT_REDEF' WHERE TYPE = 'T'; SELECT * from MDECKER.S_CONTACT_STATTAB WHERE TYPE = 'I' update MDECKER.S_CONTACT_STATTAB set c1 = c1 '_R' WHERE TYPE = 'I'; SELECT * FROM DBA_TAB_COLS where TABLE_NAME IN ('S_CONTACT', 'S_CONTACT_REDEF') AND OWNER = 'SIEBEL' AND COLUMN_NAME LIKE 'SYS_%' SELECT * from MDECKER.S_CONTACT_STATTAB WHERE TYPE = 'C' and C4 like 'SYS_%' order by c4 update MDECKER.S_CONTACT_STATTAB set c1 = 'S_CONTACT_REDEF' WHERE TYPE = 'C'; update MDECKER.S_CONTACT_STATTAB set c4 = 'SYS_NC00288$' WHERE TYPE = 'C' and c4 like 'SYS_NC%'; Online_Redefinition_Oracle_10gR2.pdf Page 7 of 9

commit; dbms_stats.import_table_stats(ownname => 'SIEBEL', tabname => 'S_CONTACT_REDEF', stattab => 'S_CONTACT_STATTAB', cascade => true, statown => 'MDECKER'); Checks: select index_name, clustering_factor, num_rows, last_analyzed from dba_ind_statistics where table_owner = 'SIEBEL' and table_name = 'S_CONTACT_REDEF' MINUS select index_name '_R', clustering_factor, num_rows, last_analyzed from dba_ind_statistics where table_owner = 'SIEBEL' and table_name = 'S_CONTACT' select index_name '_R', clustering_factor, num_rows, last_analyzed from dba_ind_statistics where table_owner = 'SIEBEL' and table_name = 'S_CONTACT' MINUS select index_name, clustering_factor, num_rows, last_analyzed from dba_ind_statistics where table_owner = 'SIEBEL' and table_name = 'S_CONTACT_REDEF' select column_name, num_distinct, low_value, high_value, num_buckets, last_analyzed from dba_tab_col_statistics where owner = 'SIEBEL' and table_name = 'S_CONTACT_REDEF' MINUS select column_name, num_distinct, low_value, high_value, num_buckets, last_analyzed from dba_tab_col_statistics where owner = 'SIEBEL' and table_name = 'S_CONTACT' select column_name, num_distinct, low_value, high_value, num_buckets, last_analyzed from dba_tab_col_statistics where owner = 'SIEBEL' and table_name = 'S_CONTACT' MINUS select column_name, num_distinct, low_value, high_value, num_buckets, last_analyzed from dba_tab_col_statistics where owner = 'SIEBEL' and table_name = 'S_CONTACT_REDEF' 12 Ending of Redefinition Finally this is the last step of our redefinition process. This is the only point in time where an exclusive lock is obtained for a very short amount of time to rename the interim table to the target table and vice versa. I have successfully performed this reorganization on a mission critical database during normal daily activity without any problems. The final step took less than one second. dbms_redefinition.finish_redef_table( Online_Redefinition_Oracle_10gR2.pdf Page 8 of 9

uname => 'SIEBEL', orig_table => 'S_CONTACT',int_table => 'S_CONTACT_REDEF'); References: Oracle Database 10.2 Documentation Administrators Guide http:download.oracle.comdocscdb19306_01server.102b14231tables.htm#i1006754 Online_Redefinition_Oracle_10gR2.pdf Page 9 of 9