π Introduction
In some enterprise environments, there’s a need to query or migrate data directly between Oracle and PostgreSQL without using ETL tools or third-party connectors.
Oracle’s Heterogeneous Services (HS) feature allows exactly that — it lets Oracle access non-Oracle databases such as PostgreSQL, MySQL, SQL Server, etc., using Oracle Database Gateway for ODBC (DG4ODBC).
In this article, we’ll walk through how to connect Oracle Database to PostgreSQL using HS, create a database link, and migrate data from Oracle to PostgreSQL seamlessly.
π§© 1. What Is Oracle Heterogeneous Services (HS)?
Heterogeneous Services is an Oracle feature that allows communication between Oracle and non-Oracle data sources through ODBC drivers.
It acts as a bridge layer — Oracle SQL queries are translated into the syntax of the remote system (PostgreSQL, in this case).
⚙️ 2. Prerequisites
Before starting, make sure you have:
| Requirement | Description |
|---|---|
| Oracle Database | Version 12c or above |
| PostgreSQL Database | Version 12 or above |
| ODBC Driver | PostgreSQL ODBC driver installed on Oracle server |
| Oracle Client utilities | tnsnames.ora, listener.ora, sqlnet.ora configured |
| OS Access | Root or sudo privileges to edit Oracle networking files |
π️ 3. Install PostgreSQL ODBC Driver on Oracle Server
For Linux:
Verify installation:
You should see:
π§Ύ 4. Configure ODBC DSN
Edit the ODBC configuration file (/etc/odbc.ini) and add a DSN for PostgreSQL:
Test connectivity:
If successful, you’ll see:
π§ 5. Create Oracle HS Initialization File
Create file:
Add:
π 6. Update Oracle Network Files
π listener.ora
Add an entry for HS service:
Restart listener:
π tnsnames.ora
Add TNS entry:
π§ 7. Create Database Link in Oracle
Now connect to Oracle DB and create the link:
Test the connection:
If you can query successfully, your HS link is working fine π―
π¦ 8. Migrate Data from Oracle to PostgreSQL
Example PL/SQL block to copy data from Oracle table to PostgreSQL table:
π 9. Verification
From Oracle:
From PostgreSQL:
Both counts should match ✅
π Conclusion
Using Oracle HS with DG4ODBC, you can directly integrate Oracle and PostgreSQL without ETL tools.
This approach is especially useful for incremental data migration, cross-database reporting, and archival automation.
For large-scale migrations, consider Oracle GoldenGate or Oracle Data Integrator (ODI), but for medium-volume transactional data, HS DB Link is a powerful and lightweight solution.
No comments:
Post a Comment