How to install and configure DBI-Link to join Oracle tables from PostgreSQL on Debian GNU/Linux

At some deployment scenarios, one may have to access Oracle tables transparently using PostgreSQL functions, without installing other language specific libraries.

There is a caveat for this version:

  • Each query will load data from remote Oracle server to the local PostgreSQL shadow table.
  • You can execute remotely on Oracle backend using remote_select as described here.


You will need the alien package to convert rpm files to deb files.

You will need to have an Oracle account to download the Oracle Instant Client Basic and Oracle Instant Client Devel rpm files suitable for your Oracle backend version from the vendor site.

At this example, we will use



Convert *.rpm to *.deb

The alien package makes a brute conversion from rpm to deb, without careful checks. You must to test the results on a disposable laboratory machine before deploying at a valuable server.

debian:~# alien --to-deb oracle-instantclient-basic-
debian:~# dpkg --install oracle-instantclient-basic_10.2.0.3-2_i386.deb
debian:~# alien --to-deb oracle-instantclient-devel_10.2.0.3-2_i386.rpm
debian:~# dpkg --install oracle-instantclient-devel_10.2.0.3-2_i386.deb

Install dbi-link and dependencies

The libaio1 is needed by the oracle programs.

debian:~# apt-get update
debian:~# apt-get install libdbd-oracle-perl dbi-link libaio1

Configure Oracle Instant Client Basic

Prepare the tnsnames.ora

debian:~# mkdir -p /usr/lib/oracle/
debian:~# nano /usr/lib/oracle/


A very simple example below, adapt it to your Oracle available database service.

your_symbolic_service_name =
(ADDRESS = (PROTOCOL = TCP) (HOST = your_oracle_server_address)(PORT = 1521))
(CONNECT_DATA = (SID = your_available_oracle_sid))


We will not use sqlnet.ora at this example. Please read the useful links section at the end of article.



debian:~# nano /etc/
debian:~# ldconfig

Configuring DBI-Link for PostgreSQL access Oracle tables

The step for creating the accessor_functions may be lenghty as it downloads all tables informations from the Oracle backend.

Your local schema MUST NOT EXISTS before creating the accessor functions. Read the dbi-link debian package documentation on your disk.

There are paremeters you must edit to your needs, like the oracle server port, and we use an example query.

Notably, the connection string:


could be something like:


or even could be:


It depends on your user access permissions and Oracle configuration files. Be careful with the syntax.

When it enters psql the first time, one must update the pg_settings for the dbi-link too. The sql is at the Debian dbi-link package documentation.

debian:~# su postgres
postgres@debian:/root$ createdb teste
postgres@debian:/root$ createlang plperlu teste
postgres@debian:/root$ psql -d teste -f /usr/share/dbi-link/dbi_link.sql
postgres@debian:/root$ psql teste
Bem vindo ao psql 8.3.14, o terminal iterativo do PostgreSQL.

Digite: \copyright para mostrar termos de distribuição
\h para ajuda com comandos SQL
\? para ajuda com comandos do psql
\g ou terminar com ponto-e-vírgula para executar a consulta
\q para sair

teste=# UPDATE
setting =
CASE WHEN 'dbi_link' = ANY(string_to_array(setting, ','))
THEN setting
ELSE 'dbi_link,' || setting
name = 'search_path'

teste=# SELECT make_accessor_functions(
AutoCommit: 1
RaiseError: 1

teste=# \d
teste=# select count(*) from your_local_schema."VW_SISCOR_02";
teste=# select count(*) from your_local_schema."VW_LOTACAO";
teste=# select count(*) from your_local_schema."VW_LOTACAO" where "UF" = 'RS';
teste=# \q
postgres@debian:/root$ exit

Useful Links

Oracle access files tnsnames.ora , sqlnet.ora

Running Perl from PHP,0