PG
PRO
HV00NERRORTier 2 — Caution✅ HIGH confidence

fdw_unable_to_establish_connection

Category: Foreign Data Wrapper ErrorVersions: PostgreSQL 9.1+

🔴 Production Risk Error

High — foreign tables that cannot connect will block any query touching them, potentially causing application-wide failures

What this means

A foreign data wrapper could not establish a connection to the remote server. The remote server may be down, unreachable, or refusing connections.

Why it happens

  1. 1Remote server is not running or is unreachable at the configured host/port
  2. 2Firewall rules block the connection from the PostgreSQL server
  3. 3Wrong host, port, or database name in CREATE SERVER options
  4. 4Remote server max_connections limit reached
  5. 5SSL certificate validation failure when ssl=require is set
  6. 6User mapping credentials rejected by remote server

How to reproduce

First access to a foreign table backed by an unreachable remote server

trigger — this will ERROR
SELECT * FROM my_foreign_table;
ERROR: HV00N: fdw_unable_to_establish_connection

Fix 1: Verify remote server host and port

Connection refused or timed out

fix
SELECT srvoptions FROM pg_foreign_server WHERE srvname = 'myserver';

Why this works

Corrects misconfigured connection parameters in the foreign server definition

Fix 2: Test connectivity from the PostgreSQL host

Network or firewall issue suspected

fix
-- From OS: pg_isready -h remotehost -p 5432

Why this works

Confirms whether the remote PostgreSQL port is accessible from the local server

What not to do

Do not store production credentials in user mappings without encryption

Why it's wrong: User mapping passwords are visible to superusers via pg_user_mappings

Sources

📚 Official docs: https://www.postgresql.org/docs/current/postgres-fdw.html

🔧 Source ref: https://www.postgresql.org/docs/current/errcodes-appendix.html

📖 Further reading:

Confidence assessment

✅ HIGH confidence

Standard FDW error code from official PostgreSQL appendix; connection failure is the most common FDW error in production.

See also

📄 Reference pages

postgres_fdw documentationCREATE SERVER
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →