Connecting Oracle to PostgreSQL
The following instructions show you how to connect Oracle on Linux to PostgreSQL. For further information about DG4ODBC, refer to our DG4ODBC tutorial.
- Download the 64-bit PostgreSQL ODBC driver for Linux.
- Install and license the PostgreSQL ODBC driver on the machine where Oracle is installed.
For installation instructions, refer to the ODBC driver documentation.
Note You need the unixODBC Driver Manager installed on your machine. The Easysoft distribution includes a version of the unixODBC Driver Manager that the Easysoft PostgreSQL ODBC driver has been tested with. The Easysoft driver setup program gives you the option to install unixODBC.
- Create an ODBC data source in
/etc/odbc.inithat connects to the PostgreSQL database you want to access from Oracle. For example:[POSTGRES_SAMPLE] Driver=Easysoft ODBC-Postgres Server Description=Easysoft ODBC-Postgres Server Server=192.0.2.1 Port=5432 Database=employees User=postgres Password=p4550rd Logging=No LogFile= Encrypt=No
- Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin ./isql.sh -v POSTGRESQL_SAMPLE
At the prompt, enter
helpto display a list of tables. To exit, press Return in an empty prompt line.If you're unable to connect, refer to this article for assistance.
- Create a DG4ODBC init file. To do this, change to the
hs/adminsubdirectory. For example:cd $ORACLE_HOME/product/11.2.0/xe/hs/admin
Create a copy of the file
initdg4odbc.ora. Name the new fileinitpostgresql.ora. - Ensure these parameters and values are present in your init file:
HS_FDS_CONNECT_INFO = my_postgresql_odbc_dsn
Replace
my_postgresql_odbc_dsnwith the name of a PostgreSQL ODBC driver data source that connects to the target PostgreSQL server. For exampleHS_FDS_CONNECT_INFO = "POSTGRES_SAMPLE"
- Comment out the line that enables DG4ODBC tracing. For example:
#HS_FDS_TRACE_LEVEL = <trace_level>
- Add an entry to
listener.orathat creates aSID_NAMEfor DG4ODBC. For example:SID_LIST_LISTENER = (SID_LIST = (SID_DESC= (SID_NAME=postgresql) (ORACLE_HOME=$ORACLE_HOME) (PROGRAM=dg4odbc) ) ) - Add a DG4ODBC entry to
tnsnames.orathat specifies theSID_NAMEcreated in the previous step. For example:POSTGRESQL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle_host)(PORT = 1521)) (CONNECT_DATA = (SID = postgresql) ) (HS = OK) )Replace
oracle_hostwith the host name of your Oracle machine. - Start (or restart) the Oracle Listener. For example:
lsnrctl stop lsnrctl start
- Connect to your Oracle database in SQL*Plus.
- In SQL*Plus, create a database link for the target PostgreSQL server. For example:
CREATE PUBLIC DATABASE LINK postgresqllink CONNECT TO "my_postgresql_user" IDENTIFIED by "my_postgresql_password" USING 'postgresql'; SELECT * FROM employees@postgresqllink
Notes
- If you have problems connecting to PostgreSQL from Oracle, enable DG4ODBC tracing and check the trace files written to the
hs/logdirectory. To enable DG4ODBC tracing, add the lineHS_FDS_TRACE_LEVEL = DEBUGtoinitpostgresql.oraand then start or restart the Oracle listener. If thelogdirectory does not exist, create it. For example:mkdir log chmod +w log
- If you get error "ORA-00997: illegal use of LONG datatype," add one of the following entries to your ODBC data source:
DisguiseLong=1 # For non-Wide PostgreSQL long columns LimitLong=size in bytes # If this value is too big you will get ORA-00997
–Or–
DisguiseWlong=1 LimitLong=size in bytes# If this value is too big you will get ORA-00997
- If you get "ORA-28562: Heterogeneous Services data truncation error," when working with PostgreSQL data in Oracle, we may have a workaround for you, but you need to understand the implications of using it. For more information, contact the Easysoft Support team ( ).