Anda di halaman 1dari 22

9/6/2016 How to access PostgreSQL from Oracle database | DBA spot

DBA spot

Oracle topics

How to access PostgreSQL from Oracle database

MAY 29, 2013  55 COMMENTS (HTTPS://DBASPOT.WORDPRESS.COM/2013/05/29/HOW‑TO‑ACCESS‑POSTGRESQL‑
FROM‑ORACLE‑DATABASE/#COMMENTS)

Se ing up connectivity between Oracle and PostgreSQL by means of database link is as easy as follows:

1. on Oracle server set up ODBC data source for PostgreSQL database:

Windows:

install ODBC driver for PostgreSQL
go to Data Sources (ODBC)
→ click System DSN
→ click Add, select ‘PostgreSQL Unicode’
→ provide Data Source (e.g. PG_LINK), Database (e.g. pgdb), Server, Port, User Name (e.g. pguser), Password (e.g. pgpass)
→ click Test to test connectivity

Linux:

install ODBC driver for PostgreSQL, e.g.

 # yum install postgresql91‐odbc

place .odbc.ini file in oracle user home directory:

[ODBC Data Sources] 
  PG_LINK = PostgreSQL 
[PG_LINK] 
  Debug = 1 
  CommLog = 1 
  ReadOnly = no 
  Driver = /usr/pgsql‐9.1/lib/psqlodbc.so 
  Servername = <PostgreSQL_IP> 
  FetchBufferSize = 99 
  Username = pguser 
  Password = pgpass 
  Port = 5432 
  Database = pgdb 
[Default] 
  Driver = /usr/lib64/liboplodbcS.so.1 

2. configure HS for Oracle database

 
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 1/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
 

create file initPG_LINK.ora under $ORACLE_HOME/hs/admin directory

(Note: PG_LINK is the name of Data Source name created above).
Edit the file:

Windows:

 HS_FDS_CONNECT_INFO = PG_LINK 
 HS_FDS_TRACE_LEVEL = 0

Linux:

 HS_FDS_CONNECT_INFO = PG_LINK 
 HS_FDS_TRACE_LEVEL = 0 
 HS_FDS_SHAREABLE_NAME=/usr/pgsql‐9.1/lib/psqlodbc.so 
 set ODBCINI=/home/oracle/.odbc.ini

modify tnsnames.ora; add the following entry:

PG_LINK  = 
  (DESCRIPTION= 
    (ADDRESS=(PROTOCOL=tcp)(HOST=<ORA_DB_HOSTNAME>)(PORT=<ORA_DB_PORT>))
    (CONNECT_DATA=(SID=PG_LINK)) 
    (HS=OK) 
  )

modify listener.ora; add the following static entry in the SID_LIST:

SID_LIST_<your_LISTENER_NAME>= 
  (SID_LIST= 
      (SID_DESC= 
         (SID_NAME=PG_LINK) 
         (ORACLE_HOME=<your_ORACLE_HOME>) 
         (PROGRAM=dg4odbc) 
      ) 
  )

reload listener configuraction

lsnrctl reload <your_LISTENER_NAME>

create database link:

create database link PG_LINK connect to "pguser" identified by "pgpass" using 'PG_LINK';

Note: In PostgreSQL all non‑quoted identifiers are converted to lowercase. On the other hand in Oracle they are converted to
uppercase.
That’s why it’s important here to put double quotes around lower‑case username (“pguser”) and password (“pgpass”). Otherwise
you’ll pass PGUSER and PGPASS (converted by Oracle) to PostgreSQL and get an error.

The same relates to querying data from PostgreSQL database via Oracle database link.
Enclose PostgreSQL table name with double quotes:

SQL> select * from "testtable"@PG_LINK; 
 col1 
 ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ 
 test row 1

Otherwise, you’ll get ORA‑28500 message:

https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 2/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot

SQL> select * from testtable@PG_LINK; 
  select * from testtable@PG_LINK 
  * 
  ERROR at line 1: 
  ORA‐28500: connection from ORACLE to a non‐Oracle system returned this message:
  ERROR: relation "TESTTABLE" does not exist; 
  No query has been executed with that handle {42P01,NativeErr = 1} 
  ORA‐02063: preceding 3 lines from PG_LINK

About these ads (https://wordpress.com/about­these­ads/)

FILED UNDER ORACLE, POSTGRESQL

55 Responses to How to access PostgreSQL from Oracle database

SutoCom says:
June 1, 2013 at 11:43
Reblogged this on Sutoprise Avenue, A SutoCom Source.

Reply
thiago says:
March 25, 2014 at 21:11
I´m having problem:
TNS‑01201: Listener cannot find executable /u00/app/oracle/product/10.2.0/db_1/bin/dg4odbc for SID POSTGRES

Reply
dbaspot says:
March 26, 2014 at 08:46
Try ‘hsodbc’ for 10g oracle binaries. ‘dg4odbc’ relates to 11g.

Paul says:
May 6, 2014 at 12:20
Followed your steps: Postgresql‑92 local on Windows 7 64bit . Oracle 12.1 local on same host.

SQL> select * from “city”@PG_LINK;
select * from “city”@PG_LINK
*
ERROR at line 1:
ORA‑28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA‑02063: preceding 2 lines from PG_LINK

Any suggestions?

Reply
dbaspot says:
May 6, 2014 at 13:15
Please post your initPG_LINK.ora, listener.ora and tnsnames.ora entries related to PG_LINK.

Reply
Paul says:
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 3/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
Paul says:
May 6, 2014 at 16:14
Thanks for your quick reply. Below the relevant info. Any ideas?

–> LISTENER.ORA:

# listener.ora Network Configuration File: D:\oracle\product\12.1.0\dbhome_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\oracle\product\12.1.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = “EXTPROC_DLLS=ONLY:D:\oracle\product\12.1.0\dbhome_1\bin\oraclr12.dll”)
)
(SID_DESC=
(SID_NAME=PG_LINK)
(ORACLE_HOME=D:\oracle\product\12.1.0\dbhome_1)
(PROGRAM=dg4odbc)
)
)

LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = mylaptop)(PORT = 1521))
)

ADR_BASE_LISTENER = D:\oracle\product\12.1.0\dbhome_1\log

–> TNSNAMES.ORA:

# tnsnames.ora Network Configuration File: D:\oracle\product\12.1.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

PG_LINK =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=mylaptop)(PORT=5432))
(CONNECT_DATA=(SID=PG_LINK))
(HS=OK)
)

–> initPG_LINK.ora:

HS_FDS_CONNECT_INFO = PG_LINK
HS_FDS_TRACE_LEVEL = 0

Reply
dbaspot says:
May 6, 2014 at 20:40
Hi.
Please change PORT to 1521 for PG_LINK entry in tnsnames.ora. It should be oracle listener port.

Reply
Paul says:
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 4/22
9/6/2016Reply How to access PostgreSQL from Oracle database | DBA spot
Paul says:
May 7, 2014 at 11:10
Great, got it working! Maybe you can edit the original post so that other readers got it right the first a empt.
You saved us a lot of time with this post! :‑)

Reply
Konstantin Mishenkov says:
June 5, 2014 at 11:32
thanks a lot

Reply
Stanislav says:
June 6, 2014 at 10:28
Hi.
I need help.
I’m create dblink from oracle12.1 to postgres9.2, but have error
“SQL> select * from “tabletest”@PG_LINK;
select * from “tabletest”@PG_LINK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
c

Reply
Stanislav says:
June 10, 2014 at 08:38
I solved the problem. my current working configuration is:

###cat /etc/odbc.ini
[PSQL]
Description = Postgres DB
Driver = /usr/pgsql‑9.2/lib/psqlodbc.so
TextAsLongVarchar = Yes
Servername = 195.191.251.54
PORT = 5432
Protocol = 9.2
UserName = postgres
Password = postgres
Database = db
TRACE =Yes
TraceFile = /tmp/sql.log

###cat /etc/odbcinst.ini
# Driver from the postgresql‑odbc package
# Setup from the unixODBC package
[PostgreSQL]
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1

###cat /u01/oracle/database/12.1/hs/admin/initPSQL.ora
HS_FDS_CONNECT_INFO = PSQL
HS_FDS_TRACE_LEVEL = 255
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
set ODBCINI=/etc/odbc.ini

### cat /u01/oracle/database/12.1/network/admin/tnsnames.ora
PSQL=
(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = oracle.mydomain.com)(PORT = 1521))
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 5/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle.mydomain.com)(PORT = 1521))
(CONNECT_DATA =(SID = PSQL))
(HS = OK)
)

### cat /u01/oracle/database/12.1/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(SID_NAME=MSSQL)
(ORACLE_HOME=/u01/oracle/database/12.1/)
(PROGRAM=dg4odbc)
)
(SID_DESC=
(SID_NAME=PSQL)
(ORACLE_HOME=/u01/oracle/database/12.1/)
(PROGRAM=dg4odbc)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle.mydomain.com)(PORT = 1521))
)
)

Reply
dariyooshdariyoosh says:
June 9, 2014 at 16:41
Hi,

First of all, thank you very much for your article. I followed the instructions. Please find below my configuration:

[ Here is the content of the file /home/oracle/odbc.ini ]
———————————————————————–
[ODBC Data Sources]
PG_LINK = PostgreSQL
[PG_LINK]
Debug = 1
CommLog = 1
ReadOnly = no
Driver = /usr/local/psqlodbc‑09.03.0300/build/lib/psqlodbcw.so
Servername = 192.168.1.177
FetchBufferSize = 99
Username = postgres
Password = postgres
Port = 5432
Database = imdb
[Default]
Driver = /usr/lib64/liboplodbcS.so.2

I downloaded and compiled the most recent version of ODBC directly from Postgresql website
so /usr/local/psqlodbc‑09.03.0300/build/lib/ above refers to the installation directory and inside the lib I have two files:
$ ls /usr/local/psqlodbc‑09.03.0300/build/lib/
psqlodbcw.la psqlodbcw.so
$
It seems to me that psqlodbcw.so is the odbc driver which I put in odbc.ini file.

[ The content of the file $ORACLE_HOME/hs/admin/initPG_LINK.ora]
—————————————————————————————–
HS_FDS_CONNECT_INFO = PG_LINK

HS_FDS_TRACE_LEVEL = 0
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 6/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
HS_FDS_TRACE_LEVEL = 0
HS_FDS_SHAREABLE_NAME=/usr/local/psqlodbc‑09.03.0300/build/lib/psqlodbcw.so
ODBCINI=/home/oracle/odbc.ini

[ The new entry in $TNS_ADMIN/tnsnames.ora ]
—————————————————————–
PG_LINK =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST = vmoracle.mydomaine.net)(PORT = 1521))
(CONNECT_DATA=
(SID=PG_LINK)
)
(HS=OK)
)

where vmoracle.mydomaine.net is oracle hostname already properly configured in /etc/hosts

[ The content of the file $TNS_ADMIN/listener.ora]
————————————————————‑
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = vmoracle.mydomaine.net)(PORT = 1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=vmdb01)
(ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1))
(SID_DESC=
(SID_NAME=PG_LINK)
(ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1)
(PROGRAM=dg4odbc))
)

ADR_BASE_LISTENER = /u01/app/oracle

Once all of this was accomplished I run the following
$ lsnrctl stop

$lsnrctl start

And I started a new SQL*Plus session with a user who has already the right to create database link

SQL> create database link PG_LINK connect to “postgres” identified by “postgres” using ‘PG_LINK’;

Database link created.

SQL> select count(*) from “movie_companies”@PG_LINK;
select count(*) from “movie_companies”@PG_LINK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
ORA‑02063: preceding line from PG_LINK

SQL>

I checked the log

$ cat $ORACLE_HOME/hs/log/PG_LINK_agt_17448.trc

Oracle Corporation — MONDAY JUN 09 2014 16:36:26.972
Heterogeneous Agent Release
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 7/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
Heterogeneous Agent Release
12.1.0.1.0

HS Gateway: NULL connection context at exit

Any idea? Why I get ORA‑28500 error message while I try to access the remote PostgreSQL database ?

Thanks in advance.

Reply
Stanislav says:
June 10, 2014 at 08:30
try adding the following line into file $ORACLE_HOME/hs/admin/initPG_LINK.ora

HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1

Reply
dariyooshdariyoosh says:
June 10, 2014 at 11:30
Hi,

Thank you very much for your time and your a ention. I changed the file accordingly, so here is the content after adding
the new line as you mentioned above:

HS_FDS_CONNECT_INFO = PG_LINK
HS_FDS_TRACE_LEVEL = 0
HS_FDS_SHAREABLE_NAME=/usr/local/psqlodbc‑09.03.0300/build/lib/psqlodbcw.so
HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
ODBCINI=/home/oracle/odbc.ini

After addding the new line I stopped the oracle server listener
$ lsnrctl stop

Then I restarted again
$ lsnrctl start

Service “PG_LINK” has 1 instance(s).
Instance “PG_LINK”, status UNKNOWN, has 1 handler(s) for this service…
Service “vmdb01” has 1 instance(s).
Instance “vmdb01”, status UNKNOWN, has 1 handler(s) for this service…
The command completed successfully

Then in the SQL*Plus session I repeated the test:

SQL> drop database link PG_LINK;

Database link dropped.

SQL> create database link PG_LINK connect to “postgres” identified by “postgres” using ‘PG_LINK’;

Database link created.

SQL> select count(*) from “movie_companies”@PG_LINK;
select count(*) from “movie_companies”@PG_LINK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
connction string lacks some options {08001,NativeErr = 202}
ORA‑02063: preceding 2 lines from PG_LINK

SQL>

So as we can see the error message has changed. I googled for it and on the postgresql online documentation I saw that the
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 8/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
So as we can see the error message has changed. I googled for it and on the postgresql online documentation I saw that the
error code 08001 has been a ributed to SQLCLIENT UNABLE TO ESTABLISH SQLCONNECTION , here is the link to the
document

h p://www.postgresql.org/docs/8.2/static/errcodes‑appendix.html

Just for reference, in case it might be helpful, the encoding of my PostgreSQL is UTF8 which as I understand is the one
generally recommended for handling Unicode and avoid conversion problems.

imdb=# show server_encoding;
server_encoding
—————–
UTF8
(1 row)

imdb=#

On the other hand the encoding of my oracle server is:

SQL> select
2 v1.value
3 from
4 v$nls_parameters v1
5 where
6 v1.parameter = ‘NLS_CHARACTERSET’;

VALUE
—————————————————————‑
AL32UTF8

SQL>

Any idea?

Thanks again.

Stanislav says:
June 10, 2014 at 13:52
also check pg_hba.conf that you are allowed to connect to the 192.168.1.177 from vmoracle.mydomaine.net

Stanislav says:
June 10, 2014 at 13:18
you can try install PostgeSQL odbc driver
yum install postgresql93‑odbc

and also configured new DSN

/etc/odbc.ini
————————————————————‑
[PG_LINK_NEW]
Description = Postgres DB
Driver = /usr/pgsql‑9.3/lib/psqlodbc.so
TextAsLongVarchar = Yes
Servername = 192.168.1.177
PORT = 5432
Protocol = 9.3
UserName = postgres
Password = postgres
Database = imdb

$ORACLE_HOME/hs/admin/initPG_LINK_NEW.ora
————————————————————
HS_FDS_CONNECT_INFO = PG_LINK_NEW
HS_FDS_TRACE_LEVEL = 0

HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 9/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
ODBCINI=/etc/odbc.ini

$TNS_ADMIN/tnsnames.ora
—————————————————————–
PG_LINK_NEW =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST = vmoracle.mydomaine.net)(PORT = 1521))
(CONNECT_DATA=
(SID=PG_LINK_NEW)
)
(HS=OK)
)

$TNS_ADMIN/listener.ora
————————————————————‑
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = vmoracle.mydomaine.net)(PORT = 1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=vmdb01)
(ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1))
(SID_DESC=
(SID_NAME=PG_LINK_NEW)
(ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1)
(PROGRAM=dg4odbc))
)

then create new dblink

create public database link to_postgres connect to “postgres” identified by “postgres” using ‘PG_LINK_NEW’;
and test it.

Reply
JM says:
October 13, 2014 at 15:17
Hi Guys,

Thanks for the article, it is very usefull. However I still have a problem to complete the configuration.

I need to create a DB_LINK from ORACLE 10.2.0.5.0 to Postgresql 8.1.8.

Below my config:

———————————
The package is installed
postgresql.x86_64 8.1.11‑1.el5_1.1 base

———————————
$HOME/.odbc.ini

[ODBC Data Sources]
PG_LINK = PostgreSQL
[PG_LINK]
Debug = 1
CommLog = 1
ReadOnly = no

Driver = /usr/lib64/psqlodbc.so
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 10/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
Driver = /usr/lib64/psqlodbc.so
Servername = ***.***.***.111
FetchBufferSize = 99
Username = lecture
Password = ******
Port = 5600
Database = *****
[Default]
Driver = /usr/lib64/liboplodbcS.so.1

———————————
$ORACLE_HOME/hs/admin/initPG_LINK.ora

HS_FDS_CONNECT_INFO = PG_LINK
HS_FDS_TRACE_LEVEL = 4
HS_FDS_TRACE_FILE_NAME=/logi/ora10205_psu4/hs/admin/pg_link.trc
#HS_FDS_SHAREABLE_NAME=/usr/lib64/psqlodbc.so
HS_FDS_SHAREABLE_NAME=/usr/lib64/libodbc.so
set ODBCINI=/logi/ora10205/.odbc.ini

———————————
I added the new entry in tnsnames.ora and in the listener.ora I added:


(SID_DESC=
(SID_NAME=PG_LINK)
(ORACLE_HOME=/logi/ora10205_psu4)
(ENVS=LD_LIBRARY_PATH=/usr/lib64:/logi/ora10205_psu4/lib:/logi/ora10205_psu4/lib32)
(PROGRAM=hsodbc)
)

———————————

I reloaded the listener, created the DB_LINK.
Until now, everything woked. But, When I try the db_link, I have this error message.

SQL> select * from “mantis_user_table”@PG_LINK;
select * from “mantis_user_table”@PG_LINK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
[Generic Connectivity Using ODBC]DRV_InitTdp: DB_ODBC_INTERFACE (718): ; [C077]
Could not find symbol ‘SQLAllocConnect’ in dynamic library
DB_ODBC_INTERFACE (722): ; [C079] Failed to load dynamic library
‘/usr/lib64/libodbc.so’
ORA‑02063: preceding 3 lines from PG_LINK

I tried with different libraries into HS_FDS_SHAREABLE_NAME variable (/usr/lib64/psqlodbc.so and /usr/lib64/libodbc.so), but
I have the same issue.

Do you have any idea please?

Reply
JM says:
October 14, 2014 at 15:28
I think the problem is because of our 64 bits Linux which is incompatible with 32bits HSODBC.
Am I right?

Reply
dbaspot says:
October 14, 2014 at 18:33
Hi,
According to MOS 264567.1:
PLEASE PAY ATTENTION: CURRENTLY (UP TO 10gR2) HSODBC IS ONLY PORTED TO

LINUX X86; NOT TO Linux X86‑64bit.
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 11/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
LINUX X86; NOT TO Linux X86‑64bit.

diego says:
December 4, 2014 at 06:55
Hi works but! is not retrieving any character,text,string fields Do I need extra configuration? thanks

Reply
dbaspot says:
December 5, 2014 at 09:38
Please add to .odbc.ini charset entry:
CHARSET = “your_PostgreSQL_charset”
and try again.

Reply
diego says:
December 6, 2014 at 03:55
I solved using Postgres ANSI instead of unicode

Josemar Furega᾽i de Abreu Silva says:
February 26, 2015 at 19:13
This post helped me a lot !!! So let me give my contribution. Oracle parses SQL statement before send throw database link to find
out table specifications. Oracle defaults behavior is convert names UPPERCASE. PostgreSQL default behaviors is convert names
to lowercase.

My query was returning error “ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message” “ERROR:
relation “INFORMATION_SCHEMA.TABLES” does not exist;”.

Try #1: Referencing table name by schema and tablename all in lowercase . – Does not work , because Oracle convert statement to
uppercase (by default) and try to ask PostgreSQL for table description details using (schema, tablename) does not find out
(schema,table) in UPERCASE. PostgreSQL does not seek (schema,tablename) in UPPERCASE.

SQL> select * from information_schema.tables@DBPG_LNK;
select * from information_schema.tables@DBPG_LNK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
ERROR: relation “INFORMATION_SCHEMA.TABLES” does not exist;
No query has been executed with that handle {42P01,NativeErr = 1}
ORA‑02063: preceding 3 lines from DBPG_LNK

Try #2: Referencing table name by schema and tablename all in lowercase surrounded by quotes “.” – Does not work , because
Oracle convert surrounded text in a tablename with a dot “.” inside and try to ask PostgreSQL for table description details
WITHOUT OWNER and with a tablename quoted with a “owner.tablename”. PostgreSQL does not find out a table with from
public schema of local user connection with name “schema.tablename”. PostgreSQL does not seek ( public schema, tablename
with name owner, dot, tablename) in UPPERCASE.

SQL> select * from “information_schema.tables”@DBPG_LNK;
select * from “information_schema.tables”@DBPG_LNK
*
ERROR at line 1:
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message:
ERROR: relation “information_schema.tables” does not exist;
No query has been executed with that handle {42P01,NativeErr = 1}
ORA‑02063: preceding 3 lines from DBPG_LNK

Try #3: Referencing table name by surrounded by quotes schema in lowercase and surrounded by quotes tablename in lowercase
as this (“owner”.”tablename”) – Yes it’s works, because Oracle parses read separated owner and tablename. And ask to
PostgreSQL correct lowercase of owner and tablename. PostgreSQL find out a table of schema=owner and tablename=tablename
everything in lowercase. PostgreSQL does seek table correctly.

SQL> select * from “information_schema”.”tables”@DBPG_LNK;

:
correct data
:

Reply
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 12/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
Reply
Henrique says:
March 5, 2015 at 18:06
Hi Josemar,

I’m almost making this work, I was hoping you could give me a hand.
All my config looks good, I’m using HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1.
But even when I query using double quotes select * from “schema”.”table”@PGLINK;
I get an error:

ORA‑00600: internal error code, arguments: [kpnfch‑1], [1406], [], [], [], [],
[], [], [], [], [], []
ORA‑01406: fetched column value was truncated
ORA‑02063: preceding line from PGLINK

Thanks!!

Reply
dbaspot says:
March 5, 2015 at 19:37
Please try to find out which column generates this error.
select “column1” from “schema”.”table”@PGLINK;
instead of star ‘*’.
It might be a datatype mapping issue.

Henrique says:
March 6, 2015 at 12:57
Hi dbaspot,

I´ve did that just some hours before seing your reply, and it works that way! But now I guess I reached the last issue, which I
assume involves datatype, on postgres I have some columns that are type boolean, If I include them on the query it fails with the
error message I mentioned before. Now I´m trying to find a way to convert when selecting those boolean columns. If you have
any idea, please let me know and thanks for your help/prompt response!

Reply
dbaspot says:
March 6, 2015 at 13:18
I would try to convert boolean to anything else before ge ing a column value from Oracle, for instance:
select “col_boolean::int4″ from “schema”.”table”@PGLINK;

Reply
rick says:
March 9, 2015 at 13:49
Hi, me again!

I was able to make it work on my VM but now, I´m facing issues with my actual dev server.
ODBC was install / configured successfully (i can test with “isql PGLINK” and then do a select on postgre db, it works fine.)
but now, when I configure listener and tnsnames / create a dblink I get this error:

ORA‑28545: erro diagnosticado pelo Net8 ao conectar com um agente
Unable to retrieve text of NETWORK/NCR message 65535
ORA‑02063: preceeding 2 lines from PGLINK
28545. 0000 – “error diagnosed by Net8 when connecting to an agent”
*Cause: An a empt to call an external procedure or to issue SQL
to a non‑Oracle system on a Heterogeneous Services database link
failed at connection initialization. The error diagnosed
by Net8 NCR software is reported separately.
*Action: Refer to the Net8 NCRO error message. If this isn’t clear,
check connection administrative setup in tnsnames.ora
and listener.ora for the service associated with the
Heterogeneous Services database link being used, or with
‘extproc_connection_data’ for an external procedure call.
Erro na linha: 3 Coluna: 37

my tnsnames / listener are listed below:

TNSNAMES.ORA
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 13/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
TNSNAMES.ORA
———–
DEV =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle‑dev.mx)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = dev.mx)
)
)

PGLINK =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST = oracle‑dev.mx)(PORT = 1521))
(CONNECT_DATA=(SID_NAME = PGLINK))
(HS=OK)
)

LISTENER.ORA
————
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle‑dev.mx)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=PGLINK)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(PROGRAM=dg4odbc)
)
)

ADR_BASE_LISTENER = /u01/app/oracle

if you have any suggestion, please let me know! thanks!

Reply
John says:
March 9, 2015 at 20:31
Hi guys, any of you got this error?

8528. 00000 – “Heterogeneous Services datatype conversion error”
*Cause: Either an Oracle datatype could not be converted to a non‑Oracle
datatype, or a non‑Oracle datatype could not be converted
to an Oracle datatype. The following are possible reasons for
for the conversion failure:
— overflow problems (in the case of numbers)
— length limitations (in the case of character strings)
— invalid values passed into the conversion routines
*Action: Contact customer support of the agent vendor. If the problem is
due to size discrepancies between Oracle and the non‑Oracle system,
it may not be possible to convert the value.

thanks

Reply
saravanan says:
April 28, 2015 at 15:06
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 14/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
April 28, 2015 at 15:06
Hi,

i created dblink,but its not retrieving any data.
if i used desc “tablename”@dblinkname its showing the column details.

thanks in advance

Reply
OvivO says:
May 22, 2015 at 14:45
Hello All,

Really helpful article and I was able to connect Oracle to PostgreSQL.
There were some issues on the way, but were able to solve it using also other sources.
Just to contribute a bit to the thread:
– Had problems with .odbc.ini – resolved after removing all spaces in lines where parameters and values are defined, so be er to
have no spaces at ^ of line and before/after ‘=’
– had also some problems with Listener SID_DESC, but this is because I haven’t read how to do it properly first time. I have
added multiple complete Listener description blocks in listener.ora, but not a SID_DESC blocks only.

Cheers,
OvivO

Reply
JM says:
June 15, 2015 at 18:04
Hi Guys,

I have a NLS conversion using my db_link betwwen ORACLE and PostgreSQL.

My Oracle is a 11.2.0.3 WE8ISO8859P15 NLS database. And my postgreSQL use UTF8.

When I try this SQL request :
SQL> select “id” ID,
“summary” DESCRIPTION,
CONVERT(“summary”, ‘WE8ISO8859P15’, ‘UTF8’) CONVERTED_DESC
from “mantis_bug_table”@PG_LINK

I have:
[1561] Probl?smes PA et adresse interne sur matricule 220899…

The french accent aren’t converted and the “è” character appears as “?s” in this example.

This is my configuration:

postgresql‑odbc.x86_64 08.04.0200‑1PGDG.rhel5 installed

My [.odbc.ini]

[ODBC Data Sources]
PG_LINK = PostgreSQL
[PG_LINK]
Debug = 1
CommLog = 1
ReadOnly = no
Driver = /usr/lib64/psqlodbc.so
Servername = xxxxx
FetchBufferSize = 99
Username = xxxxxx
Password = xxxxxxx
Port = 5600
Database = xxxxx
Trace=0

TraceFile=odbctrace.out
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 15/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
TraceFile=odbctrace.out
[Default]
Driver = /usr/lib/liboplodbcS.so

My [initPG_LINK.ora]:

HS_FDS_CONNECT_INFO = PG_LINK
HS_FDS_TRACE_LEVEL = DEBUG
#HS_FDS_TRACE_LEVEL = OFF
HS_FDS_SHAREABLE_NAME=/usr/lib64/psqlodbc.so
HS_FDS_FETCH_ROWS=1
HS_FDS_SQLLEN_INTERPRETATION=64
set ODBCINI=/home/oracle/.odbc.ini
#HS_NLS_NCHAR=UTF8
#HS_NLS_NCHAR=UCS2
HS_KEEP_REMOTE_COLUMN_SIZE=ALL
HS_NLS_LENGTH_SEMANTICS=CHAR
#HS_LANGUAGE=FRENCH_FRANCE.WE8ISO8859P1

As you can see I tried to modify HS_NLS_NCHAR and HS_LANGUAGE but didn’t work.

Is anyone can help me please? :)

Thanks in advance
JM

Reply
Moez BOUCHRIHA says:
December 17, 2015 at 17:44
please! How can i call a postgres procedure or function from oracle via pglink?

Reply
Lizeth Solis says:
May 9, 2016 at 23:40
Hi, please I have a HS installed and configured, I need to execute this:
select * from “schema”.”table”@db_pg where “ini_date” = ’01/01/2016′;
But I got this error ORA‑00997: illegal use of LONG datatype.
I tried with ‘2016‑01‑01’ and it doesn’t work either.
Please somebody could help me please.

Reply
Anonymous says:
May 10, 2016 at 10:26
Hi, please try to select columns directly instead of ‘*’ and one by one check which one causes the error to come up.

Reply
Lizeth Solis says:
May 10, 2016 at 15:17
Thank you for your answer. I tried it:
select “campo1”, “campo2” from “schema”.”table”@db_pg where “ini_date” = ’01/01/2016′
and I got the same error. But if I don´t write the “where clause” the query goes fine.
I think the error is in the where, that is a date field.

I.K. says:
May 10, 2016 at 17:05
If “ini_date” is date type, you try to match with a string ’01/01/2016′, so first you have to convert string to date. In oracle
WHERE clause would look somehow similar to this:
where “ini_date” = to_date(’01/01/2016′, ‘dd/mm/yyyy’) so you have to check how this is done in Postgres

Puneet says:
May 25, 2016 at 07:40
Thank you foe Guide I an facing following issue.

select * from “abc”@hslink;
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 16/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
select * from “abc”@hslink;
ct * from “abc”@hslink
*
ERROR at line 1:
ORA‑28513: internal error in heterogeneous remote agent
ORA‑ 02063: preceding line from HSLINK

Reply
Puneet says:
May 25, 2016 at 14:54
Need Your Immediate help. I have setup every thing. even DB link created successfully but when trying to access the table
using Link facing the issue.

I have Oracle on windows and Postgres also running on windows.

Reply
Puneet says:
May 30, 2016 at 09:12
Hi, Please help. I am stuck on this.

Reply
Anonymous says:
May 30, 2016 at 21:14
Have you tried to select each column separately instead of using star ‘*’ ? Try this out to eliminate one problem after
another.

Puneet says:
May 31, 2016 at 12:28
yes i have checked through column name. still have same issue. please help

OvivO says:
June 1, 2016 at 07:17
Hi Puneet,

Can you please post your configuration file, masking passwords, hostnames and ports, of course?
Also you may activate tracing on ODBC gateway and driver so that error is logged and then check it, it might help a lot.

Regards,
OvivO

Puneet says:
June 1, 2016 at 08:00
Hi Ovivo.

as my Oracle server installed on windows machine so I have created the system DSN for the same. and Connection is OK.

Please find the initpg_LINK.ora
————————————————–
HS_FDS_CONNECT_INFO = PG_LINK
HS_FDS_TRACE_LEVEL = Debug
————————————————–
tnsname.ora
————————–
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

ORCL =
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 17/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = NG5174.newgen.co.in)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)

PG_LINK =
(DESCRIPTION=
(ADDRESS=(PROTOCOL= TCP)(HOST = NG5174.newgen.co.in)(PORT= 1521))
(CONNECT_DATA=(SID=PG_LINK))
(HS=OK)
)
———————————————————————‑
listener.ora
——————————
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = “EXTPROC_DLLS=ONLY:D:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll”)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = NG5174.newgen.co.in)(PORT = 1521))
)
)

SID_LIST_LISTENER =
(SID_LIST=
(SID_DESC=
(SID_NAME = PG_LINK)
(ORACLE_HOME=D:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM=dg4odbc)
)
)
ADR_BASE_LISTENER = D:\app\Administrator
———————————‑

Puneet says:
June 1, 2016 at 08:06
then created the db link using below.

CREATE PUBLIC DATABASE LINK PGlinknew CONNECT TO “user” IDENTIFIED BY “password” using ‘PG_LINK’;

OvivO says:
June 4, 2016 at 00:48
Hi Puneet,

You might merge Sid List Listener records into single one as currently you have two. You should check syntax, this is how
I made it work. Then restart listener to reread file.
You can telnet postgres host on port 1521, right? Last thing: on postgres side you should allow Oracle host/ip to connect to
Postgres DB.

Cheers,
OvivO

NY says:
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 18/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
NY says:
May 25, 2016 at 14:47
I have an error in my listener list I want to access Postgres from Oracle I have Oracle database and I am trying to connect to
Postgres
here is my listerner.ora and the error I am receiving

TNS‑01155: Incorrectly specified SID_LIST_LISTENER parameter in LISTENER.ORA

# listener.ora Network Configuration File: /oracle/12c/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = my_DB)
(ORACLE_HOME = /oracle/12c)
(GLOBAL_DBNAME = my_DB.world)
)

(SID_DESC =
(SID_NAME = PG_KING)
(ORACLE_HOME = /oracle/12C)
(PROGRAM = dg4odbc)
(ENVS=LD_LIBRARY_PATH=/usr/lib64:/oracle/12c/lib:/oracle/12c/hs/lib)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

ADR_BASE_VoicePortal_LISTENER = /oracl

I should note add the Postgres db in same SID_list?

Reply
NY says:
May 25, 2016 at 18:38
I did all the steps and I am still receiving this error:
An error was encountered performing the requested operation:

ORA‑28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA‑02063: preceding 2 lines from VOICEPORTAL
28545. 0000 – “error diagnosed by Net8 when connecting to an agent”
*Cause: An a empt to call an external procedure or to issue SQL
to a non‑Oracle system on a Heterogeneous Services database link
failed at connection initialization. The error diagnosed
by Net8 NCR software is reported separately.
*Action: Refer to the Net8 NCRO error message. If this isn’t clear,
check connection administrative setup in tnsnames.ora
and listener.ora for the service associated with the
Heterogeneous Services database link being used, or with
‘extproc_connection_data’ for an external procedure call.
Vendor code 28545

Reply
I.K. says:
May 26, 2016 at 14:49
Hello NY,
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 19/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
Hello NY,

On Postgres side – you should also allow connections from host where Oracle is installed, so that Postgres server allow
connections. Have you done this?

Regards,
I.K.

Reply
NY says:
May 27, 2016 at 20:28
The problem has been resolved thank you!

Reply
I.K. says:
May 27, 2016 at 23:11
Hi NY, this is great! Can you please share what was the problem and resolution? It will serve for future reference. Thanks!
Regards,
I.K.

NY says:
June 8, 2016 at 15:05
I had a problem in the spelling only in my listener.
But I want to post another problem.
Select statement is working properly but running procedure using the db link is giving me this error:

Error(1): ORA‑04052: error occurred when looking up remote object ORA‑00604: error occurred at recursive SQL level 1
ORA‑28500: connection from ORACLE to a non‑Oracle system returned this message: ERROR: schema does not exist.

Any suggestion please.
Thank you.

I.K. says:
June 9, 2016 at 08:05
Not sure you can run a procedure from Oracle on Postgres side using generic ODBC Gateway. I think you should use
Postgres Gateway from Oracle to achieve it.

vic says:
June 2, 2016 at 14:40
Hi, thanks for this im trying to setup but get error. ORA‑12154: TNS:could not resolve the connect identifier specified. Here is my
files.

listener.ora

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = PostgreSQL30)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = dg4odbc)
)
)

LISTENER =
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 20/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = GR90AVA03E.logon.ds.com)(PORT = 1521))
)
)

DEFAULT_SERVICE_LISTENER = (XE)

initPostgreSQL30.ora

HS_FDS_CONNECT_INFO = PostgreSQL30
HS_FDS_TRACE_LEVEL = 0

tnsnames.ora

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = GR90AVA03E.logon.ds.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)

EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)

ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)

PostgreSQL30 =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=GR90AVA03E.logon.ds.com)(PORT=1521))
(CONNECT_DATA=(SID=PostgreSQL30))
(HS=OK)
)

create database link PostgreSQL30 connect to “postgres” identified by “postgres” using ‘PostgreSQL30’;

ORA‑12154: TNS:could not resolve the connect identifier specified
12154. 00000 – “TNS:could not resolve the connect identifier specified”
*Cause: A connection to a database or other service was requested using
a connect identifier, and the connect identifier specified could not
be resolved into a connect descriptor using one of the naming methods
configured. For example, if the type of connect identifier used was a

net service name then the net service name could not be found in a
https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 21/22
9/6/2016 How to access PostgreSQL from Oracle database | DBA spot
net service name then the net service name could not be found in a
naming method repository, or the repository could not be
located or reached.

Reply
vic says:
June 2, 2016 at 14:52
nevermind. thank you, its working

Reply

Blog at WordPress.com.

The Enterprise Theme.

https://dbaspot.wordpress.com/2013/05/29/how­to­access­postgresql­from­oracle­database/ 22/22

Anda mungkin juga menyukai