Upload
radian-adhi-c
View
239
Download
0
Embed Size (px)
Citation preview
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 1/58
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 2/58
Agenda
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 3/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 4/58
Schema Migration
A.K.A “User” in Oracle
Oracle gives every user her own schema, by default
Names of schema, tables, columns, functions, …
Oracle converts them to UPPER CASE, unless quoted
Postgres converts them to lower case, unless quoted
You're safe if application quotes/does not quote the identifiers
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 5/58
Schema Migration
CREATE TABLE is mostly compatible, except
Virtual Columns: Use views
Data Types <discussed separately>
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 6/58
Schema Migration
Primary Key, Foreign Key, Unique, CHECK, NOT NULL
Btree / Descending: Works
Reverse Key / Bitmap / Join: Not implemented (yet)
Global: Feature not available
Hash, List, Range
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 7/58
Schema Migration
Not really the same thing as Oracle, but serves the same purpose
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 8/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 9/58
Data Type Migration
Convert to VARCHAR or TEXT
Convert to CHAR
Convert to VARCHAR or TEXT
Totally transparent to application.
Size limit 2^30-1 (1 GB)
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 10/58
Data Type Migration
BIGINT, INT, SMALLINT, REAL, REAL, DOUBLE PRECISION
NUMERIC
Convert to INTEGER, FLOAT, …
Convert to BYTEA; requires additional work in applicationmigration
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 11/58
Data Type Migration
DATE or TIMESTAMP
Also consider timezone effects; TIMESTAMP WITH TIMEZONE
DATE + integer
ORAFCE provides last_day, add_months, … TIMESTAMP – TIMESTAMP: Oracle: NUMBER, Postgres: INTERVAL
Controls output of TO_CHAR and TO_DATE functions
In Postgres, controlled by locale settings
Note: DateStyle GUC variable
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 12/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 13/58
Data Migration
Use GUI tools
Use ETL style
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 14/58
Data Migration
Extract sequence_name.nextval
Use Postgres' setval('sequence_name', value)
Avoid transaction logging (WAL), as noted previously
Defer Index creation until after data load
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 15/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 16/58
Business Logic Migration
RETURN becomes RETURNS
EXECUTE IMMEDIATE becomes EXECUTE
SELECT without INTO becomes PERFORM
You must chose a language
%TYPE, %ROWTYPE: works
cursor_name% ROWTYPE: Doesn't work; Use RECORD
REFCURSORS: No replacement; Use Set-Returning-Functions
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 17/58
Business Logic Migration
Autonomous transactions
Ability to COMMIT/ROLLBACK within procedures (only)
REVERSE LOOPs require switching the start/end conditions
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 18/58
Business Logic Migration
Split them into trigger function and the trigger
CREATE OR REPLACE FUNCTION my_trig_fn() RETURNS TRIGGER
AS $$ ... $$ LANGUAGE xxx;
CREATE TRIGGER tbl1_trig1 BEFORE UPDATE ON table
EXECUTE PROCEDURE my_trig_fn();
:NEW, :OLD
UPDATING, INSERTING => Use TG_OP; consider TG_* variables
Don't forget to RETURN NEW in BEFORE triggers
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 19/58
Business Logic Migration
Execute a trigger only if a condition matches
Postgres has it.
Postgres has only functions
Use RETURNS VOID
May need application changes
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 20/58
Business Logic Migration
RETURN becomes RETURNS
Should provide parentheses () even for empty parameter list
DEFAULT values for parameters
Can return pseudo type RECORD
Can return set of records; RETURNS SETOF type
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 21/58
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 22/58
Business Logic Migration
Functions within functions, oh my...
Feature not available in Postgres; use normal functions
(C) EnterpriseDB Corporation 2011. All Rights Reserved.
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 23/58
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 24/58
Other Objects
Feature not avaialable
Feature not available
Use the dblink contrib module, and views
Use WITH RECURSIVE; SQL compliant and very flexible
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 25/58
Other Objects
Create wrapper views
Jonathan Gardner
Dan Chak – Materialized Views that Work
Roll your own using Inheritance, Triggers, CHECKconstraints, and constraint_exclusion
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 26/58
Other Objects
Work pretty much the same way as in Oracle.
NOCACHE becomes CACHE 1 (or remove this clause)
MAXVALUE
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 27/58
Other Objects
NO{CACHE|MINVALUE|MAXVALUE|CYCLE}
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 28/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 29/58
Application Connectivity
Works
Works
Consider turning off the autocommit flag in driver
Npgsql
Used by Pro*C programs
Oracle Forms
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 30/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 31/58
Application Migration
Names of schema, tables, columns, functions, …
Oracle converts them to UPPER CASE, unless quoted
Postgres converts them to lower case, unless quoted
You're safe if application quotes/does not quote the identifiers
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 32/58
Application Migration
In Oracle, WHERE clause entries mark the NULL augmented sidewith a (+)
Oracle was ahead of the SQL Standards Committee
Postgres provides SQL Standard syntax {LEFT|RIGHT|FULL}[OUTER] JOIN; and so does Oracle.
SELECT e.name, d.name FROM emp e, dept d WHERE e.deptno
= d.deptno (+)
SELECT e.name, d.name FROM emp e LEFT JOIN dept d ONe.deptno = d.deptno
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 33/58
Application Migration
Becomes EXCEPT
=> becomes :=
For example:
var = fn( c => 10, a => 'xyz', b => 2.5);
becomes
var = fn( c := 10, a := 'xyz', b := 2.5);
Just a 1-row x 1-column table for expression evaluation
Orafce provides this table.
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 34/58
Application Migration
Use ROW_NUMBER() windowing function
Use as a wrapper around the main query, if needed.
Use CTID system column
Use OID column
Postgres doesn't have them, and doesn't want them. Discard, or keep for future reference; they won't bite you
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 35/58
Application Migration
Oracle treats empty string '' as NULL. Non-standard andconfusing.
Needs careful examination of queries comparing empty string
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 36/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 37/58
Builtin functions
Provided by Orafce
Or use SQL standard COALESCE()
Use the SQL Standard CASE clause
Postgres now has VARIADIC; it might be possible to implementthis where all parameters' data types are same.
Postgres has this, but not very robust; requires testing of queries.
Orafce provides the 1-argument version
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 38/58
Builtin functions
Postgres provides this.
Postgres also provides SQL standards compliant syntax
Use current_timestamp
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 39/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 40/58
DBA Migration
Have them attend some of Bruce's talks :)
No Rollback Segments
SGA => ~ shared_buffers
PGA => ~ work_mem
PMON => Postmaster
TNS Listener => Postmaster
GRANT/REVOKE => Almost the same; mostly syntax change
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 41/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 42/58
Porting Tools
A lot of Oracle compatibility functions
DUAL table
Packages for various platforms (RPM, .deb)
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 43/58
Porting Tools
Pretty advanced schema and data extraction
Extracts PL/SQL too; Packages, Functions, Procedures
Tries to convert PL/SQL
Export to file, multiple files, compressed
Export directly to Postgres
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 44/58
Porting Tools
Perl module
Develop your own extraction tools
Ora2pg uses this
Packages available for different platforms
Developed by EnterpriseDB
Mainly for Oracle to Postgres Plus Advanced Server migration
May help in Oracle to Postgres migration
Does not convert PL/SQL code Maps data types
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 45/58
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
O 2
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 46/58
Ora2pg
Tables
Views
Sequences
Indexes
GRANT
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
O 2
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 47/58
Ora2pg
Range
List
No Hash partitions (yet)
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
O 2
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 48/58
Ora2pg
Export to a single file
Export to multiple files
Compress output files using gzip or bzip
Export directly to Postgres (not recommended as first step)
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 49/58
Everything is specified in a config file
Define Oracle's connection paramters
Ora2pg
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 50/58
Ora2pg
Define objects to export
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 51/58
Ora2pg
Define objects to export (continued)
Modify structure
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 52/58
Ora2pg
DATA_LIMIT: Limit number of incoming rows in memory
OUTPUT: output file name; .gz or .bz2
OUTPUT_DIR: Where to put output file(s)
BZIIP2: Location of bzip2 executable
FILE_PER_TABLE: One output file per table
FILE_PER_FUNCTION: One function/trigger per file TRUNCATE_TABLE: Truncate the table before loading;
DATA/COPY mode only
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 53/58
Ora2pg
PG_DSN
PG_USER
PG_PWD
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 54/58
Ora2pg
SKIP: List of schema constraint type to skip
KEEP_PKEY_NAMES
FKEY_DEFERRABLE
DEFER_FKEY
DROP_FKEY
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 55/58
Ora2pg
DROP_INDEXES
DISABLE_TABLE_TRIGGERS: 0/USER/ALL
DISABLE_SEQUENCE
DATA_TYPE
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 56/58
Ora2pg
CASE_SENSITIVE
ORA_RESERVED_WORDS
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential
Ora2pg
8/2/2019 205 Oracle to Postgres Migration
http://slidepdf.com/reader/full/205-oracle-to-postgres-migration 57/58
Ora2pg
NLS_LANG
BINMODE
CLIENT_ENCODING
(C) EnterpriseDB Corporation 2011. All Rights Reserved. Company Confidential