Aug 23 2016

Create Dblink From Oracle to PostgreSQL Database

Category: Administration,AdministrationFatih Acar @ 14:36

Since fetching data from PostgreSQL database to Oracle database, you can create database link between two database systems. For that you can apply below operations.

Test Systems

PostgreSQL DB
IP :
OS : Centos 7 x64
Service : postgresql.service

Oracle DB
IP :
OS : OEL 6 x64


PostgreSQL Side

psql# create user dblinkuser encrypted password ‘dblinkuserpass’;

psql# grant usage on schema “testschema” to dblinkuser;

psql# grant select on “testschema”.tbl_test to dblinkuser;

Add new line to pg_hba.conf

vi /pgdir/data/pg_hba.conf

host testdb dblinkuser md5

systemctl reload postgresql.service

Oracle Side

yum install postgresql-odbc

vi /etc/odbc.ini

Description = PG
Driver = /usr/lib64/
ServerName =
Username = dblinkuser
Password = dblinkuserpass
Port = 5432
Database = testdb
Driver = /usr/lib64/

vi $ORACLE_HOME/hs/admin/initPG.ora

# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC

# HS init parameters
# ODBC specific environment variables
set ODBCINI=/etc/odbc.ini

# ODBC specific environment variables

# Environment variables required for the non-Oracle system
#set =

vi $ORACLE_HOME/network/admin/tnsnames.ora

PG =
(SID = PG)
(HS = OK)

vi $GRID_HOME/network/admin/listener.ora


lsnrctl reload

Listener reload can be adacuate to apply changes;but, sometimes not.

lsnrctl stop
lsnrctl start
lsnrctl status

Create Database Link on Oracle

CONNECT TO “dblinkuser”
IDENTIFIED BY ‘dblinkuserpass’


select * from “testschema”.”tbl_test”@PG

30,556 total views, 34 views today

Tags: Database Administration, Oracle Administration, PostgreSQL Administration

facebook comments:

4 Responses to “Create Dblink From Oracle to PostgreSQL Database”

  1. PK says:

    I’m trying to connect from oracle database to aws rds postgresql.
    AWS rds postgresql instances will not have OS level access, when trying to connect getting following errors.
    Any idea what these errors are?

    SQL> select * from names@pg;

    select * from names@pg
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    FATAL: password authentication failed for user “abcd”
    {08001,NativeErr = 113}
    ORA-02063: preceding 3 lines from PG

  2. Ballat Marc says:


    Google Apps Script does not support connection to Postgresql (unless in Google Cloud). It does support connection to Oracle. Does it make sense to develop the tables, views and triggers in Postgres and access them through Oracle Express/dblink ? I don’t know the implications in terms of performance, security and type compatibility. This would be temporary, the time for me to rewrite my GAS spreadsheets using node.js and jQuery.

    I would appreciate if someone can shed some light on this.

    Thx, Marc

  3. Stephanie says:

    Im trying to configure db link to a postgress cluster the same thing you have done only with port=9999 and oracle us throwing me an error, what can i do?
    Thanks stepg

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.