New ways to migrate from Oracle

Similar documents
Oracle Syllabus Course code-r10605 SQL

Oracle Database 10g: Introduction to SQL

Pl Sql Copy Table From One Schema To Another

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Copy Data From One Schema To Another In Sql Developer

Oracle Database: Introduction to SQL Ed 2

Oracle Copy Entire Schema Within Database Another

Databases and SQL programming overview

Oracle Schema Create Date Index Trunc >>>CLICK HERE<<<

Oracle Sql Describe Schema Query To Find Table

Oracle Compare Two Database Tables Sql Query Join

Creating and Managing Tables Schedule: Timing Topic

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

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

A Unit of SequelGate Innovative Technologies Pvt. Ltd. All Training Sessions are Completely Practical & Real-time

Oracle Database 12c SQL Fundamentals

Course Outline and Objectives: Database Programming with SQL

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

ORACLE DATABASE 12C INTRODUCTION

Oracle Database 11g: SQL and PL/SQL Fundamentals

MySQL for Developers Ed 3

Oracle Alter Table Add Unique Constraint Using Index Tablespace

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Using Relational Databases for Digital Research

Introduction to Computer Science and Business

Oracle Compare Two Database Tables Sql Query List All

SEF DATABASE FOUNDATION ON ORACLE COURSE CURRICULUM

Oracle Database: Introduction to SQL

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle Database: Introduction to SQL/PLSQL Accelerated

Oracle Database: SQL and PL/SQL Fundamentals

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Oracle Database: Introduction to SQL

Sql 2008 Copy Table Structure And Database To

Using SQL with SQL Developer 18.2

Large Scale MySQL Migration

Introduction to Computer Science and Business

Compare Two Identical Tables Data In Different Oracle Databases

Sql Server Syllabus. Overview

Using SQL with SQL Developer Part II

5. Single-row function

MySQL for Developers Ed 3

Oracle PLSQL Training Syllabus

CHAPTER. Oracle Database 11g Architecture Options

Full file at

Using SQL Developer. Oracle University and Egabi Solutions use only

Using SQL with SQL Developer 18.1 Part II

Introduction to SQL/PLSQL Accelerated Ed 2

New Oracle 12c Features for Developers

Granting Read-only Access To An Existing Oracle Schema

Chapter 8 - Sql-99 Schema Definition Constraints Queries And Views

Essential SQLite3. Section Title Page

Course Contents of ORACLE 9i

Oracle Database: Introduction to SQL

Nikolay Samokhvalov.

Migration From DB2 in a Large Public Setting: Lessons Learned

Oracle Database 12c: Program with PL/SQL Duration: 5 Days Method: Instructor-Led

Business Analytics. SQL PL SQL [Oracle 10 g] P r i n c e S e t h i w w w. x l m a c r o. w e b s. c o m

EDB Postgres Migration Portal Guide Version 1.0

MySQL for Developers with Developer Techniques Accelerated

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

Module 9: Managing Schema Objects

normalization are being violated o Apply the rule of Third Normal Form to resolve a violation in the model

Oracle SQL Developer. Oracle TimesTen In-Memory Database Support User's Guide Release 4.0 E

Topics - System Administration for Glovia

ORACLE TRAINING. ORACLE Training Course syllabus ORACLE SQL ORACLE PLSQL. Oracle SQL Training Syllabus

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615

IBM. Database Database overview. IBM i 7.1

Oracle Database 10g: SQL Fundamentals I

IBM Database Conversion Workbench 3.5

IBM i Version 7.2. Database Database overview IBM

Oracle Database: Program with PL/SQL

Mastering phpmyadmiri 3.4 for

Oracle Database: Program with PL/SQL Ed 2

SQL (Structured Query Language)

Oracle Database 12c R2: Program with PL/SQL Ed 2 Duration: 5 Days

Update Table Schema Sql Server 2008 Add Column After

Conditionally control code flow (loops, control structures). Create stored procedures and functions.

1. Data Model, Categories, Schemas and Instances. Outline

Oracle - Oracle Database: Program with PL/SQL Ed 2

Sql 2008 Copy Tables Structure And Database To Another

IZ0-144Oracle 11g PL/SQL Certification (OCA) training

This document contains information on fixed and known limitations for Test Data Management.

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

Oracle 12C DBA Online Training. Course Modules of Oracle 12C DBA Online Training: 1 Oracle Database 12c: Introduction to SQL:

PL/PGSQL AN INTRODUCTION ON USING IMPERATIVE PROGRAMMING IN POSTGRESQL

Projects. Corporate Trainer s Profile. CMM (Capability Maturity Model) level Project Standard:- TECHNOLOGIES

DB2 UDB: Application Programming

php works 2006 in Toronto Lukas Kahwe Smith

ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com

Oracle Database 11g: SQL Fundamentals I

Introduction. Sample Database SQL-92. Sample Data. Sample Data. Chapter 6 Introduction to Structured Query Language (SQL)

Review -Chapter 4. Review -Chapter 5

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing T-SQL and Data Management Systems 1. Chapter 2: SQL Server Fundamentals 23.

Oracle Database 11g: Introduction to SQLRelease 2

MySQL for Beginners Ed 3

Oracle Database 11g: Program with PL/SQL Release 2

Tools for Oracle Oracle Tutorials 2013 Przemyslaw Radowiecki CERN IT-DB

Transcription:

New ways to migrate from Oracle Laurenz Albe laurenz.albe@cybertec.at Cybertec Prague PostgreSQL Developers Day 2018

The problem Database migration consists of several parts: Migration of object definitions (CREATE TABLE, constraints, indexes ) Migration of the table data Migration of code stored in the database (functions, triggers, packages, ) Adapt the application (drivers, SQL dialect)

DDL migration Need to extract metadata to construct DDL CREATE TABLE is defined in the SQL standard but not nested tables, partitioning Need to adapt data types Translate NUMBER to integer, double precision or numeric? Translate DATE to date or timestamp? (Oracle DATE has seconds precision) Translate BLOB to bytea or large objects?

Data migration Extracting data from Oracle is difficult: sqlplus can be scripted, but is (almost) unusable SQL Developer is possible, but not comfortable. Cannot export BLOBs Oracle foreign data wrapper works well It seems like Oracle makes this hard by design

Stored code migration Functions, procedures, packages, triggers Code has to be translated by hand PL/SQL is similar to PL/pgSQL, but only very simple functions need no editing Packages can often be translated to functions in a schema PL/SQL code that interacts with the OS a lot (manipulate files, send e-mail) is often better translated to PL/Perl or PL/Python PL/Java is an option for Java stored procedures

Adapt the application Should be simple: both Oracle and PostgreSQL use SQL, and there is an SQL standard, but nobody supports the complete standard everybody extends the standard Need to adapt to changed data types Application code needs manual intervention and a lot of testing Module orafce provides (some) compatibility Abstraction layers (ORM) help a lot

SQL differences: Joins Oracle uses a special syntax for outer joins: SELECT b.col1, a.col2 FROM base_table b, attributes a WHERE b.id=a.b_id(+); Has to be translated to standard join syntax: SELECT b.col1, a.col2 FROM base_table b LEFT JOIN attributes a ON b.id=a.b_id;

SQL differences: empty strings Oracle treats empty strings as NULL values This leads to different semantics in string concatenation: ('astring' NULL) IS NOT NULL A workaround in PostgreSQL is to use the function coalesce: coalesce(col1, '') coalesce(col2, '')

SQL differences: Aliases Oracle supports the following syntax: SELECT * FROM (SELECT ); PostgreSQL (and the standard) require an alias: SELECT * FROM (SELECT ) alias;

SQL differences: sequences SQL standard syntax: NEXT VALUE FOR asequence Oracle syntax: asequence.nextval PostgreSQL syntax: nextval('asequence') Oracle does not allow NEXTVAL in a DEFAULT clause simplification in PostgreSQL possible This difference might become less important with the new identity column syntax supported by both

Techniques for Oracle migration There are some commercial tools There is ora2pg (https://ora2pg.darold.net/) Free open source Time tested (has been around for a while) Rich in features (PL/SQL migration, migration cost assessment reports) Works fairly well

Shortcomings of ora2pg Many features lead to many bugs Produces a monolithic SQL script that usually has to be edited by hand. Does not cope well with moving targets (schema changes while migration is developed)

Design goals for a new tool Do not attempt to cover everything (PL/SQL code, user defined types, ) Rather, keep it simple Comfortable editing of individual object definitions Ability to cope with moving targets (to some extent)

Idea: use Oracle FDW The Oracle foreign data wrapper is good for data migration (can be used with ora2pg): Translates between data types Translates encoding Direct data transfer without intermediate storage If oracle_fdw is good for data, why not also for metadata? This way, everything can be done with PL/pgSQL inside PostgreSQL Easy to write, no portability issues!

What is a foreign data wrapper? Allows to define foreign tables which look and feel like they are normal tables. SQL statements are redirected to an external data source. Conforms to the SQL standard. Exist (in varying quality) for a lot of external data sources.

ora_migrator architecture Two helper schemas: Oracle and PG stage Oracle stage contains foreign tables for Oracle metadata (table columns, constraints, etc.) PG stage contains tables with a snapshot of the data from the Oracle stage plus translated values (lower case names, PostgreSQL data types) PG stage can be edited (data types, PL/SQL code) PG stage can be refreshed from Oracle stage (should work well for normal schema changes)

ora_migrator requirements Install oracle_fdw extension Create a foreign server and a user mapping with a user that can access Oracle catalog (e.g. SELECT ANY DICTIONARY privilege) Test oracle_fdw configuration with SELECT oracle_diag('servername'); Install ora_migrator extension with CREATE EXTENSION

Migration steps (1) oracle_migrate_prepare: creates stages Edit tables in the PG stage oracle_migrate_mkforeign: creates target schemas and foreign tables for the data oracle_migrate_tables: creates local tables and migrates the data (errors turned to warnings) for parallelization, migrate each table by calling oracle_materialize('schema', 'table')

Migration steps (2) oracle_migrate_functions: creates functions oracle_migrate_triggers: creates triggers oracle_migrate_views: creates views oracle_migrate_constraints: creates constraints and indexes oracle_migrate_finish: drops staging schemas DROP EXTENSION oracle_fdw CASCADE; to remove all traces of the migration process

One click migration For simple databases that need no manual editing, you can migrate with one call: SELECT oracle_migrate( server => 'oraserver', only_schemas => '{ORASCHEMA}'); This won t migrate functions and will only work in very simple cases.

Data migration problems (1) Zero bytes in Oracle strings invalid byte sequence for encoding "UTF8": 0x00 Best solution: fix in Oracle Workaround: ALTER FOREIGN TABLE s.tab OPTIONS ( DROP schema, SET table '(SELECT id, replace(str, chr(0), '''') AS str, FROM s.tab)');

Data migration problems (2) Illegal bytes in Oracle: invalid byte sequence for encoding "UTF8": 0x80 Can happen because Oracle does not check data if client encoding = server encoding Possible solution (if real encoding is known) Create PostgreSQL DB with real encoding Set nls_lang option on foreign data wrapper to Oracle server encoding (no translation)

Making it comfortable Editing tables with UPDATE statements isn t nice Cybertec is currently developing a GUI that handles ora_migrator for you: Calls the appropriate SQL functions for setup and migration Comfortable editor to modify metadata

How can I get ora_migrator? ora_migrator is open source and available on https://github.com/cybertec postgresql/ora_migrator Try it and share your issues and ideas

Thank you for your attention! Any Questions?