Keith's picture

PostgreSQL Oracle FDW... in 8i?!

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.

Tags: 

Comments

The problem with that is that

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

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

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 ?

Strange problem with oracle_fdw

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

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

Filtered HTML

  • E-Mail addresses are hidden with reCAPTCHA Mailhide.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Twitter-style @usernames are linked to their Twitter account pages.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.