So one of our clients is still stuck running an old Oracle 8i database. Please, no comments on how there's no more support and they should have moved off this long ago. We know. They know. Moving on...
The introduction of a new Oracle Foreign Data Wrapper peaked our interest. Could it possibly still work with 8i? Working with our SA team, they found that the oldest client libraries still available from Oracle are 10.2. We're not exactly sure when Oracle dropped 8i support from their client libraries, so instead of experimenting at this time they went with known working client libraries for our currently used client which is 10.1.0.2.0 (looking at the package info). So they compiled up some packages for our Solaris environment and off I went.
With the packages installed, setting up the extension couldnt've been easier
CREATE EXTENSION oracle_fdw;
This was my first attempt with using Foreign Data Wrappers, so the next hour or so was spent reading the oracle_fdw docs and jumping around the postgres docs to see how it all works. We already have a connection between PostgreSQL and Oracle working with the dbi_link package, so the Oracle Client connection was already setup and working (explaining that setup is a little out of scope for this blog post). The commands to create the server, user mapping & foreign table follow...
CREATE SERVER oracle_server FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver 'ORACLE_DBNAME');
CREATE USER MAPPING FOR CURRENT_USER SERVER oracle_server OPTIONS (user 'oracle_user', password '######');
CREATE FOREIGN TABLE keith.fdw_test (
userid numeric,
username text,
email text
)
SERVER oracle_server
OPTIONS ( schema 'keith', table 'fdw_test');
Then run a select and see...
pgsql=# select * from keith.fdw_test;
userid | username | email
--------+----------+-------------------
1 | keith | kei...@example.com
(1 row)
It works! This will make the (hopeful) migration off of Oracle 8i that much easier.
Could this possibly be faster than dbi_link for replicating data from Oracle to Postgres? Will be working on rewriting some of our data replication functions to use the FDW and run comparisons. I'll share the results in a future post.
Comments
As the author of DBI-Link,
Submitted by David Fetter (not verified) on
I very sincerely hope that oracle_fdw beats the pants off the hack I wrote in PL/Perl.
Sounds good
Submitted by Hans (not verified) on
now the only thing that is missing are pre-built binaries for oracle_fdw (especially for Windows users..)
The problem with that is that
Submitted by Laurenz Albe (not verified) on
The problem with that is that the oracle_fdw binary has to match the server binary. Which server binary should I chose? I tried with EnterpriseDB's binary but couldn't get pgxs to run with MinGW. I could not find documentation on how they build their binary.
Why not try to get it into
Submitted by Hans (not verified) on
Why not try to get it into the PostgreSQL distribution as a contrib module? Then it would be clear to which server binary it belongs to. Compiling stuff is extremely uncommon (if not mostly unheard off) in the Windows world.
error connecting to oracle
Submitted by jose (not verified) on
Hi, when i create the server :
--
CREATE SERVER oracle_server
FOREIGN DATA WRAPPER oracle_fdw
OPTIONS (dbserver 'ORACLE_DBNAME');
--
what i should set dbserver value?
what meaning "Oracle Client connection was already setup and working"?
when i execute select on foreign table received the error ORA-12514.
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
helpme, what's cause of this error ?
You need to have the Oracle
Submitted by Keith on
You need to have the Oracle Client installed and set up with a tns_names.ora config file set up to point to where your Oracle database is. You also need to have the TNS_ADMIN and ORACLE_HOME environment variables set so the the oracle foreign data wrapper knows where to find your tns_names.ora file and the oracle client libraries. The 'dbserver' value is whatever you have set up in your tns_names.ora file for your database connection.
I can't really provide much more support than that here, I'm sorry. Oracle is a beast of an database to get set up properly which is why I really didn't go into much detail about it here.
Strange problem with oracle_fdw
Submitted by Rodrigo Gamboa (not verified) on
I installed oracle_fdw, and, at first, I've not problems with psql client in the server computer. But my problem started when i wanted use a pgadmin (remote and local client) or a psql from another computer. Server computer is a VirtualBox machine server with postgresql and oracle server (in the same virtual machine). I have only one tnsname.ora, ORACLE_HOME and TN_ADMIN set. I've worked for a three day and i can't solve this problem. Could any help me please?
Thanks.
server creation with ure
Submitted by vincent (not verified) on
As for the server creation, the new way of providing the address is muuuuch easier :
CREATE SERVER oracle_server
FOREIGN DATA WRAPPER oracle_fdw
OPTIONS (dbserver '//servername:1521/basename');
Add new comment