Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

PostgreSQL HV00N: FDW Connection Error Fix

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The PostgreSQL error HV00N (fdw_unable_to_establish_connection) means the foreign data wrapper could not open a network connection to the remote server. The fix is almost always one of four things: the remote host is down or unreachable, the port is wrong or blocked, the connection string (host, port, dbname, user) is wrong, or the remote server is not accepting connections from your PostgreSQL host. Work through the checks below in order.

What You'll Need

  • Access to the PostgreSQL server that throws the error, with a superuser or the owner of the foreign server object.
  • The foreign server definition: run \des+ in psql or query pg_foreign_server to see the host, port, and options.
  • Network access from the PostgreSQL host to the remote host and port (SSH or a terminal on the database server).
  • The remote database's connection details and credentials.
  • Permission to edit pg_hba.conf on the remote server if authentication is the blocker.

Step-by-Step

  1. Read the full error message. HV00N is a class-level code; the detail line usually names the host and port that failed. In psql, the message appears after the failing query. In application logs, search for HV00N or fdw_unable_to_establish_connection and note the remote address.
  2. Confirm which foreign server is involved. Run SELECT srvname, srvoptions FROM pg_foreign_server; and match the name used in your query. If the query uses a foreign table, find its server with SELECT ftoptions, srvname FROM pg_foreign_table JOIN pg_foreign_server USING (srvname);.
  3. Test basic reachability from the PostgreSQL host. On the database server, run ping <remote-host> and then nc -vz <remote-host> <port> (or telnet <remote-host> <port>). If the port is closed or times out, the problem is network or firewall, not PostgreSQL. Fix routing, security groups, or firewall rules before continuing.
  4. Check the remote server is listening. On the remote host, confirm PostgreSQL is running and listening on the expected interface. ss -ltnp | grep 5432 shows the listening socket; if it only listens on 127.0.0.1, remote connections will fail. Adjust listen_addresses in postgresql.conf and restart the remote server.
  5. Verify the connection options in the foreign server. Compare host, port, and dbname in srvoptions with the remote server's actual values. A typo in the port (5432 vs 5433) or a hostname that resolves to the wrong address produces HV00N. Correct with ALTER SERVER <name> OPTIONS (SET host 'correct-host', SET port '5432');.
  6. Check remote authentication. On the remote server, inspect pg_hba.conf. The entry for the connecting user and the PostgreSQL host's IP must use a method the FDW supports (for example scram-sha-256 or md5). If the remote server rejects the connection at the auth stage, the FDW reports HV00N. Reload the remote configuration after edits.
  7. Confirm the user mapping exists and is correct. Run SELECT * FROM pg_user_mappings WHERE srvname = '<name>';. The local role running the query needs a user mapping with the remote username and password. Create or fix it with CREATE USER MAPPING FOR <local_role> SERVER <name> OPTIONS (user 'remote_user', password 'secret');.
  8. Test with a minimal query. Run SELECT 1 FROM foreign_table LIMIT 1; or use postgres_fdw's postgres_fdw_get_connections() if available to see active connections. A successful minimal query confirms the fix; if it still fails, return to step 3 with the exact host and port from the error detail.

Common Mistakes

  • Fixing the local server only. HV00N is about the outbound connection; the remote server's firewall, listen address, and pg_hba.conf matter as much as the local definition.
  • Assuming the hostname resolves the same everywhere. The PostgreSQL host may resolve a hostname to a private IP while your workstation resolves it to a public one. Test from the database server, not your laptop.
  • Editing the foreign server but not the user mapping. Wrong credentials in the user mapping produce the same class of error. Check both objects.
  • Forgetting to reload the remote configuration. Changes to pg_hba.conf need a reload (SELECT pg_reload_conf(); on the remote server) before they take effect.
  • Using a connection string in the wrong option. Some FDWs expect separate host, port, and dbname options rather than a single URI. Check the extension's documentation for the exact option names.

Tips

  • Keep the remote host and port in a single place (the foreign server options) and avoid duplicating them in user mappings.
  • Use \des+ in psql for a quick view of all foreign servers and their options.
  • When testing connectivity, use the same user the PostgreSQL service runs as; a shell user with different network access can give misleading results.
  • Log the full error detail in your application so the remote host and port are visible without reproducing the query.
  • If the remote server is behind a load balancer or proxy, confirm the proxy forwards the PostgreSQL port and does not terminate the connection prematurely.

Troubleshooting

If nc succeeds but the FDW still fails, the problem is above the network layer. Check the remote server's logs for connection attempts and authentication failures; they usually name the reason (no pg_hba entry, password authentication failed, database does not exist). If the remote server logs nothing, the connection is being dropped before it arrives, so revisit firewalls, security groups, and NAT rules. If the error appears only for some queries, check whether those queries use a different foreign server or user mapping. If the remote server is reachable but slow to respond, the FDW may time out; check the extension's connection timeout option and the remote server's load. Finally, confirm the FDW extension is installed and the foreign server was created with the correct extension; a mismatch between the extension and the server definition can cause connection failures that look like network errors.

Frequently Asked Questions

What does HV00N mean exactly?

It is the SQLSTATE for fdw_unable_to_establish_connection: the foreign data wrapper could not open a connection to the remote server. The detail line usually names the host and port.

Is HV00N a PostgreSQL bug?

No. It is a reported condition, not a defect. The cause is almost always configuration, network, or authentication on either the local or remote side.

Can HV00N happen with postgres_fdw only?

No. Any FDW that opens a network connection can raise it. The checks are the same: reachability, port, credentials, and remote server configuration.

Why does it work from my laptop but not from the database server?

Because the database server's network path, DNS resolution, or firewall rules differ from your laptop's. Test with nc or telnet from the database server itself.

Does fixing pg_hba.conf require a restart?

No, a reload is enough. Run SELECT pg_reload_conf(); on the remote server after editing the file.

What should I check first if the error is intermittent?

Check the remote server's connection limits and logs for dropped connections, and confirm no firewall or proxy is timing out idle connections. Intermittent HV00N often points to a network device between the two servers.