HV00N
PostgreSQLERRORNotableForeign Data Wrapper ErrorHIGH confidence

fdw_unable_to_establish_connection

Production Risk

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
trigger — this will error
SELECT * FROM my_foreign_table;

expected output

ERROR:  HV00N: fdw_unable_to_establish_connection

Fix 1

Verify remote server host and port

WHEN Connection refused or timed out

Verify remote server host and port
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

WHEN Network or firewall issue suspected

Test connectivity from the PostgreSQL host
-- 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

User mapping passwords are visible to superusers via pg_user_mappings

Sources
Official documentation ↗

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

https://www.postgresql.org/docs/current/sql-createserver.html

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors