Oracle connection timeout limits how long PostgreSQL waits when oracle_fdw tries to open a session with an Oracle database.
Long connection attempts block queries, tie up connection pool slots, and create user frustration. Setting a timeout lets PostgreSQL abort the attempt quickly and return an error you can handle in code or retry logic.
oracle_fdw is the de-facto extension for querying Oracle from PostgreSQL. It exposes a connect_timeout
server option that limits connection attempts in seconds.
connect_timeout
when creating a server?Add the option directly in the CREATE SERVER
statement so every session inherits it. You can also amend an existing server with ALTER SERVER
.
CREATE SERVER oracle_sales
FOREIGN DATA WRAPPER oracle_fdw
OPTIONS (
dbserver '//ora-host:1521/ORCLPDB',
connect_timeout '10' -- seconds
);
ALTER SERVER oracle_sales
OPTIONS (ADD connect_timeout '10');
Yes. Supply the parameter in the connection string of IMPORT FOREIGN SCHEMA
or SET
the oracle_fdw.connect_timeout
GUC for the current backend.
oracle_fdw raises error SQLSTATE 08001
(connection exception). Wrap the foreign query in application-side retry logic or fallback to cached data.
Keep timeout under expected network latency (5–15s). Monitor failed connections in pg_stat_activity
and Oracle alert logs. Combine with statement_timeout
to protect long-running calls after the connection is established.
IMPORT FOREIGN SCHEMA orders_schema
FROM SERVER oracle_sales INTO public;
SELECT id, customer_id, total_amount
FROM orders
WHERE order_date > CURRENT_DATE - INTERVAL '30 days';
If Oracle is unreachable for more than 10 seconds, the query aborts immediately.
Run SELECT srvoptions FROM pg_foreign_server WHERE srvname = 'oracle_sales';
and ensure connect_timeout=10
appears in the result.
No. It only applies while establishing a new Oracle session. Use Oracle-side profiles to limit idle sessions.
Per attempt. Each new connection launched by PostgreSQL gets the full timeout window.
Yes. Omit the option or set it to '0'
. PostgreSQL then waits indefinitely for Oracle to respond—usually discouraged in production.