Porting Oracle Applications To PostgreSQL
Porting Oracle Applications To PostgreSQL
PGCon 2008
Disclaimers
Outline
2 Porting Tools
4 Interfaces
5 Project Management
Outline
2 Porting Tools
4 Interfaces
5 Project Management
Syntax
Table Definition
Null Values
Functions: General
Functions: Compatibility
Functions: Specifics
Functions: decode
becomes
becomes
Sequences: Creating
Sequences: Using
becomes
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)
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???
Locking
Indexes
Optimizer Hints
Delete them
Or keep them for future investigation
Usually useless
Date Formatting
Date Arithmetic
Encodings
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 *
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.
XML
(untested!)
xmltype → xml
extract → xpath
XMLELEMENT, XMLATTRIBUTES, etc. are the same.
Most functionality is different or missing in PostgreSQL.
Triggers: Declarations
becomes
Outline
2 Porting Tools
4 Interfaces
5 Project Management
orafce
http://orafce.projects.postgresql.org/
Large set of Oracle compatibility functions
“dual” table
Debian and RPM packages available
Invaluable
ora2pg
http://ora2pg.projects.postgresql.org/
Converts Oracle schema definitions
Extracts data from Oracle database for import into
PostgreSQL
Packages available
Invaluable
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
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
Outline
2 Porting Tools
4 Interfaces
5 Project Management
Function Creation
Syntax Differences
Variables
Packages
Package Variables
Cursors
BEGIN
FOR x IN foo LOOP
can be simplified to
BEGIN
FOR x IN SELECT ... LOOP
Cursors Variables
This doesn’t work in PostgreSQL:
BEGIN
FOR x IN foo LOOP
Use RECORD:
DECLARE
CURSOR foo IS SELECT ..;
x RECORD;
BEGIN
FOR x IN foo LOOP
PERFORM
service.put_utl(’Error’);
becomes
PERFORM service.put_utl(’Error’);
EXECUTE
Subcommits
Exceptions (1)
Exceptions (2)
Exceptions (3)
raise_application_error(12345, ’msg’);
---> RAISE EXCEPTION ’+12345:msg’;
errcode := substr(SQLERRM, 1, 6)
Logging
Backtraces
Outline
2 Porting Tools
4 Interfaces
5 Project Management
psql/sqlplus
Backup, Recovery
Setup, initdb
JDBC
Outline
2 Porting Tools
4 Interfaces
5 Project Management
Testing
Long-Term Maintenance
Code Formatting
Version Control
Client Participation
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.
Coincidence?
COMMIT;