oracle_fdw for querying Oracle from PostgreSQL

oracle_fdw lets PostgreSQL read and write Oracle tables through foreign tables during a phased migration. This page covers the setup, the decisions that shape it and where it stops working.

On this page

Why teams run oracle_fdw for querying Oracle from PostgreSQL

Teams run oracle_fdw when a PostgreSQL platform must read or update Oracle data while a migration or coexistence period is still underway. The usual situation is an application that has moved to PostgreSQL in stages, with some reports, batch jobs or write paths still depending on tables that remain in Oracle. oracle_fdw is a PostgreSQL foreign data wrapper for Oracle, so it lets PostgreSQL query those remote tables as if they were local, without a separate extract job for every read. A superuser enables it with CREATE EXTENSION oracle_fdw and then defines a foreign server whose dbserver option points at the Oracle database, with user mappings that tell PostgreSQL which Oracle account to use for each role. The extension is maintained in the project's oracle_fdw repository, which is the place to confirm supported PostgreSQL and Oracle client combinations before you plan.

Implement oracle_fdw when the data stays in Oracle for a defined period and the cost of moving it all at once is higher than the cost of a bridge. Typical cases include reference data still owned by an Oracle system, a phased cutover where a subset of applications moves first, or reconciliation queries that compare both sides during parallel running. A full migration is the better path when the Oracle dependency has no end date, when application logic relies on Oracle-specific behavior that the bridge cannot reproduce, or when the team cannot accept cross-database query latency on hot paths. Decide the boundary in writing before build starts: which schemas and tables are foreign, who owns each one, and when each bridge is removed.

What oracle_fdw does inside PostgreSQL

oracle_fdw sits inside PostgreSQL's foreign data wrapper model, so Oracle tables appear as objects you can query from SQL. The cards below cover what the wrapper exposes, where its behavior is limited, and what to confirm before relying on it for a migration.

Oracle tables as foreign tables

Once the extension is installed and a foreign server points at your Oracle database, you define foreign tables that map to Oracle tables or views. Queries against them run from PostgreSQL, so applications and reports can read Oracle data during a transition without a separate copy. Check that each column's data type mapping matches what your applications expect, especially for dates, numbers and LOB columns.

oracle_fdw repository

Writing through the wrapper

The wrapper can also modify Oracle data from PostgreSQL when the foreign table and the Oracle user permit it. This is useful for keeping Oracle synchronized during a phased cutover, but every write path needs a clear owner, transaction boundary and rollback plan. Confirm for your oracle_fdw version which write operations are supported and how errors surface back to the PostgreSQL session.

Filter pushdown to Oracle

Where the wrapper can, it passes WHERE conditions and similar restrictions to Oracle, so less data crosses the network. Pushdown depends on the expression, the data types and the PostgreSQL planner's choices, so a query that looks selective may still read far more rows than expected. Use EXPLAIN VERBOSE on representative queries to see what is actually sent to Oracle.

Credentials through user mappings

Foreign servers hold the connection target, and user mappings tie each PostgreSQL role to an Oracle account. Plan these mappings deliberately so that application roles do not all share one powerful Oracle login. Creating the extension and servers requires superuser rights, so decide early who administers the wrapper and how those credentials are stored and rotated.

Its place in the FDW model

oracle_fdw is one implementation of PostgreSQL's foreign data wrapper interface, which other wrappers also use for remote sources. Its behavior, including pushdown, type handling and write support, is defined by the extension rather than by core PostgreSQL. Confirm the extension version that matches your PostgreSQL major version and the Oracle client libraries on the database host before you plan the build.

Limits to verify before cutover

The wrapper depends on the Oracle client libraries installed on the PostgreSQL server, and remote queries add latency and a dependency on Oracle availability. Large joins across foreign and local tables can be slow, and some Oracle-specific features will not behave the same in PostgreSQL. Test performance, data types and failure handling with your own workload, and confirm the limitations listed in the repository for your target version.

Oracle client and PostgreSQL version requirements to confirm first

oracle_fdw does not talk to Oracle directly. It links against Oracle client libraries installed on each PostgreSQL host, so the client version is a property of the database server, not of the Oracle database. Client packages come from Oracle and carry their own licence terms, and they must be installed in a location the PostgreSQL service can load at runtime. Confirm which client release the extension version supports, then check that the same release works with the Oracle database release you are connecting to.

  • Client version pairing: Check the oracle_fdw repository for the client releases each extension version is built and tested against.
  • Library path: Confirm the shared libraries resolve for the PostgreSQL service account, not only for your interactive shell.
  • Consistent hosts: Every PostgreSQL server that runs the extension, including standbys and rebuilt nodes, needs the same client version.
  • Licence review: Have legal review how Oracle client packages may be installed and redistributed in your images or configuration management.
  • Upgrade coupling: Record the client version next to the PostgreSQL and extension versions so a later client update is tested as its own change.

Before building, write down the exact client release and where it is installed on each host.

Foreign server, user mapping and access design choices

This table compares the main design choices for oracle_fdw foreign servers, user mappings and Oracle accounts, with the typical fit for each and who in the client organization should approve it. Read each row as a decision to make before any foreign table is created, since changing these later usually means reworking grants and credentials. The main takeaway is that read-only, narrowly scoped Oracle accounts tied to a named staging schema are the safer default during a migration.

DecisionOptionWhen it fitsWho should approve
Foreign server scopeOne foreign server per Oracle databaseSingle source system with one service account and a stable connect stringOracle DBA and the data owner of the source system
Foreign server scopeOne foreign server per Oracle schemaSeveral schemas with different owners or separate retention rulesOracle DBA, data owners for each schema
User mappingShared mapping for all PostgreSQL rolesSmall team, batch loads run by one service roleSecurity team and the Oracle account owner
User mappingPer-role mapping tied to named PostgreSQL rolesSeveral teams query Oracle and need separate audit trailsSecurity team and identity administrators
Oracle account privilegesRead-only account on the required tables and viewsExtraction, reconciliation and phased cutover readsOracle DBA and the security team
Oracle account privilegesRead-write account on specific staging tablesWriting results back to Oracle during coexistence, with narrow grantsOracle DBA, application owner and change board
Foreign table locationDedicated staging schema in PostgreSQLMigration load and validation work that should not be exposed to applicationsPostgreSQL DBA and the application owner
Foreign table locationApplication schema alongside native tablesLong-running coexistence where applications query Oracle data directlyApplication owner, PostgreSQL DBA and architecture review

Implementation sequence from extension install to cutover

The sequence moves oracle_fdw from a tested connection on a non-production PostgreSQL to verified, phased data moves and a retired link. Each step produces a artifact that the next step depends on, so a failed check stops the work before data moves.

  1. Confirm the Oracle client and network path

    Before touching PostgreSQL, the platform or database team installs the Oracle client libraries that match the PostgreSQL host's operating system and confirms that the PostgreSQL server can reach the Oracle listener on the required host and port through the firewalls in between. Ask the Oracle DBA which client version and connection string format they support, and confirm it with the oracle_fdw documentation for the version you plan to install. The output is a connection test from the PostgreSQL host using the Oracle client tools, recorded with the host, port, service name and client version. Do not continue until that test succeeds from the same host that runs PostgreSQL.

  2. Install the extension on a non-production server

    A PostgreSQL administrator builds oracle_fdw against the installed PostgreSQL major version and Oracle client, then runs CREATE EXTENSION oracle_fdw in a non-production database as a superuser. Confirm the build is compatible with your PostgreSQL major version before you install it, since the extension is compiled against the server. The output is a database where the extension is listed in pg_extension, the version is recorded in your change log, and a test query against a sample Oracle table succeeds. Keep this server separate from production until the later steps pass.

  3. Create foreign servers and user mappings

    The administrator creates a foreign server with CREATE SERVER whose dbserver option points at the Oracle database, then creates a user mapping for each PostgreSQL role that needs access. Each mapping should point to a dedicated Oracle account granted only the SELECT privileges on the tables in scope, and where writes are needed, only the specific INSERT, UPDATE or DELETE grants on the target tables. The Oracle DBA owns those accounts and their grants. The output is a mapping inventory listing each PostgreSQL role, its Oracle account, the schemas it can reach and the date the grants were reviewed. Confirm that no mapping uses a broad Oracle administrative account.

  4. Import foreign schemas into a staging schema

    Use IMPORT FOREIGN SCHEMA to bring the agreed Oracle tables into a staging schema in PostgreSQL, rather than into the schemas that applications use. Review the generated foreign table definitions for column types, nullability, and any Oracle types that map imperfectly to PostgreSQL types, such as large objects, dates with time zones and number precision. Record any table you chose to exclude. The output is a foreign table inventory with the mapped column types and a list of exceptions that the migration team has approved or rejected.

  5. Validate row counts and column types

    The data team compares row counts between each Oracle source table and its foreign table, then checks sample rows and aggregate values such as sums, minimums, maximums and distinct counts on key and numeric columns. Run the same checks on the Oracle side with its own queries so the comparison does not rely on oracle_fdw alone. Check that date, timestamp and numeric values round-trip without change. The output is a reconciliation report per table showing the source count, target count, the checks run and any differences with their causes. A table with unexplained differences does not move to the next step.

  6. Run phased data moves into PostgreSQL

    Move data in batches, one table group at a time, using INSERT ... SELECT from the foreign tables into native PostgreSQL tables that the target application will read. Schedule each batch during a window agreed with the application owners, and capture the Oracle system change point or a last-modified marker where your data model supports it, so each later pass moves only new or changed rows. Write each batch to a log with its start and end time, row count and any errors. Note that oracle_fdw reads over the network on every query, so large moves depend on the network and Oracle capacity. The output is a batch log and a reconciliation run after every batch that matches the validation standard from the previous step.

  7. Cut over and retire the foreign link

    When the final pass has matched the source, the team points applications at the PostgreSQL tables, freezes writes on the Oracle side for the tables being cut, and runs one last reconciliation. After the cutover is confirmed, drop the user mappings, the foreign server and the foreign tables with DROP statements, revoke the Oracle grants and disable the Oracle accounts that were created for the migration. Confirm with the Oracle DBA that the accounts no longer connect. The output is a signed-off cutover record, a removal log showing each object dropped and each account disabled, and a note that the PostgreSQL extension can be removed or kept for future use.

Using oracle_fdw to move data in a phased migration

A phased migration with oracle_fdw works in three stages: read Oracle data from PostgreSQL while both systems run, copy batches into native PostgreSQL tables, and switch application reads once reconciliation passes. A foreign table makes Oracle data visible to PostgreSQL queries through the oracle_fdw extension, so the team can build and test new PostgreSQL reports before any data has moved. The foreign tables are a bridge, not the destination: each foreign table reads from Oracle on every query, so it inherits Oracle's load, network latency and availability for as long as it is used in production paths.

Type mapping is the first place where copied data changes meaning. Oracle NUMBER without precision, DATE (which carries a time component), VARCHAR2 with byte or character semantics, and empty-string handling all need an explicit target type in the CREATE FOREIGN TABLE definition and in the native table DDL. Confirm each mapping against your own column inventory and test it with representative values, including nulls, zero-length strings and timestamps near daylight saving boundaries, because a silent rounding or truncation rarely raises an error. Sequences, triggers, packages, stored procedures and views do not travel with the foreign table. Each must be rebuilt in PostgreSQL, or its behavior must be replaced in the application, and the team should list every one before the first batch runs.

Reconciliation must pass before cutover, and it should compare more than row counts. Compare per-table row counts, sums of key numeric columns, min and max of date columns, and a hash over ordered key and value columns, run against the same snapshot or a frozen window on both sides. Agree the tolerance for any difference in writing, keep the reconciliation queries in version control, and repeat them after the final incremental load. Confirm the exact behavior of the Oracle client and the oracle_fdw release you deploy with your own test data before relying on these queries, using the oracle_fdw repository as the starting reference.

Limits that change the design

oracle_fdw makes Oracle tables look like local PostgreSQL tables, which is convenient during a migration and easy to over-trust. The cards below cover the limits that most often change how the foreign tables, credentials and exit plan should be designed. Verify each one against the current oracle_fdw repository documentation before you commit to a design.

Network cost of large scans

A query that touches a large Oracle table can pull rows across the network into PostgreSQL before any filtering happens that Oracle could have done. Check which predicates and joins are pushed down to Oracle for your query shapes, using EXPLAIN VERBOSE on representative statements. Keep bulk copies on the migration path and reserve foreign tables for filtered reads and reconciliation. Ask your DBA to measure the round trips from the PostgreSQL host to the Oracle listener.

oracle_fdw repository

Dependence on Oracle client builds

oracle_fdw loads Oracle client libraries at build and run time, so the PostgreSQL major version, the extension build and the Oracle client version must agree on each host. A PostgreSQL upgrade can require rebuilding the extension against a matching client. Record the exact client version in your build inventory and confirm the supported combinations in the repository before you schedule an upgrade window.

Credentials stored in PostgreSQL catalogs

User mappings hold the Oracle account name and password, and PostgreSQL catalog access can expose them to anyone with sufficient privileges on the database. Decide which role owns the foreign server, restrict who can read pg_user_mappings, and use a least-privilege Oracle account that only sees the tables the migration needs. Confirm how the extension stores and displays these options in your version before you grant broad read access.

Transaction and error behavior across systems

PostgreSQL and Oracle run separate transaction managers, so a write that spans both systems is not atomic in the way a single-database transaction is. An Oracle error can surface as a generic PostgreSQL error, and a connection drop can leave a partial result. Keep writes to Oracle in small, idempotent batches with reconciliation counts, and test failure handling with a deliberate network interruption.

Oracle features that do not carry over

Oracle-specific objects such as packages, synonyms, database links, and certain data types may not map cleanly to foreign tables, and some constructs will not push down. Inventory the Oracle objects your application reads and write down the type mapping for each column, including dates, numbers with precision and LOBs. Treat any column whose mapping you cannot explain as a blocker for the phase that depends on it.

A planned exit after the migration

A foreign table that remains in place after cutover keeps an Oracle dependency alive in a system that was meant to leave Oracle. Set an exit date for each foreign table, the owner who removes it, and the test that proves the application no longer reads from Oracle. Record the exit plan in the migration runbook before the first foreign table is created, so the temporary link does not become permanent architecture.

What drives the effort and cost of an oracle_fdw setup

This table breaks down who is paid for each part of an oracle_fdw setup, which work is one-time and which recurs, and what pushes effort up. Use it to compare a quote against the work it should cover and to spot items that are missing.

Cost componentWho does the workOne-time or recurringWhat drives it up or down
Oracle client and extension build per PostgreSQL majorYour platform team or a partner builds and tests the Oracle client libraries and oracle_fdw against each PostgreSQL major in useRecurring at each PostgreSQL major upgrade, plus an initial buildNumber of PostgreSQL majors in service, Oracle client version support, and whether builds come from packages or source
Network and firewall changesYour network team opens the path from PostgreSQL hosts to the Oracle listener and reviews routingOne-time, with change requests for any later host or listener changeNumber of Oracle hosts and PostgreSQL servers involved, and whether traffic crosses zones or sites
Oracle account and privilege designYour Oracle DBA creates a read or write account scoped to named schemas and tablesOne-time setup, recurring when tables or owners changeNumber of schemas exposed, whether write access is needed, and how many foreign servers share credentials
PostgreSQL foreign server and user mapping setupYour PostgreSQL administrator defines foreign servers, user mappings and foreign table definitionsOne-time per migration phase, recurring when Oracle schemas changeNumber of foreign tables, column type mapping decisions and how credentials are stored
Reconciliation testingYour data team or a partner compares row counts, checksums and sample values between Oracle and PostgreSQLOne-time per migration phase, and again for each cutoverTable volume, number of transforms, and how much history must match exactly
Security reviewYour security team reviews the extension, the Oracle client, stored credentials and the connection pathOne-time, with re-review after upgrades or new exposed schemasSensitivity of the data, how credentials are protected, and how many people can query foreign tables
Operations and monitoringYour operations team tracks foreign query errors, latency and Oracle session useRecurring for as long as the foreign tables remain in useQuery volume against Oracle, the number of applications using foreign tables, and whether alerts exist

How long oracle_fdw takes to set up and what it needs from your team

Can our own team set up oracle_fdw without outside help?

Yes, a team with PostgreSQL administration skills and some Oracle knowledge can usually install it, but the work spans two database platforms and a network path between them. The PostgreSQL side needs a superuser to run CREATE EXTENSION oracle_fdw and define a foreign server whose dbserver option points at the Oracle database. Whether your team should do it alone depends on how many Oracle schemas, credentials and environments must be wired up, how well your staff know the Oracle client stack, and whether anyone has time to test failure cases before cutover. Ask a partner for a written scope if you want those tests covered. The project's own repository is the natural starting point: oracle_fdw repository.

What makes oracle_fdw setup take longer or shorter?

Duration depends mostly on the number of Oracle objects you expose, the number of foreign servers and user mappings, and how much of the path is already tested. The main drivers are:

  • Oracle client installation and version matching on each PostgreSQL server, which needs a change window if the hosts are shared
  • Credential design, since each user mapping should use a least-privilege Oracle account rather than a shared administrator login
  • Network routing and firewall approvals between PostgreSQL and Oracle listeners
  • Data type and character set checks for each table you read or write

A small read-only proof of concept against one schema usually moves faster than a multi-schema, bidirectional design. No duration is given here because none was supplied; ask any provider for a schedule tied to these drivers.

What do we need from our Oracle DBAs?

Oracle DBAs must create the accounts, grant the minimum privileges the foreign tables need, and confirm the listener and service name that PostgreSQL will connect to. They also review which tables, views and synonyms are exposed, because foreign tables read whatever the Oracle account can see. Ask them to document the grants and to advise on Oracle client compatibility, since the PostgreSQL host must run an Oracle client version their database accepts. If writes are planned, DBAs should review transaction behavior and lock impact on busy Oracle tables before any load runs. Confirm these responsibilities in writing with your Oracle team before scoping begins.

What do network teams need to approve?

Network teams must open a path from the PostgreSQL servers to the Oracle listener port, usually defined by your Oracle configuration, and confirm that traffic is encrypted or otherwise protected as your policy requires. Plan for name resolution, firewall rules in both directions where needed, and load balancers or DNS aliases if the Oracle service moves. Keep the approved path narrow, with one source group and one destination service, and record it in your change system. Test latency from the PostgreSQL host, because queries that cross a slow link can make joins against Oracle tables noticeably slower.

Can oracle_fdw run in production during a phased migration?

It can serve as a bridge during a phased migration, but whether it is suitable for production depends on your workload, query patterns and the failure behavior you accept. Reads through a foreign table depend on the Oracle database being available, so an Oracle outage or network fault appears as a PostgreSQL query failure. Load it with a defined owner, monitor the foreign server and the Oracle account, and set a retirement date for each dependency. Test the complete query path under realistic concurrency before depending on it. Treat it as a migration component with an exit plan, not a permanent integration, unless your own testing shows it meets your service expectations.

How does oracle_fdw affect PostgreSQL major upgrades?

The extension must be compiled or installed for each PostgreSQL major version you run, so an upgrade adds a step to your plan. Confirm that a build of oracle_fdw exists for the target major version and that it works with the Oracle client you have installed. Then test the foreign servers, user mappings and sample queries on a copy of the upgraded cluster before cutover. The PostgreSQL upgrade options, pg_upgrade and logical replication, both need this check, and the current supported major versions are listed in the PostgreSQL versioning policy. Ask your team to record the tested combination of PostgreSQL, extension and Oracle client versions.

When is a full migration tool a better path than oracle_fdw?

A full migration tool is usually the better path when you need to move the whole database rather than query it across systems, or when the application must stop depending on Oracle. oracle_fdw suits incremental reads, validation queries and staged data moves, while a migration project also needs schema conversion, data copy, cutover planning and reconciliation. If your end state removes Oracle entirely, plan the migration tooling early and use the foreign data wrapper only where it shortens a specific step. Ask any provider to explain which parts of the migration each approach covers before committing to one.

How PostgreSQL reaches Oracle through the foreign data wrapper

The request starts in an application that queries a foreign table in PostgreSQL. The foreign table hands the query to oracle_fdw, which loads the Oracle client library and opens a connection across the network boundary to the Oracle database. The credential mapping sits at the PostgreSQL side, so the Oracle account the wrapper uses is set by a user mapping rather than by the application. Check that the trust boundary matches your network rules and that the mapped Oracle account has only the privileges the migration needs.

Request path from a PostgreSQL session to an Oracle database, with the trust boundary and credential mapping marked.

How oracle_fdw connects to the rest of your PostgreSQL platform

oracle_fdw is not a standalone component. Its foreign servers, user mappings and Oracle credentials sit on top of the authentication, backup, monitoring and upgrade practices you already run for PostgreSQL. The cards below cover the touchpoints to plan for before the link carries production data.

Authentication and role design

Creating the extension and foreign servers requires superuser rights, so keep that step separate from day-to-day application roles. User mappings store Oracle credentials for each PostgreSQL role that reads through the link, so decide which roles may query which Oracle schemas. Check how the Oracle account is locked down on the Oracle side, since the PostgreSQL grants do not restrict what that account can read. Review pg_hba.conf and TLS settings for the connections that reach the link.

PostgreSQL authentication methods

Backup and restore of foreign definitions

Foreign servers, user mappings and foreign tables live in the PostgreSQL catalog, so a restore only brings them back if the backup captured them. Test a restore on a separate cluster and confirm the extension, server options and mappings reappear. Remember that the Oracle data itself is not in your PostgreSQL backup, so the recovery plan for migrated data and for the Oracle source must be documented separately. Passwords in user mappings need a plan for how they are re-entered or rotated after restore.

Monitoring the link

A failed Oracle connection usually shows up first as slow or failing queries in the application, not as a database alert. Track errors and slow statements that touch foreign tables, and watch the Oracle side for session counts and failed logins from the PostgreSQL host. Confirm the network path between the PostgreSQL servers and the Oracle listener is covered by your existing monitoring, and alert on changes to the Oracle client library version on those hosts.

Migration tooling around the link

oracle_fdw handles live reads and writes between the two databases, but it does not convert Oracle schemas, procedures or data types for you. For schema and code conversion, see the Ora2Pg guidance in the Oracle migration pages. For Oracle functions that the application calls, the orafce page explains which behaviors it emulates and where they still differ. Plan which tool owns each object type so that the link is not used as a substitute for a conversion decision.

Upgrade plan for PostgreSQL majors

Foreign data wrappers are compiled against PostgreSQL server headers, so a major upgrade needs a matching oracle_fdw build for the new version before cutover. Confirm the extension version supports your target major, and rehearse the upgrade on a copy that still has the foreign servers defined. Add the link checks to the post-upgrade test list, because a successful upgrade does not prove the Oracle connection works. PostgreSQL 14 reaches end of support on November 12, 2026, so plan that date into the upgrade schedule.

PostgreSQL versioning policy

How DeployOpen scopes and delivers an oracle_fdw implementation

DeployOpen starts every oracle_fdw engagement with a written scope that names the exact Oracle and PostgreSQL versions in use, the schemas and tables that will be exposed, the accounts that will connect, and the reconciliation tests that prove the data matches. Most engagements are fixed-scope, so the scope, deliverables and timeline are agreed in writing before any work begins, and the quote follows from that document. Before signing, confirm which Oracle client libraries your platform team can install on the PostgreSQL hosts, which Oracle database versions your DBAs will support, and who owns the Oracle accounts used for read or write access.

The build happens inside your infrastructure, in your cloud accounts, data centers or air-gapped network. DeployOpen installs the extension with CREATE EXTENSION oracle_fdw as a superuser, defines foreign servers whose dbserver option points at the Oracle database, and creates user mappings so that each PostgreSQL role uses only the Oracle credentials it is allowed to use. Foreign tables are then built over the agreed Oracle objects. The written scope should also list how credentials are stored, which PostgreSQL roles may create or alter foreign servers, and how changes to these objects are reviewed and logged, since those decisions shape your audit evidence later.

Handover includes the reconciliation results, configuration in version control, runbooks for rotating Oracle passwords and upgrading the extension alongside PostgreSQL, and the knowledge transfer your team needs to operate the setup. Ongoing support, upgrades and continuous testing are available as optional retainers, which suit teams that will keep oracle_fdw in place for a multi-phase migration or that must re-test after PostgreSQL or Oracle client changes. Ask for the retainer terms in the same written quote so that the one-time build and the recurring support are priced and scoped separately.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.