Vous êtes sur la page 1sur 24

Use Oracle from PostgreSQL

oracle_fdw in migration scenarios


Laurenz Albe <laurenz.albe@wien.gv.at
!"#!$#"$"%

&'at is oracle_fdw(

it allows read access to Oracle tables as if t'e)


were PostgreSQL tables

an SQL*+,- .oreign -ata &ra//er for Oracle

a PostgreSQL server e0tension

/ro1ect /age2
'tt/2**oracle$fdw./ro1ects./ostgres3l.org*

.oreign -ata &ra//er conce/ts
PostgreSQL ob1ect
.oreign -ata &ra//er
.oreign Server
User +a//ing
.oreign 4able
corres/onds to
Oracle -5 software
Oracle instance
Oracle credentials
Oracle table*view

A sim/le e0am/le
pgdb=# CREATE EXTENSION oracle_fdw;
pgdb=# CREATE SERVER oradb FOREIGN DATA RA!!ER
oracle_fdw O!TIONS
"db#er$er&''db#er$er()*do)a+,(co)'ORAD-&.;
pgdb=# GRANT /SAGE ON FOREIGN SERVER oradb
TO pg0#er;
pgdb=# 1co,,ec2 pgdb pg0#er
pgdb=3 CREATE /SER 4A!!ING FOR pg0#er
SERVER oradb
O!TIONS "0#er &ora0#er&5 pa##word &orapwd&.;
pgdb=3 CREATE FOREIGN TA-6E people "
+d +,2eger NOT N/665
,a)e $arc7ar"89.5
b+r27da* da2e NOT N/66
. SERVER oradb O!TIONS "2able &!EO!6E&.;

-ata migration wit' oracle_fdw
-EGIN;
CREATE TA-6E loc_people AS
"SE6ECT : FRO4 people.;
A6TER TA-6E loc_people
ADD CONSTRAINT people_p;e*
!RI4AR< =E<"+d.;
DRO! FOREIGN TA-6E people;
A6TER TA-6E loc_people
RENA4E TO people;
CO44IT;

S/ecial .eatures of oracle_fdw

Automatic encoding management

-ata t)/e conversion

>ERE clause /us' down

Onl) fetc' re3uired columns

EX!6AIN su//ort
6ew in 7.!2

Statistics on foreign tables

6o re$c'ec8 of /us'ed down >ERE clauses



.eature2 Automatic encoding
management
9:est tr;<s im/ortant=
Automaticall) sets t'e Oracle client encoding to
t'e value of t'e PostgreSQL server encoding.
Override wit' ,l#_la,g o/tion on t'e .-&
ob1ect >useful for S?6_ASCII?.

.eature2 -ata t)/e conversion
4'is could be done wit' views and casts@ but it is
more convenient if t'e .-& su//orts it.

Allows conversion of matc'ing data t)/es >e.g.


N/4-ER A ,0)er+c*+,2eger*do0ble prec+#+o,/
boolea,?

All e0ce/t binar) data can be converted to


te0tual t)/es

-oes not guarantee t'at all values can be


converted >encoding /roblems@ string lengt'@
integer ma0imum@ B?

.eature2 >ERE /us'down@
column elimination
EX!6AIN SE6ECT ,a)e FRO4 people >ERE +d=@;

?/ER< !6AN
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Fore+g, Sca, o, people "co#2=B9999(99((B9999(99
row#=B w+d27=CD.
F+l2erE "+d = @.
Oracle F0er*E SE6ECT
':D@@dCDGad@HbcI8@e9aJIJGCH8d@b8CG:'
KIDK5 KNA4EK FRO4 !EO!6E >ERE "KIDK = @.
"8 row#.

.eature2 EX!6AIN su//ort

EX!6AIN s'ows t'e remote 3uer)

EX!6AIN VER-OSE s'ows t'e remote 3uer)


/lan >re3uires SE6ECT /rivilege on VLS?6 and
VLS?6_!6AN?

.eature2 EX!6AIN su//ort
EX!6AIN VER-OSE SE6ECT ,a)e FRO4 people >ERE +d=@;
?/ER< !6AN
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Fore+g, Sca, o, pg0#er(people
"co#2=B9999(99((B9999(99 row#=B w+d27=CD.
O02p02E ,a)e
F+l2erE "people(+d = @.
Oracle F0er*E
SE6ECT':D@@dCDGad@HbcI8@e9aJIJGCH8d@b8CG:'
KIDK5 KNA4EK FRO4 !EO!6E >ERE "KIDK = @.
Oracle pla,E SE6ECT STATE4ENT
Oracle pla,E TA-6E ACCESS -< INDEX ROID !EO!6E
Oracle pla,E INDEX /NI?/E SCAN !EO!6E_!=E<
"co,d+2+o, KIDK=@.
"C row#.

>+is$?.eature2 ,stimates in 7.#
EX!6AIN ANA6<ME SE6ECT +d FRO4 people
>ERE ,a)e 6I=E &6N&
AND b+r27da* O ,ow". A &J9 *ear#&EE+,2er$al;
?/ER< !6AN
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Fore+g, Sca, o, people
"co#2=B9999(99((B9999(99 row#=GJCC w+d27=G.
"ac20al 2+)e=B(BCI((B9@(JHB row#=HC8 loop#=B.
F+l2erE """,a)e.EE2eP2 QQ &6N&EE2eP2. AND
"b+r27da* O ",ow". A &J9 *ear#&EE+,2er$al...
Oracle F0er*E
SE6ECT ':I9af@IHc98dDDD@a899fJCHeIB9JI9Gd:'
KIDK5 KNA4EK5 K-IRT>DA<K FRO4 !EO!6E
>ERE "KNA4EK 6I=E &6N& ESCA!E &1&.
To2al r0,2+)eE B98(HI9 )#

.eature2 ANA6<ME in 7.!

ANA6<ME collects statistics for remote tables

+ust be called for eac' foreign table e0/licitl)

Cood estimates even wit'out as8ing Oracle

Performs a full table scan on Oracle



.eature2 ,stimates in 7.!
EX!6AIN ANA6<ME SE6ECT +d FRO4 people
>ERE ,a)e 6I=E &6N&
AND b+r27da* O ,ow". A &J9 *ear#&EE+,2er$al;
?/ER< !6AN
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Fore+g, Sca, o, people
"co#2=B9999(99((B9999(99 row#=GB@ w+d27=G.
"ac20al 2+)e=B(DDH((BBH(BG8 row#=HC8 loop#=B.
F+l2erE
"b+r27da* O ",ow". A &J9 *ear#&EE+,2er$al..
Row# Re)o$ed b* F+l2erE G9BD
Oracle F0er*E
SE6ECT ':I9af@IHc98dDDD@a899fJCHeIB9JI9Gd:'
KIDK5 KNA4EK5 K-IRT>DA<K FRO4 !EO!6E
>ERE "KNA4EK 6I=E &6N& ESCA!E &1&.
To2al r0,2+)eE BBH(CCD )#

Problems

Still beta >awaiting )our feedbac8=?

NC6O- and ot'er rare data t)/es not su//orted

6o Oracle su//ort for some rare server


encodings >non$AS9DD c'aracters become :R:?

5ad Oracle cost estimates


>disabled b) default?

Dncom/atible L-AP libraries


>build PostgreSQL AAw+27o02Aldap?

Usage for migration

9oe0ist2 integrate wit' e0isting Oracle


databases

+igrate data2 e0tract@ transform@ load >,4L?



9oe0ist wit' Oracle
Usuall) one cannot*does not want to migrate all
Oracle databases at once.
4'en 'ow can )ou migrate an Oracle database
wit' database lin8s(
oracle_fdw can save t'e da)=
4'is can also be a /roblem for new a//lications2
E&e cannot use PostgreSQL because we 'ave to
access t'is certain Oracle table.F

+igration2 e0tract data from Oracle
Oracle deliberatel) does not /rovide tools for t'at
>SQLGPlus does not wor8 well?.
Hou can use t'ird$/art) tools or write )our own.
oracle_fdw does it for )ou=
9an also be used to e0tract data from Oracle to
te0t files for ot'er /ur/oses2
pgdb=3 1cop* "SE6ECT : FRO4 people.
TO &people(c#$& "FOR4AT &c#$&.

+igration2 transform data
Often data need to be converted during migration2

different string encoding2


oracle_fdw does t'is efficientl)

different data t)/es2


oracle_fdw does t'is efficientl)

Edata cleansingF or ma//ing to ot'er values2


can sometimes be im/lemented b) 1oins on t'e
PostgreSQL or Oracle side >views?.
oracle_fdw can /erform sim/le transformations.

+igration2 load into PostgreSQL
Usuall) done wit' CO!< FRO4 SQL statement.
4'is is t'e easiest /art.
oracle_fdw is slower t'an CO!<@ but can avoid t'e
need for an o/erating s)stem file as intermediar)
data store.

+igration2 advantages of oracle_fdw
.or sim/le migration scenarios@ oracle_fdw is a
fast and sim/le migration tool2

all written in 9

all can be done in one SQL statement

Oracle /refetc'ing for fewer client$server round


tri/s

no intermediar) files

binar) values are transferred binar)@ no


conversion necessar)

su//ort for Elegac)F data2 Oracle I@ de/recated


t)/es 6ONG and 6ONG RA

+igration2 limits of oracle_fdw
oracle_fdw will not 'el/ wit' table*inde0*function
definitions.
ora!/g >'tt/2**ora!/g.darold.net*config.'tml? can
generate foreign table definitions for oracle_fdw.
An alternative is a sim/le Esc'ema converterF2
PostgreSQL function t'at uses foreign tables for
/SER_TA-6ES and /SER_TA-_CO6/4NS to
create foreign tables for ever)t'ing in an Oracle
sc'ema.

&'at t'e future could bring

E1oin /us'downF of 1oins between Oracle tables


in t'e same Oracle database

writeable foreign tables


All t'is needs added su//ort in core PostgreSQL.

Questions( Suggestions(