1 Peter Eisentraut Sun Microsystems PORTING APPLICATIONS FROM ORACLE TO POSTGRESQL 1.

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
ISD3 Chris Wallace Next 6 Weeks Extended Relational Model Object Orientation Matching systems 3 tier architecture Technology.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
CERN IT Department CH-1211 Genève 23 Switzerland t Streams new features in 11g Zbigniew Baranowski.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
SQL Within PL / SQL Chapter 4. 2 SQL Within PL / SQL SQL Statements DML in PL / SQL Pseudocolums Transaction Control.
PostgreSQL and relational databases As well as assignment 4…
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
Oracle PL/SQL Programming Steven Feuerstein All About the (Amazing) Function Result Cache of Oracle Database 11g.
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Oracle Database Administration Lecture 3  Transactions  SQL Language: Additional information  SQL Language: Analytic Functions.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
Oracle Database Administration
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
SCUHolliday - coen 1788–1 Schedule Today u Modifications, Schemas, Views. u Read Sections (except and 6.6.6) Next u Constraints. u Read.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Database Application Development using PL/SQL Programming.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Softsmith Infotech Oracle Table of contents What is a database? Fundamentals of database Table management Inserting data Updating data Deleting data Query.
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
 CONACT UC:  Magnific training   
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
7 Copyright © 2004, Oracle. All rights reserved. Managing Schema Objects.
Database Design: Solving Problems Before they Start! Ed Pollack Database Administrator CommerceHub.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Michal Kvet Lucia Fidesová
COMP 430 Intro. to Database Systems
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
CS320 Web and Internet Programming SQL and MySQL
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Relational Database Design
Oracle SQL.
What’s So Great About PL/SQL
Database Systems: Design, Implementation, and Management Tenth Edition
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Relational Algebra Chapter 4, Part A
DATABASE MANAGEMENT SYSTEM
SQL OVERVIEW DEFINING A SCHEMA
Relational Algebra Chapter 4, Sections 4.1 – 4.2
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Defining a Database Schema
Database Processing: David M. Kroenke’s Chapter Seven:
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
CS3220 Web and Internet Programming SQL and MySQL
PL/SQL Declaring Variables.
Database Systems: Design, Implementation, and Management Tenth Edition
Chapter 11 Managing Databases with SQL Server 2000
CS3220 Web and Internet Programming SQL and MySQL
CMSC-461 Database Management Systems
Presentation transcript:

1 Peter Eisentraut Sun Microsystems PORTING APPLICATIONS FROM ORACLE TO POSTGRESQL 1

2 Why? – Reasons for Porting Number One reasons: Cost Most people appear to come from Oracle and Informix But porting can be pretty difficult A rewrite might be better

3 Tools Essential: orafce ora2pg Also useful: TOra DBD::Oracle Oracle Instant Client

4 Critical Syntax Differences Identifier quoting: “foo” vs. foo vs. FOO vs. “FOO” > better not to mix quoted and unquoted SELECT foo [AS] bar FROM... > fixed in PostgreSQL 8.4 MINUS instead of EXCEPT > search and replace SELECT... FROM dual > fixed through orafce SQL key words

5 Porting the SQL Schema Many things work without problems: Table definition Columns Constraints Views Many queries Locking, concurrency control

6 Data Types varchar2 → varchar or text clob, long → varchar or text nvarchar2, nclob → varchar or text number → numeric or bigint or int or smallint or double precision or real (bug potential) binary_float, binary_double → real/double precision blob, raw, long raw → (bytea) date → date or timestamp

7 Data Types – Development Plan Implement missing SQL standard types in PostgreSQL: blob, clob, nclob Add some Oracle types to orafce: varchar2, nvarchar2 long number binary_float, binary_double

8 Built-in Functions PostgreSQL supports many compatibility functions. orafce supports even more compatibility functions. It's easy to write your own. Manual work necessary for: > sysdate → current_timestamp or localtimestamp > decode → CASE > seqname.nextval → nextval('seqname')

9 Functions with Default Parameters CREATE FUNCTION foo (a int, b int, c int = 0)... becomes CREATE FUNCTION foo (a int, b int, c int)... CREATE FUNCTION foo (a int, b int)... AS $$ SELECT foo(a, b, 0) $$; This doesn't always work for the general case. PostgreSQL might support this better in the future.

10 Outer Joins Oracle supports SQL join syntax, but most people don't use it. To port: SELECT * FROM a, b WHERE a.x = b.y(+) becomes SELECT * FROM a LEFT JOIN b ON a.x = b.y Po

11 Null Values Oracle has NULL equivalent to '' Therefore, '' = '' is not true Causes all kinds of logical inconsistencies Just hope your code doesn't rely too much on this

12 Triggers Same concept, different syntax: CREATE TRIGGER foo AFTER action ON table AS BEGIN... END; becomes CREATE OR REPLACE FUNCTION foo_tg() RETURNS TRIGGER LANGUAGE xxx AS $$... $$; CREATE TRIGGER foo AFTER action ON table EXECUTE PROCEDURE foo_tg();

13 Date/Time Processing Remember: date might be timestamp > Then date + int might become timestamp + int, which doesn't work. to_char() is mostly compatible, but less robust NLS_DATE_FORMAT → locale settings orafce helps: to_char(), last_day(), add_months(),... Code rewrite is sometimes preferrable.

14 ROWNUM and ROWID ROWNUM: > Rewrite using LIMIT, or > Use generate_series, or > Handle in the client, or > Window functions in 8.4? ROWID: > Similar to ctid > Not portable > Query can usually be rewritten –Sometimes used as workaround for lack of joins in UPDATE or DELETE

15 Other Porting Issues Indexes Optimizer hints Encodings, locales Partitioning

16 Things That Won't Work Easily CONNECT BY Window functions Materialized views, snapshots Database links Autonomous transactions Synonyms Virtual Private Database (VPD) XML (= your project might balloon if you have a lot of these)

17 PL/SQL vs. PL/pgSQL Very similar, but not really that compatible Count on having to manually touch up every single function/procedure See also porting.html porting.html

18 PL/SQL vs. PL/pgSQL: Major Diffs CREATE FUNCTION... RETURN → RETURNS Quote function body ($$... $$) Add DECLARE for variable definitions block Columns vs. variables name clashes Packages Package variables cursorname%ROWTYPE → RECORD PERFORM procname();

19 PL/SQL vs. PL/pgSQL: More Diffs Intra-procedure COMMIT and ROLLBACK Exception handling > Implicit rollback in PostgreSQL > Oracle code often has complex savepoint-using code to achieve the same → delete it. > Exception names and error codes are different. NO_DATA_FOUND exceptions → use SELECT INTO STRICT or IF NOT FOUND

20 sqlplus vs. psql sqlplus is more powerful for scripting. psql is better for interactive use. With careful naming conventions and use of variables, some scripts can be ported. Better rewrite all the scripts.

21 Other Things to Think About Backup, recovery Setup scripts Maintenance scripts Test suite Long-term code maintenance Legacy environments Adjusting client code

22 Conclusions It's possible to write portable Oracle applications, but most people don't do it. Porting projects range from trivial to nearly impossible. Rewrites or complete redesigns might work better. Careful evaluation and planning is advisable.

23 Contribute Porting projects are a good source for feature ideas and bug fixes. Contribute your improvements: > ora2pg > orafce > PL/pgSQL > PL/Java Record experiences in wiki

24 PORTING ORACLE APPLICATIONS TO POSTGRESQL Peter Eisentraut 24