Resolve the “Oracle access denied” connection error when PostgreSQL queries Oracle through oracle_fdw.
PostgreSQL raises this error when Oracle rejects the login defined in your USER MAPPING. The usual causes are wrong credentials, expired passwords, locked Oracle accounts, or insufficient Oracle privileges.
The extension authenticates with the username and password stored in the CREATE USER MAPPING statement—not the PostgreSQL role that runs the query.The mapping must stay in sync with the Oracle account.
Confirm the Oracle username, reset the password, unlock the account, and GRANT the required SELECT privileges on the target schemas.Then refresh the USER MAPPING in PostgreSQL.
• Test credentials with sqlplus
• ALTER USER account UNLOCK;
• ALTER USER account IDENTIFIED BY new_pw;
• GRANT CREATE SESSION, SELECT ANY TABLE TO account;
Use CREATE SERVER to point at the Oracle instance, then CREATE USER MAPPING with valid credentials, and optionally IMPORT FOREIGN SCHEMA.
Yes—run SELECT oracle_diag(); to confirm that oracle_fdw can log in.If the function returns session details, the mapping works.
Limit the IMPORT FOREIGN SCHEMA to the exact tables (CUSTOMERS, ORDERS, PRODUCTS, ORDERITEMS).This prevents unnecessary objects and permissions.
• Store credentials in a dedicated PostgreSQL role with limited privileges.
• Rotate Oracle passwords with an automated script.
• Monitor pg_stat_activity for FATAL connection failures.
Create a scheduled job that updates the USER MAPPING right after the Oracle password rotation.This keeps PostgreSQL in sync and avoids downtime.
Wrap foreign-table queries in SECURITY DEFINER views or functions when end-users should not see Oracle credentials. The wrapper executes as the owner role that already holds the mapping.
.
No. oracle_fdw requires explicit user/password pairs. Use a restricted PostgreSQL role and OS-level file permissions to secure the mapping.
Yes, if the Oracle server enforces TLS. Configure the Oracle client (sqlnet.ora) on the PostgreSQL host; oracle_fdw will use those settings automatically.
Run IMPORT FOREIGN SCHEMA with the same LIMIT TO list and the option "REPLACE TRUE" (available from oracle_fdw 2.5) to update column definitions in place.