SlideShare a Scribd company logo
1 of 80
Download to read offline
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management




                  Porting Oracle Applications to PostgreSQL

                        Peter Eisentraut, credativ GmbH / credativ Ltd.



                                                    PGCon 2008




Porting Oracle Applications to PostgreSQL: 1 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Disclaimers




                This presentation was written by a PostgreSQL expert, not an
                Oracle expert.
                Both Oracle and PostgreSQL are diverse, complex, and
                moving targets.
                Both Oracle and PostgreSQL are (probably) Turing-complete,
                so almost anything is “possible”, but we are looking for
                reasonable options.




Porting Oracle Applications to PostgreSQL: 2 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   You Will See . . .




                Porting projects are hard.
                Compatibility and compatibility layers are an illusion.
                It might be better not to do it.
                But success can be very rewarding.




Porting Oracle Applications to PostgreSQL: 3 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 4 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 5 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Syntax


             Identifiers Oracle case folds to upper case, PostgreSQL to lower
                        case. Big trouble if you mix quoted and unquoted
                        identifiers.
        Column aliases SELECT foo [AS] bar — Most Oracle
                     applications omit the AS, but PostgreSQL requires it.
                     Fixed in PostgreSQL 8.4.
                MINUS Change to EXCEPT.
        SQL key words Usually not a big problem, but should be kept in
                    mind.
        “FROM dual” Easy to work around (or use orafce).




Porting Oracle Applications to PostgreSQL: 6 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Table Definition




                The usual features are mostly the same: columns, constraints,
                defaults.
                Data types are more work; see below.
                No fancy features like “table of type”.




Porting Oracle Applications to PostgreSQL: 7 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Data Types: General




                Both Oracle and PostgreSQL support plenty of
                SQL-conforming data types.
                But usually the nonconforming ones are in wider use.
                Thin compatibility layers can usually help, but that will make
                your PostgreSQL application unpretty.
                A big search-and-replace is usually in order.




Porting Oracle Applications to PostgreSQL: 8 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Data Types: Specifics



                varchar2 → varchar or text
                clob, long → varchar or text
                nchar, 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 (additional porting required)
                date → date or timestamp




Porting Oracle Applications to PostgreSQL: 9 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Null Values




                Infamous Oracle behavior: NULL = ’’
                Consequently, ’’ = ’’ is not true
                Completely weird and inconsistent
                Usually, your data will just disappear in PostgreSQL
                transform_null_equals does not help here
                If your application relies on any of this, you are in trouble.




Porting Oracle Applications to PostgreSQL: 10 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Functions: General




                Function compatibility is a bottomless pit.
                PostgreSQL (+ orafce) supports many Oracle compatibility
                functions.
                It’s easy to write your own.
                Only the special syntax is trouble.




Porting Oracle Applications to PostgreSQL: 11 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Functions: Compatibility




        For example, the following common functions are supported by
        PostgreSQL as well:
                substr
                to char
                nvl, nullif (orafce)




Porting Oracle Applications to PostgreSQL: 12 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Functions: Specifics




        Manual work required here:
                sysdate → current_timestamp or localtimestamp




Porting Oracle Applications to PostgreSQL: 13 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Functions: decode




        DECODE(expr, search, expr[, search, expr...] [, default])

        becomes

        CASE WHEN expr THEN search .. ELSE default END




Porting Oracle Applications to PostgreSQL: 14 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Default Parameters: Overview




                PostgreSQL supports neither default values for parameters nor
                named parameters in function calls.
                Oracle applications make ample use of both.




Porting Oracle Applications to PostgreSQL: 15 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Default Parameters: The Easy Case




        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) $$;




Porting Oracle Applications to PostgreSQL: 16 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Default Parameters: The Hard Case




        CREATE FUNCTION foo (a int, b int = 5, c int = 0) ...

                This is only callable with named parameters.
                PostgreSQL doesn’t support this.
                You will have to change your client application.
                Your project time will double.




Porting Oracle Applications to PostgreSQL: 17 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Default Parameters: Conclusion




                Approx. 97% of applications to be ported contain issues like
                this.
                Client code must be reworked.
                Adding this support in PostgreSQL would be a great feature.




Porting Oracle Applications to PostgreSQL: 18 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Sequences: Creating




        Sequences are somewhat compatible . . .
                Change NOCACHE to CACHE 1 (or omit).
                MAXVALUE 9999999999999999999999999 needs to be
                reduced.
        Don’t rely on the caching behavior.




Porting Oracle Applications to PostgreSQL: 19 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Sequences: Using




                Oracle syntax: sequence_name.nextval
                PostgreSQL syntax: nextval(’sequence_name’)
        Search-and-replace; but direct sequence calls are rare.




Porting Oracle Applications to PostgreSQL: 20 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outer Joins: Overview




                PostgreSQL only supports the SQL-standard outer join syntax.
                Oracle supports it since version 9.
                Most Oracle code uses the old, Oracle-specific syntax.
                Porting is usually straightforward, but requires manual work.
                Set up test queries to catch porting mistakes.




Porting Oracle Applications to PostgreSQL: 21 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outer Joins: Simple Example




        SELECT * FROM a, b WHERE a.x = b.y(+)

        becomes

        SELECT * FROM a LEFT JOIN b ON a.x = b.y




Porting Oracle Applications to PostgreSQL: 22 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outer Joins: Complex Example


        SELECT ...
            FROM A, B, C
            WHERE A.A_ID (+) = B.A_ID
              AND C.C_KEY(+) = B.C_KEY

        becomes

        SELECT ...
            FROM A
                 RIGHT JOIN
                 B ON (A.A_ID = B.A_ID)
                 LEFT JOIN
                 C ON (C.C_KEY = B.C_KEY)


Porting Oracle Applications to PostgreSQL: 23 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outer Joins: Unclear Example



        SELECT         ...
          FROM         A, B, C, D, E
         WHERE         A.A_ID = B.A_ID
           AND         B.B_ID = C.A_ID(+)
           AND         B.B_KEY = C.B_KEY(+)
           AND         C.C_ID = D.C_ID(+)
           AND         B.A_ID = E.A_ID(+)
           AND         B.B_KEY = E.B_KEY(+)
           AND         ’CONSTANT’ = C.X_ID(+)

        What’s that???



Porting Oracle Applications to PostgreSQL: 24 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Locking




                Transaction isolation, locking, SELECT FOR UPDATE behave
                pretty much the same.
                Oracle also defaults to read committed.
                Usually, no one at the client has ever heard of concurrency
                issues, so the code is likely buggy anyway.




Porting Oracle Applications to PostgreSQL: 25 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Indexes




                Basic syntax the same:
                CREATE INDEX name ON table (a, b)
                Primary keys and unique constraints are automatically
                indexed.
                Other features are implementation-specific.
                You will have to re-tune the entire porting result anyway.




Porting Oracle Applications to PostgreSQL: 26 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Optimizer Hints




                Delete them
                Or keep them for future investigation
                Usually useless




Porting Oracle Applications to PostgreSQL: 27 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Date Formatting




                TO_CHAR is largely compatible.
                Warning: PostgreSQL version is not very robust.
                One-argument variant provided by orafce
                NLS_DATE_FORMAT is replaced by locale settings.




Porting Oracle Applications to PostgreSQL: 28 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Date Arithmetic



                Usually, date arithmetic is easier in PostgreSQL, so consider a
                small code rewrite.
                orafce provides compatibility functions, such as last_day,
                add_months.
                Oracle code often does date + int . . .
                        In PostgreSQL, this may become timestamp + int.
                        This doesn’t work.
                        Write a custom operator or rewrite the code.




Porting Oracle Applications to PostgreSQL: 29 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Encodings




                Both Oracle and PostgreSQL support the same ideas.
                But everything is named differently.
                Might be a good time to review the encoding and locale
                choices.




Porting Oracle Applications to PostgreSQL: 30 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   NLS * vs. LC *


        Approximate analogies:

             NLS     CALENDAR                                 —
             NLS     COMP                                     lc collate = ’C’
             NLS     CURRENCY                                 lc monetary
             NLS     DATE FORMAT                              DateStyle
             NLS     DATE LANGUAGE                            lc messages, lc time (8.4?)
             NLS     LANG, NLS LANGUAGE                       LANG, client encoding
             NLS     NCHAR                                    —
             NLS     NUMERIC CHARACTERS                       lc numeric
             NLS     SORT                                     lc collate
             NLS     TERRITORY                                LANG, lc *




Porting Oracle Applications to PostgreSQL: 31 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   ROWNUM and ROWID



        ROWNUM:
                Use generate_series, or
                Rewrite and apply LIMIT, or
                Just handle in the client
        ROWID:
                Analogous to ctid
                Good code should usually not use this.
                That does not prevent some from trying.




Porting Oracle Applications to PostgreSQL: 32 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   XML




        (untested!)
                xmltype → xml
                extract → xpath
                XMLELEMENT, XMLATTRIBUTES, etc. are the same.
                Most functionality is different or missing in PostgreSQL.




Porting Oracle Applications to PostgreSQL: 33 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Triggers: Declarations

        Oracle uses inline trigger actions:

        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();

        Note: FOR EACH STATEMENT is the default in Oracle and
        PostgreSQL.


Porting Oracle Applications to PostgreSQL: 34 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Triggers: Column-Level Triggers
        Oracle supports column-level triggers:
        CREATE TRIGGER foo BEFORE UPDATE OF column ON table
            AS BEGIN ... END;
        becomes
        CREATE OR REPLACE FUNCTION foo_tg() RETURNS TRIGGER
             LANGUAGE xxx AS $$
        BEGIN
          IF NEW.column IS NOT DISTINCT FROM OLD.column THEN
             RETURN NEW;
          END IF;
          ... -- normal code
        END;
        $$;
        CREATE TRIGGER foo AFTER action ON table
             EXECUTE PROCEDURE foo_tg();
        But this doesn’t catch updates to the same value.
        You will need to make a choice which behavior you need.
Porting Oracle Applications to PostgreSQL: 35 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Things That Won’t Work Directly



        CONNECT BY Try contrib/tablefunc.
        Materialized views Write your own wrapper.
            Snapshots Write your own wrapper.
        Database links Use contrib/dblink plus views.
        Autonomous transactions Try dblink.
            Synonyms Try views or wrapper or schema path.
         Partitioning Write your own system.




Porting Oracle Applications to PostgreSQL: 36 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 37 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   orafce




        http://orafce.projects.postgresql.org/
                Large set of Oracle compatibility functions
                “dual” table
                Debian and RPM packages available
                Invaluable




Porting Oracle Applications to PostgreSQL: 38 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   ora2pg




        http://ora2pg.projects.postgresql.org/
                Converts Oracle schema definitions
                Extracts data from Oracle database for import into
                PostgreSQL
                Packages available
                Invaluable




Porting Oracle Applications to PostgreSQL: 39 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   TOra




        http://tora.sourceforge.net/
                GUI for PostgreSQL and Oracle
                Contains exploration and debugging facilities for Oracle
                Packages available, but usually without Oracle support
                Generally a bit outdated, but good for this purpose




Porting Oracle Applications to PostgreSQL: 40 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   DBD::Oracle




        http://search.cpan.org/dist/DBD-Oracle/
                Needed for ora2pg
                Also helpful for test scripts etc.
                Building it can be challenging
                Debian and RPM packages available




Porting Oracle Applications to PostgreSQL: 41 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Oracle Instant Client




                Needed for DBD::Oracle and TOra
                Also contains sqlplus
        download from Oracle




Porting Oracle Applications to PostgreSQL: 42 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Oracle Database Express Edition




                Use this for testing if you have no other Oracle instance.
        download from Oracle




Porting Oracle Applications to PostgreSQL: 43 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 44 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   From PL/SQL to PL/pgSQL




                Compatibility isn’t that great, but it’s obviously the best
                choice.
                The PL/pgSQL parser is DAAB.
                See also http://www.postgresql.org/docs/current/
                static/plpgsql-porting.html.




Porting Oracle Applications to PostgreSQL: 45 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Function Creation




                CREATE FUNCTION ... RETURN type becomes
                CREATE FUNCTION ... RETURNS type
                Function body must be quoted (dollar quoting).
                Various other details are incompatible:
                        LANGUAGE
                        STRICT, STABLE, etc.
                For variable declarations, DECLARE is needed in PostgreSQL.




Porting Oracle Applications to PostgreSQL: 46 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Syntax Differences




                FOR i IN REVERSE 1..10 LOOP — Order must be switched
                for PostgreSQL.




Porting Oracle Applications to PostgreSQL: 47 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Variables




                PL/SQL can distinguish column names and variable names.
                PL/pgSQL replaces all matching tokens by variables.
                Find a namespacing mechanism to tell apart variables,
                parameters, and columns.




Porting Oracle Applications to PostgreSQL: 48 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Packages




                Use schemas to group your functions.
                Call syntax is about the same.
                But there is no equivalent public/private mechanism.




Porting Oracle Applications to PostgreSQL: 49 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Package Variables




                Not supported by PostgreSQL
                Write a wrapper based on (temporary) tables.




Porting Oracle Applications to PostgreSQL: 50 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Cursors

        Usually, you need less cursors in PostgreSQL.

        CURSOR foo IS SELECT ...;

        BEGIN
            FOR x IN foo LOOP

        can be simplified to

        BEGIN
            FOR x IN SELECT ... LOOP

        Note: The x is defined implicitly in Oracle. In PostgreSQL, you
        need to declare it.


Porting Oracle Applications to PostgreSQL: 51 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Cursors Variables
        This doesn’t work in PostgreSQL:

        CURSOR foo IS SELECT ...;
        x foo%ROWTYPE;

        BEGIN
            FOR x IN foo LOOP

        Use RECORD:

        DECLARE
            CURSOR foo IS SELECT ..;
            x RECORD;

        BEGIN
            FOR x IN foo LOOP

Porting Oracle Applications to PostgreSQL: 52 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   PERFORM




        In PostgreSQL, “procedure” calls must start with PERFORM. E. g.,

        service.put_utl(’Error’);

        becomes

        PERFORM service.put_utl(’Error’);




Porting Oracle Applications to PostgreSQL: 53 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   EXECUTE




        For DDL statements, EXECUTE might be necessary. E. g.,

        EXECUTE ’CREATE TABLE ’ || quote_ident(foo) || ...




Porting Oracle Applications to PostgreSQL: 54 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Subcommits




        Code that does COMMIT or ROLLBACK needs major, client-side
        changes. (Savepoints won’t usually do the job.)




Porting Oracle Applications to PostgreSQL: 55 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Exceptions (1)




                An exception rolls back all changes implicitly in PostgreSQL.
                You can drop most savepoint-using code from the Oracle
                version.
                More complex behavior needs a redesign.




Porting Oracle Applications to PostgreSQL: 56 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Exceptions (2)




                Exception block syntax is the same.
                Exception names are different.
                Oracle supports user-defined exception names.
                Error codes are different.
                Variable SQLERRM is available.
                Of course, error messages are also different.




Porting Oracle Applications to PostgreSQL: 57 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Exceptions (3)


        We use a scheme to encode exception information into the
        message string:

        RAISE name; ---> RAISE EXCEPTION ’name’;

        Similar for error codes:

        raise_application_error(12345, ’msg’);
            ---> RAISE EXCEPTION ’+12345:msg’;

        Codes can be positive or negative. Write a wrapper function.

        errcode := substr(SQLERRM, 1, 6)




Porting Oracle Applications to PostgreSQL: 58 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   No Data Found Exceptions



        Oracle throws NO_DATA_FOUND exceptions for
                SELECT
                INSERT
                UPDATE
                DELETE
        PostgreSQL only for:
                SELECT INTO STRICT
        Use IF NOT FOUND to deal with other cases.




Porting Oracle Applications to PostgreSQL: 59 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Logging




        dbms_output “package” is provided by orafce. E. g.

        dbms_output.put_line(’WRONG PARAMETER: ’ || par);

        Watch for interferences from null values!




Porting Oracle Applications to PostgreSQL: 60 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Backtraces




                orafce provides dbms_utility.format_call_stack()
                impossible to implement
                dbms_utility.format_error_stack() in PostgreSQL
                (except by patching PL/pgSQL directly)




Porting Oracle Applications to PostgreSQL: 61 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   What About PL/Java?




                Should be compatible with SQL/JRT and Oracle
                Basic functionality should work without changes
                Reality is more complex
                There is little or no experience with this scenario.




Porting Oracle Applications to PostgreSQL: 62 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 63 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   psql/sqlplus




                psql is much nicer for interactive use. :-)
                sqlplus is much nicer for scripting use. :-(
                With use of variables and naming conventions, sqlplus scripts
                can be converted anyway.
                Consider a wholesale rewrite.




Porting Oracle Applications to PostgreSQL: 64 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Backup, Recovery




        Build a new system using transaction log archiving or SQL dumps.




Porting Oracle Applications to PostgreSQL: 65 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Setup, initdb




                Works completely differently.
                Forget everything you get from Oracle.
                Write new setup scripts that integrate well with the operating
                system.
                Forget about tablespaces, partitioning, OS tuning, etc. until
                you have a porting result.




Porting Oracle Applications to PostgreSQL: 66 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   JDBC




        Works great, aside from SQL syntax issues




Porting Oracle Applications to PostgreSQL: 67 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Outline


        1    Porting the SQL

        2    Porting Tools

        3    PL/SQL vs. PL/pgSQL

        4    Interfaces

        5    Project Management




Porting Oracle Applications to PostgreSQL: 68 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Testing




        Have a test suite for:
                functions
                setup
                tables/database contents




Porting Oracle Applications to PostgreSQL: 69 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Dividing the Work




                In PL/SQL-heavy applications, you can usually divide the
                work by function or package.
                Someone needs to drive and monitor integration work.
                Have a test suite.




Porting Oracle Applications to PostgreSQL: 70 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Long-Term Maintenance




                Will the original application continue to be developed?
                . . . while the porting project runs?!?
                How is the merging going to work?
                One time ports, maintainable ports, and mergeable ports are
                all slightly different.




Porting Oracle Applications to PostgreSQL: 71 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Code Formatting




                Create a code formatting standard.
                (This applies to any development project.)
                I tend to stick with the original layout.
                This is important for later updates, merges, and maintenance.




Porting Oracle Applications to PostgreSQL: 72 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Version Control




                Use version control, even if the client doesn’t.
                Prefer to use your own VCS; merge later.




Porting Oracle Applications to PostgreSQL: 73 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Beyond the SQL



                Applications also contain setup and maintenance scripts.
                These were typically written by old-school Oracle
                administrators.
                Hence completely incomprehensible and written in ksh
                Half the logic usually doesn’t make sense for PostgreSQL.
                Half the logic required to make PostgreSQL work will not
                have been written yet.
        Reserve plenty of time for dealing with this.




Porting Oracle Applications to PostgreSQL: 74 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Legacy Code and Legacy Environments



                Applications to be ported are usually very old and crufty.
                This multiplies the time required to deal with them.
                A lot of the code won’t compile/run on newer operating
                systems.
                Half your tools won’t compile/run on the old operating
                system.
                Everything is locked down, so you can’t do anything about
                this.
        Evaluate this carefully before starting the project.




Porting Oracle Applications to PostgreSQL: 75 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Client Participation



                Almost always, the database clients will need to be adjusted.
                Almost always, you need someone reachable who understands
                the code.
                Clients think SQL code is a black box with a clean and simple
                interface.
                In practice, a port is like a major new software release.
                A port affects your entire system.
        The client must be willing, able, and available to participate in the
        project.




Porting Oracle Applications to PostgreSQL: 76 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   “Josh’s Rules (of Database Contracting)”



        http://blogs.ittoolbox.com/database/soup/archives/
        joshs-rules-of-database-contracting-17253
                Learn them by heart.
                Print them out.
                Post them at your office door.
                Quote them to the sales people.




Porting Oracle Applications to PostgreSQL: 77 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Contribute Your Improvements




                Porting projects are a great source of ideas for features and
                bug fixes.
                Record your experiences, e. g., in the wiki.
                Contribute to orafce and ora2pg.
                Contribute to PL/pgSQL and PL/Java.




Porting Oracle Applications to PostgreSQL: 78 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Coincidence?




        If you need help:
                  Oracle Ask Tom: http://asktom.oracle.com/
         PostgreSQL Ask Tom: tgl@sss.pgh.pa.us




Porting Oracle Applications to PostgreSQL: 79 / 80
Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management

   Fly Way to Conclude SQL-Themed Presentation




                                                     COMMIT;




Porting Oracle Applications to PostgreSQL: 80 / 80

More Related Content

What's hot

Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...timfanelli
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPGConf APAC
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...Alex Zaballa
 
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...Cloudera, Inc.
 
Ordina Oracle Open World
Ordina Oracle Open WorldOrdina Oracle Open World
Ordina Oracle Open WorldMarco Gralike
 
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Toronto-Oracle-Users-Group
 
An AMIS Overview of Oracle database 12c (12.1)
An AMIS Overview of Oracle database 12c (12.1)An AMIS Overview of Oracle database 12c (12.1)
An AMIS Overview of Oracle database 12c (12.1)Marco Gralike
 
Talend Open Studio For Data Integration Training Curriculum
Talend Open Studio For Data Integration Training CurriculumTalend Open Studio For Data Integration Training Curriculum
Talend Open Studio For Data Integration Training CurriculumBharat Khanna
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2Gal Marder
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cTanel Poder
 
Designing and Testing Accumulo Iterators
Designing and Testing Accumulo IteratorsDesigning and Testing Accumulo Iterators
Designing and Testing Accumulo IteratorsJosh Elser
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a clusterGal Marder
 
Design Concepts For Xml Applications That Will Perform
Design Concepts For Xml Applications That Will PerformDesign Concepts For Xml Applications That Will Perform
Design Concepts For Xml Applications That Will PerformMarco Gralike
 
Oracle & sql server comparison 2
Oracle & sql server comparison 2Oracle & sql server comparison 2
Oracle & sql server comparison 2Mohsen B
 
MySQL 8.0 Optimizer Guide
MySQL 8.0 Optimizer GuideMySQL 8.0 Optimizer Guide
MySQL 8.0 Optimizer GuideMorgan Tocker
 
ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3DataWorks Summit
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharmaaioughydchapter
 
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2Dobler Consulting
 

What's hot (20)

Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
Three Key Concepts for Understanding JSR-352: Batch Programming for the Java ...
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata  Expr...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expr...
 
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
Friction-free ETL: Automating data transformation with Impala | Strata + Hado...
 
Ordina Oracle Open World
Ordina Oracle Open WorldOrdina Oracle Open World
Ordina Oracle Open World
 
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?Extreme Availability using Oracle 12c Features: Your very last system shutdown?
Extreme Availability using Oracle 12c Features: Your very last system shutdown?
 
An AMIS Overview of Oracle database 12c (12.1)
An AMIS Overview of Oracle database 12c (12.1)An AMIS Overview of Oracle database 12c (12.1)
An AMIS Overview of Oracle database 12c (12.1)
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
Talend Open Studio For Data Integration Training Curriculum
Talend Open Studio For Data Integration Training CurriculumTalend Open Studio For Data Integration Training Curriculum
Talend Open Studio For Data Integration Training Curriculum
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12c
 
Designing and Testing Accumulo Iterators
Designing and Testing Accumulo IteratorsDesigning and Testing Accumulo Iterators
Designing and Testing Accumulo Iterators
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
Design Concepts For Xml Applications That Will Perform
Design Concepts For Xml Applications That Will PerformDesign Concepts For Xml Applications That Will Perform
Design Concepts For Xml Applications That Will Perform
 
Oracle & sql server comparison 2
Oracle & sql server comparison 2Oracle & sql server comparison 2
Oracle & sql server comparison 2
 
MySQL 8.0 Optimizer Guide
MySQL 8.0 Optimizer GuideMySQL 8.0 Optimizer Guide
MySQL 8.0 Optimizer Guide
 
ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3ORC improvement in Apache Spark 2.3
ORC improvement in Apache Spark 2.3
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2
A Practitioner's Guide to Successfully Migrate from Oracle to Sybase ASE Part 2
 

Viewers also liked

Migrating from Oracle to Postgres
Migrating from Oracle to PostgresMigrating from Oracle to Postgres
Migrating from Oracle to PostgresEDB
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLPGConf APAC
 
Most Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL FeaturesMost Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL FeaturesPeter Eisentraut
 
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle Ashnikbiz
 
DBaaS with EDB Postgres on AWS
DBaaS with EDB Postgres on AWSDBaaS with EDB Postgres on AWS
DBaaS with EDB Postgres on AWSEDB
 
Key Methodologies for Migrating from Oracle to Postgres
Key Methodologies for Migrating from Oracle to PostgresKey Methodologies for Migrating from Oracle to Postgres
Key Methodologies for Migrating from Oracle to PostgresEDB
 

Viewers also liked (7)

Migrating from Oracle to Postgres
Migrating from Oracle to PostgresMigrating from Oracle to Postgres
Migrating from Oracle to Postgres
 
Migration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQLMigration From Oracle to PostgreSQL
Migration From Oracle to PostgreSQL
 
Autonomous transaction
Autonomous transactionAutonomous transaction
Autonomous transaction
 
Most Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL FeaturesMost Wanted: Future PostgreSQL Features
Most Wanted: Future PostgreSQL Features
 
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
 
DBaaS with EDB Postgres on AWS
DBaaS with EDB Postgres on AWSDBaaS with EDB Postgres on AWS
DBaaS with EDB Postgres on AWS
 
Key Methodologies for Migrating from Oracle to Postgres
Key Methodologies for Migrating from Oracle to PostgresKey Methodologies for Migrating from Oracle to Postgres
Key Methodologies for Migrating from Oracle to Postgres
 

Similar to Porting Oracle Applications to PostgreSQL

Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPeter Eisentraut
 
PostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesPostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesAll Things Open
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5Pranab Dasgupta
 
Intro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationIntro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationPhilip Yurchuk
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9google
 
Boulder/Denver BigData: Cluster Computing with Apache Mesos and Cascading
Boulder/Denver BigData: Cluster Computing with Apache Mesos and CascadingBoulder/Denver BigData: Cluster Computing with Apache Mesos and Cascading
Boulder/Denver BigData: Cluster Computing with Apache Mesos and CascadingPaco Nathan
 
shibindas_Plsql2year
shibindas_Plsql2yearshibindas_Plsql2year
shibindas_Plsql2yearshibindas pk
 
Oracle Application Express 20.2 New Features
Oracle Application Express 20.2 New FeaturesOracle Application Express 20.2 New Features
Oracle Application Express 20.2 New Featuresmsewtz
 
App Load Presentation 2009
App Load Presentation 2009App Load Presentation 2009
App Load Presentation 2009sundu72
 
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...mahdi ahmadi
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB graphdevroom
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Holden Karau
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming LanguagesS.Shayan Daneshvar
 

Similar to Porting Oracle Applications to PostgreSQL (20)

Porting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQLPorting Applications From Oracle To PostgreSQL
Porting Applications From Oracle To PostgreSQL
 
PostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real DifferencesPostgreSQL versus MySQL - What Are The Real Differences
PostgreSQL versus MySQL - What Are The Real Differences
 
naiditch_resume_APR10
naiditch_resume_APR10naiditch_resume_APR10
naiditch_resume_APR10
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
 
Intro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationIntro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data Integration
 
Shrikanth
ShrikanthShrikanth
Shrikanth
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Boulder/Denver BigData: Cluster Computing with Apache Mesos and Cascading
Boulder/Denver BigData: Cluster Computing with Apache Mesos and CascadingBoulder/Denver BigData: Cluster Computing with Apache Mesos and Cascading
Boulder/Denver BigData: Cluster Computing with Apache Mesos and Cascading
 
shibindas_Plsql2year
shibindas_Plsql2yearshibindas_Plsql2year
shibindas_Plsql2year
 
Oracle Application Express 20.2 New Features
Oracle Application Express 20.2 New FeaturesOracle Application Express 20.2 New Features
Oracle Application Express 20.2 New Features
 
App Load Presentation 2009
App Load Presentation 2009App Load Presentation 2009
App Load Presentation 2009
 
Hadoop ecosystem
Hadoop ecosystemHadoop ecosystem
Hadoop ecosystem
 
Plpgsql russia-pgconf
Plpgsql russia-pgconfPlpgsql russia-pgconf
Plpgsql russia-pgconf
 
Database programming
Database programmingDatabase programming
Database programming
 
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...
Oracle restful api & data live charting by Oracle Apex - داشبورد آنلاین (داده...
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018
 
Advanced SQL - Database Access from Programming Languages
Advanced SQL - Database Access  from Programming LanguagesAdvanced SQL - Database Access  from Programming Languages
Advanced SQL - Database Access from Programming Languages
 

More from Peter Eisentraut

Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/ProxyPeter Eisentraut
 
Linux distribution for the cloud
Linux distribution for the cloudLinux distribution for the cloud
Linux distribution for the cloudPeter Eisentraut
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and DevelopmentPeter Eisentraut
 
PostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie DatenbankalternativePostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie DatenbankalternativePeter Eisentraut
 
The Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future DevelopmentsThe Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future DevelopmentsPeter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsPeter Eisentraut
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQLPeter Eisentraut
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsPeter Eisentraut
 
Docbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XMLDocbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XMLPeter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...Peter Eisentraut
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...Peter Eisentraut
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)Peter Eisentraut
 
The Lives of Others: Open-Source Development Practices Elsewhere
The Lives of Others: Open-Source Development Practices ElsewhereThe Lives of Others: Open-Source Development Practices Elsewhere
The Lives of Others: Open-Source Development Practices ElsewherePeter Eisentraut
 

More from Peter Eisentraut (20)

Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
 
Linux distribution for the cloud
Linux distribution for the cloudLinux distribution for the cloud
Linux distribution for the cloud
 
PostgreSQL and XML
PostgreSQL and XMLPostgreSQL and XML
PostgreSQL and XML
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
 
PostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie DatenbankalternativePostgreSQL: Die Freie Datenbankalternative
PostgreSQL: Die Freie Datenbankalternative
 
The Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future DevelopmentsThe Road to the XML Type: Current and Future Developments
The Road to the XML Type: Current and Future Developments
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Replication Solutions for PostgreSQL
Replication Solutions for PostgreSQLReplication Solutions for PostgreSQL
Replication Solutions for PostgreSQL
 
PostgreSQL News
PostgreSQL NewsPostgreSQL News
PostgreSQL News
 
PostgreSQL News
PostgreSQL NewsPostgreSQL News
PostgreSQL News
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
 
Docbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XMLDocbook: Textverarbeitung mit XML
Docbook: Textverarbeitung mit XML
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail Sy...
 
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...Collateral Damage:
Consequences of Spam and Virus Filtering for the E-Mail S...
Collateral Damage: Consequences of Spam and Virus Filtering for the E-Mail S...
 
Spaß mit PostgreSQL
Spaß mit PostgreSQLSpaß mit PostgreSQL
Spaß mit PostgreSQL
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)
 
SQL/MED and PostgreSQL
SQL/MED and PostgreSQLSQL/MED and PostgreSQL
SQL/MED and PostgreSQL
 
The Lives of Others: Open-Source Development Practices Elsewhere
The Lives of Others: Open-Source Development Practices ElsewhereThe Lives of Others: Open-Source Development Practices Elsewhere
The Lives of Others: Open-Source Development Practices Elsewhere
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Porting Oracle Applications to PostgreSQL

  • 1. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Porting Oracle Applications to PostgreSQL Peter Eisentraut, credativ GmbH / credativ Ltd. PGCon 2008 Porting Oracle Applications to PostgreSQL: 1 / 80
  • 2. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Disclaimers This presentation was written by a PostgreSQL expert, not an Oracle expert. Both Oracle and PostgreSQL are diverse, complex, and moving targets. Both Oracle and PostgreSQL are (probably) Turing-complete, so almost anything is “possible”, but we are looking for reasonable options. Porting Oracle Applications to PostgreSQL: 2 / 80
  • 3. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management You Will See . . . Porting projects are hard. Compatibility and compatibility layers are an illusion. It might be better not to do it. But success can be very rewarding. Porting Oracle Applications to PostgreSQL: 3 / 80
  • 4. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 4 / 80
  • 5. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 5 / 80
  • 6. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Syntax Identifiers Oracle case folds to upper case, PostgreSQL to lower case. Big trouble if you mix quoted and unquoted identifiers. Column aliases SELECT foo [AS] bar — Most Oracle applications omit the AS, but PostgreSQL requires it. Fixed in PostgreSQL 8.4. MINUS Change to EXCEPT. SQL key words Usually not a big problem, but should be kept in mind. “FROM dual” Easy to work around (or use orafce). Porting Oracle Applications to PostgreSQL: 6 / 80
  • 7. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Table Definition The usual features are mostly the same: columns, constraints, defaults. Data types are more work; see below. No fancy features like “table of type”. Porting Oracle Applications to PostgreSQL: 7 / 80
  • 8. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Data Types: General Both Oracle and PostgreSQL support plenty of SQL-conforming data types. But usually the nonconforming ones are in wider use. Thin compatibility layers can usually help, but that will make your PostgreSQL application unpretty. A big search-and-replace is usually in order. Porting Oracle Applications to PostgreSQL: 8 / 80
  • 9. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Data Types: Specifics varchar2 → varchar or text clob, long → varchar or text nchar, 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 (additional porting required) date → date or timestamp Porting Oracle Applications to PostgreSQL: 9 / 80
  • 10. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Null Values Infamous Oracle behavior: NULL = ’’ Consequently, ’’ = ’’ is not true Completely weird and inconsistent Usually, your data will just disappear in PostgreSQL transform_null_equals does not help here If your application relies on any of this, you are in trouble. Porting Oracle Applications to PostgreSQL: 10 / 80
  • 11. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Functions: General Function compatibility is a bottomless pit. PostgreSQL (+ orafce) supports many Oracle compatibility functions. It’s easy to write your own. Only the special syntax is trouble. Porting Oracle Applications to PostgreSQL: 11 / 80
  • 12. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Functions: Compatibility For example, the following common functions are supported by PostgreSQL as well: substr to char nvl, nullif (orafce) Porting Oracle Applications to PostgreSQL: 12 / 80
  • 13. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Functions: Specifics Manual work required here: sysdate → current_timestamp or localtimestamp Porting Oracle Applications to PostgreSQL: 13 / 80
  • 14. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Functions: decode DECODE(expr, search, expr[, search, expr...] [, default]) becomes CASE WHEN expr THEN search .. ELSE default END Porting Oracle Applications to PostgreSQL: 14 / 80
  • 15. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Default Parameters: Overview PostgreSQL supports neither default values for parameters nor named parameters in function calls. Oracle applications make ample use of both. Porting Oracle Applications to PostgreSQL: 15 / 80
  • 16. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Default Parameters: The Easy Case 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) $$; Porting Oracle Applications to PostgreSQL: 16 / 80
  • 17. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Default Parameters: The Hard Case CREATE FUNCTION foo (a int, b int = 5, c int = 0) ... This is only callable with named parameters. PostgreSQL doesn’t support this. You will have to change your client application. Your project time will double. Porting Oracle Applications to PostgreSQL: 17 / 80
  • 18. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Default Parameters: Conclusion Approx. 97% of applications to be ported contain issues like this. Client code must be reworked. Adding this support in PostgreSQL would be a great feature. Porting Oracle Applications to PostgreSQL: 18 / 80
  • 19. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Sequences: Creating Sequences are somewhat compatible . . . Change NOCACHE to CACHE 1 (or omit). MAXVALUE 9999999999999999999999999 needs to be reduced. Don’t rely on the caching behavior. Porting Oracle Applications to PostgreSQL: 19 / 80
  • 20. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Sequences: Using Oracle syntax: sequence_name.nextval PostgreSQL syntax: nextval(’sequence_name’) Search-and-replace; but direct sequence calls are rare. Porting Oracle Applications to PostgreSQL: 20 / 80
  • 21. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outer Joins: Overview PostgreSQL only supports the SQL-standard outer join syntax. Oracle supports it since version 9. Most Oracle code uses the old, Oracle-specific syntax. Porting is usually straightforward, but requires manual work. Set up test queries to catch porting mistakes. Porting Oracle Applications to PostgreSQL: 21 / 80
  • 22. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outer Joins: Simple Example SELECT * FROM a, b WHERE a.x = b.y(+) becomes SELECT * FROM a LEFT JOIN b ON a.x = b.y Porting Oracle Applications to PostgreSQL: 22 / 80
  • 23. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outer Joins: Complex Example SELECT ... FROM A, B, C WHERE A.A_ID (+) = B.A_ID AND C.C_KEY(+) = B.C_KEY becomes SELECT ... FROM A RIGHT JOIN B ON (A.A_ID = B.A_ID) LEFT JOIN C ON (C.C_KEY = B.C_KEY) Porting Oracle Applications to PostgreSQL: 23 / 80
  • 24. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outer Joins: Unclear Example SELECT ... FROM A, B, C, D, E WHERE A.A_ID = B.A_ID AND B.B_ID = C.A_ID(+) AND B.B_KEY = C.B_KEY(+) AND C.C_ID = D.C_ID(+) AND B.A_ID = E.A_ID(+) AND B.B_KEY = E.B_KEY(+) AND ’CONSTANT’ = C.X_ID(+) What’s that??? Porting Oracle Applications to PostgreSQL: 24 / 80
  • 25. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Locking Transaction isolation, locking, SELECT FOR UPDATE behave pretty much the same. Oracle also defaults to read committed. Usually, no one at the client has ever heard of concurrency issues, so the code is likely buggy anyway. Porting Oracle Applications to PostgreSQL: 25 / 80
  • 26. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Indexes Basic syntax the same: CREATE INDEX name ON table (a, b) Primary keys and unique constraints are automatically indexed. Other features are implementation-specific. You will have to re-tune the entire porting result anyway. Porting Oracle Applications to PostgreSQL: 26 / 80
  • 27. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Optimizer Hints Delete them Or keep them for future investigation Usually useless Porting Oracle Applications to PostgreSQL: 27 / 80
  • 28. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Date Formatting TO_CHAR is largely compatible. Warning: PostgreSQL version is not very robust. One-argument variant provided by orafce NLS_DATE_FORMAT is replaced by locale settings. Porting Oracle Applications to PostgreSQL: 28 / 80
  • 29. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Date Arithmetic Usually, date arithmetic is easier in PostgreSQL, so consider a small code rewrite. orafce provides compatibility functions, such as last_day, add_months. Oracle code often does date + int . . . In PostgreSQL, this may become timestamp + int. This doesn’t work. Write a custom operator or rewrite the code. Porting Oracle Applications to PostgreSQL: 29 / 80
  • 30. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Encodings Both Oracle and PostgreSQL support the same ideas. But everything is named differently. Might be a good time to review the encoding and locale choices. Porting Oracle Applications to PostgreSQL: 30 / 80
  • 31. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management NLS * vs. LC * Approximate analogies: NLS CALENDAR — NLS COMP lc collate = ’C’ NLS CURRENCY lc monetary NLS DATE FORMAT DateStyle NLS DATE LANGUAGE lc messages, lc time (8.4?) NLS LANG, NLS LANGUAGE LANG, client encoding NLS NCHAR — NLS NUMERIC CHARACTERS lc numeric NLS SORT lc collate NLS TERRITORY LANG, lc * Porting Oracle Applications to PostgreSQL: 31 / 80
  • 32. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management ROWNUM and ROWID ROWNUM: Use generate_series, or Rewrite and apply LIMIT, or Just handle in the client ROWID: Analogous to ctid Good code should usually not use this. That does not prevent some from trying. Porting Oracle Applications to PostgreSQL: 32 / 80
  • 33. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management XML (untested!) xmltype → xml extract → xpath XMLELEMENT, XMLATTRIBUTES, etc. are the same. Most functionality is different or missing in PostgreSQL. Porting Oracle Applications to PostgreSQL: 33 / 80
  • 34. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Triggers: Declarations Oracle uses inline trigger actions: 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(); Note: FOR EACH STATEMENT is the default in Oracle and PostgreSQL. Porting Oracle Applications to PostgreSQL: 34 / 80
  • 35. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Triggers: Column-Level Triggers Oracle supports column-level triggers: CREATE TRIGGER foo BEFORE UPDATE OF column ON table AS BEGIN ... END; becomes CREATE OR REPLACE FUNCTION foo_tg() RETURNS TRIGGER LANGUAGE xxx AS $$ BEGIN IF NEW.column IS NOT DISTINCT FROM OLD.column THEN RETURN NEW; END IF; ... -- normal code END; $$; CREATE TRIGGER foo AFTER action ON table EXECUTE PROCEDURE foo_tg(); But this doesn’t catch updates to the same value. You will need to make a choice which behavior you need. Porting Oracle Applications to PostgreSQL: 35 / 80
  • 36. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Things That Won’t Work Directly CONNECT BY Try contrib/tablefunc. Materialized views Write your own wrapper. Snapshots Write your own wrapper. Database links Use contrib/dblink plus views. Autonomous transactions Try dblink. Synonyms Try views or wrapper or schema path. Partitioning Write your own system. Porting Oracle Applications to PostgreSQL: 36 / 80
  • 37. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 37 / 80
  • 38. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management orafce http://orafce.projects.postgresql.org/ Large set of Oracle compatibility functions “dual” table Debian and RPM packages available Invaluable Porting Oracle Applications to PostgreSQL: 38 / 80
  • 39. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management ora2pg http://ora2pg.projects.postgresql.org/ Converts Oracle schema definitions Extracts data from Oracle database for import into PostgreSQL Packages available Invaluable Porting Oracle Applications to PostgreSQL: 39 / 80
  • 40. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management TOra http://tora.sourceforge.net/ GUI for PostgreSQL and Oracle Contains exploration and debugging facilities for Oracle Packages available, but usually without Oracle support Generally a bit outdated, but good for this purpose Porting Oracle Applications to PostgreSQL: 40 / 80
  • 41. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management DBD::Oracle http://search.cpan.org/dist/DBD-Oracle/ Needed for ora2pg Also helpful for test scripts etc. Building it can be challenging Debian and RPM packages available Porting Oracle Applications to PostgreSQL: 41 / 80
  • 42. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Oracle Instant Client Needed for DBD::Oracle and TOra Also contains sqlplus download from Oracle Porting Oracle Applications to PostgreSQL: 42 / 80
  • 43. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Oracle Database Express Edition Use this for testing if you have no other Oracle instance. download from Oracle Porting Oracle Applications to PostgreSQL: 43 / 80
  • 44. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 44 / 80
  • 45. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management From PL/SQL to PL/pgSQL Compatibility isn’t that great, but it’s obviously the best choice. The PL/pgSQL parser is DAAB. See also http://www.postgresql.org/docs/current/ static/plpgsql-porting.html. Porting Oracle Applications to PostgreSQL: 45 / 80
  • 46. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Function Creation CREATE FUNCTION ... RETURN type becomes CREATE FUNCTION ... RETURNS type Function body must be quoted (dollar quoting). Various other details are incompatible: LANGUAGE STRICT, STABLE, etc. For variable declarations, DECLARE is needed in PostgreSQL. Porting Oracle Applications to PostgreSQL: 46 / 80
  • 47. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Syntax Differences FOR i IN REVERSE 1..10 LOOP — Order must be switched for PostgreSQL. Porting Oracle Applications to PostgreSQL: 47 / 80
  • 48. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Variables PL/SQL can distinguish column names and variable names. PL/pgSQL replaces all matching tokens by variables. Find a namespacing mechanism to tell apart variables, parameters, and columns. Porting Oracle Applications to PostgreSQL: 48 / 80
  • 49. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Packages Use schemas to group your functions. Call syntax is about the same. But there is no equivalent public/private mechanism. Porting Oracle Applications to PostgreSQL: 49 / 80
  • 50. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Package Variables Not supported by PostgreSQL Write a wrapper based on (temporary) tables. Porting Oracle Applications to PostgreSQL: 50 / 80
  • 51. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Cursors Usually, you need less cursors in PostgreSQL. CURSOR foo IS SELECT ...; BEGIN FOR x IN foo LOOP can be simplified to BEGIN FOR x IN SELECT ... LOOP Note: The x is defined implicitly in Oracle. In PostgreSQL, you need to declare it. Porting Oracle Applications to PostgreSQL: 51 / 80
  • 52. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Cursors Variables This doesn’t work in PostgreSQL: CURSOR foo IS SELECT ...; x foo%ROWTYPE; BEGIN FOR x IN foo LOOP Use RECORD: DECLARE CURSOR foo IS SELECT ..; x RECORD; BEGIN FOR x IN foo LOOP Porting Oracle Applications to PostgreSQL: 52 / 80
  • 53. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management PERFORM In PostgreSQL, “procedure” calls must start with PERFORM. E. g., service.put_utl(’Error’); becomes PERFORM service.put_utl(’Error’); Porting Oracle Applications to PostgreSQL: 53 / 80
  • 54. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management EXECUTE For DDL statements, EXECUTE might be necessary. E. g., EXECUTE ’CREATE TABLE ’ || quote_ident(foo) || ... Porting Oracle Applications to PostgreSQL: 54 / 80
  • 55. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Subcommits Code that does COMMIT or ROLLBACK needs major, client-side changes. (Savepoints won’t usually do the job.) Porting Oracle Applications to PostgreSQL: 55 / 80
  • 56. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Exceptions (1) An exception rolls back all changes implicitly in PostgreSQL. You can drop most savepoint-using code from the Oracle version. More complex behavior needs a redesign. Porting Oracle Applications to PostgreSQL: 56 / 80
  • 57. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Exceptions (2) Exception block syntax is the same. Exception names are different. Oracle supports user-defined exception names. Error codes are different. Variable SQLERRM is available. Of course, error messages are also different. Porting Oracle Applications to PostgreSQL: 57 / 80
  • 58. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Exceptions (3) We use a scheme to encode exception information into the message string: RAISE name; ---> RAISE EXCEPTION ’name’; Similar for error codes: raise_application_error(12345, ’msg’); ---> RAISE EXCEPTION ’+12345:msg’; Codes can be positive or negative. Write a wrapper function. errcode := substr(SQLERRM, 1, 6) Porting Oracle Applications to PostgreSQL: 58 / 80
  • 59. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management No Data Found Exceptions Oracle throws NO_DATA_FOUND exceptions for SELECT INSERT UPDATE DELETE PostgreSQL only for: SELECT INTO STRICT Use IF NOT FOUND to deal with other cases. Porting Oracle Applications to PostgreSQL: 59 / 80
  • 60. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Logging dbms_output “package” is provided by orafce. E. g. dbms_output.put_line(’WRONG PARAMETER: ’ || par); Watch for interferences from null values! Porting Oracle Applications to PostgreSQL: 60 / 80
  • 61. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Backtraces orafce provides dbms_utility.format_call_stack() impossible to implement dbms_utility.format_error_stack() in PostgreSQL (except by patching PL/pgSQL directly) Porting Oracle Applications to PostgreSQL: 61 / 80
  • 62. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management What About PL/Java? Should be compatible with SQL/JRT and Oracle Basic functionality should work without changes Reality is more complex There is little or no experience with this scenario. Porting Oracle Applications to PostgreSQL: 62 / 80
  • 63. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 63 / 80
  • 64. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management psql/sqlplus psql is much nicer for interactive use. :-) sqlplus is much nicer for scripting use. :-( With use of variables and naming conventions, sqlplus scripts can be converted anyway. Consider a wholesale rewrite. Porting Oracle Applications to PostgreSQL: 64 / 80
  • 65. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Backup, Recovery Build a new system using transaction log archiving or SQL dumps. Porting Oracle Applications to PostgreSQL: 65 / 80
  • 66. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Setup, initdb Works completely differently. Forget everything you get from Oracle. Write new setup scripts that integrate well with the operating system. Forget about tablespaces, partitioning, OS tuning, etc. until you have a porting result. Porting Oracle Applications to PostgreSQL: 66 / 80
  • 67. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management JDBC Works great, aside from SQL syntax issues Porting Oracle Applications to PostgreSQL: 67 / 80
  • 68. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Outline 1 Porting the SQL 2 Porting Tools 3 PL/SQL vs. PL/pgSQL 4 Interfaces 5 Project Management Porting Oracle Applications to PostgreSQL: 68 / 80
  • 69. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Testing Have a test suite for: functions setup tables/database contents Porting Oracle Applications to PostgreSQL: 69 / 80
  • 70. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Dividing the Work In PL/SQL-heavy applications, you can usually divide the work by function or package. Someone needs to drive and monitor integration work. Have a test suite. Porting Oracle Applications to PostgreSQL: 70 / 80
  • 71. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Long-Term Maintenance Will the original application continue to be developed? . . . while the porting project runs?!? How is the merging going to work? One time ports, maintainable ports, and mergeable ports are all slightly different. Porting Oracle Applications to PostgreSQL: 71 / 80
  • 72. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Code Formatting Create a code formatting standard. (This applies to any development project.) I tend to stick with the original layout. This is important for later updates, merges, and maintenance. Porting Oracle Applications to PostgreSQL: 72 / 80
  • 73. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Version Control Use version control, even if the client doesn’t. Prefer to use your own VCS; merge later. Porting Oracle Applications to PostgreSQL: 73 / 80
  • 74. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Beyond the SQL Applications also contain setup and maintenance scripts. These were typically written by old-school Oracle administrators. Hence completely incomprehensible and written in ksh Half the logic usually doesn’t make sense for PostgreSQL. Half the logic required to make PostgreSQL work will not have been written yet. Reserve plenty of time for dealing with this. Porting Oracle Applications to PostgreSQL: 74 / 80
  • 75. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Legacy Code and Legacy Environments Applications to be ported are usually very old and crufty. This multiplies the time required to deal with them. A lot of the code won’t compile/run on newer operating systems. Half your tools won’t compile/run on the old operating system. Everything is locked down, so you can’t do anything about this. Evaluate this carefully before starting the project. Porting Oracle Applications to PostgreSQL: 75 / 80
  • 76. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Client Participation Almost always, the database clients will need to be adjusted. Almost always, you need someone reachable who understands the code. Clients think SQL code is a black box with a clean and simple interface. In practice, a port is like a major new software release. A port affects your entire system. The client must be willing, able, and available to participate in the project. Porting Oracle Applications to PostgreSQL: 76 / 80
  • 77. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management “Josh’s Rules (of Database Contracting)” http://blogs.ittoolbox.com/database/soup/archives/ joshs-rules-of-database-contracting-17253 Learn them by heart. Print them out. Post them at your office door. Quote them to the sales people. Porting Oracle Applications to PostgreSQL: 77 / 80
  • 78. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Contribute Your Improvements Porting projects are a great source of ideas for features and bug fixes. Record your experiences, e. g., in the wiki. Contribute to orafce and ora2pg. Contribute to PL/pgSQL and PL/Java. Porting Oracle Applications to PostgreSQL: 78 / 80
  • 79. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Coincidence? If you need help: Oracle Ask Tom: http://asktom.oracle.com/ PostgreSQL Ask Tom: tgl@sss.pgh.pa.us Porting Oracle Applications to PostgreSQL: 79 / 80
  • 80. Porting the SQL Porting Tools PL/SQL vs. PL/pgSQL Interfaces Project Management Fly Way to Conclude SQL-Themed Presentation COMMIT; Porting Oracle Applications to PostgreSQL: 80 / 80