PostgreSQL Error HV091: FDW Invalid Field Identifier Fix
In this article
HV091 means PostgreSQL rejected a column name you passed to a foreign table operation because it does not exist in the foreign object's descriptor. In practice it almost always comes from a mismatch between your local foreign table definition and the actual structure of the remote table (or of the foreign data source itself), and the fix is to resynchronise the two: recreate or re-import the foreign table so its column list matches the remote schema exactly, then retry the query. If you are writing to the foreign table, also confirm the column names, case, and quoting line up with what the FDW wrapper reports.
This error is raised by the foreign data wrapper layer rather than by the core executor, so the exact message you see depends on the wrapper. Wrappers such as postgres_fdw, mysql_fdw, oracle_fdw, sqlite_fdw and file_fdw all raise HV091 when they are asked to read or write a field whose identifier is not part of the descriptor they built for the remote relation. That descriptor is built at connection time (or at planning time), so a stale descriptor is a very common cause: the remote table gained a column, dropped one, or was renamed after the foreign table was created. Labels and paths can differ slightly depending on the PostgreSQL version and the wrapper version, so treat the exact wording below as a guide rather than a guarantee.
What You'll Need
- Access to the PostgreSQL database that raises the error, with permission to inspect foreign servers, user mappings and foreign tables (a superuser is usually required to alter these).
- psql or another SQL client, since the correction is done in SQL, not through a graphical menu.
- The credentials, host and database name for the remote data source if you need to query its schema directly.
- The exact errdetail and errhint text from the error, which names the offending identifier, visible in psql, in the client's error pane, or in the server log if
log_error_verbosityis verbose.
Step-by-Step
Capture the full error first. Run the failing statement in psql and read the message, the DETAIL line and any HINT. A typical DETAIL names the field, for example that the descriptor for a given relation does not contain a field with the name you referenced. Write down that identifier, the remote relation name and the FDW in use, because the next steps depend on which of the three is wrong. If you only see the code in an application log, set
client_min_messagesandlog_min_messageshigh enough to expose the detail, or check the server log.Inspect the local foreign table definition. Query the catalogue with
SELECT attname, atttypid::regtype, attnum FROM pg_attribute WHERE attrelid = 'public.your_foreign_table'::regclass AND attnum > 0 ORDER BY attnum;and also check the options on the table and its columns withSELECT * FROM pg_foreign_table WHERE ftrelid = 'public.your_foreign_table'::regclass;. Some wrappers such as file_fdw and oracle_fdw need column-level options (for example a remote column name that differs from the local one); a missing or misspelled column option produces HV091 just as reliably as a missing column.Compare that list with the remote object. Connect directly to the remote database and describe the table, or use the wrapper's own import function, which is the authoritative source of truth for what the descriptor will contain. For postgres_fdw that is
IMPORT FOREIGN SCHEMA. If the remote table has a column your foreign table lacks, or your foreign table lists a column the remote table no longer has, you have found the mismatch.Check case and quoting. PostgreSQL folds unquoted identifiers to lower case, while remote systems differ: Oracle and SQL Server typically store upper case unless quoted, MySQL's case sensitivity depends on the setting of
lower_case_table_namesand the platform. If the remote column isCustomerIDand you definedcustomerid, a case-sensitive wrapper will fail to find it. Define the column with the remote spelling and quotes, for example"CustomerID" integer OPTIONS (column_name 'CustomerID')where the wrapper supportscolumn_name.Refresh the descriptor. The simplest reliable repair is to drop and recreate the foreign table. Save its definition first with
\d+ foreign_table, thenDROP FOREIGN TABLE public.your_foreign_table;and recreate it. Dropping a foreign table removes only the local definition, not the remote data, but it also drops dependent local objects such as views and grants on that table, so check with\ddependents or thepg_dependview before you drop. For schemas with many tables,IMPORT FOREIGN SCHEMA remote_schema LIMIT TO (table_a, table_b) FROM SERVER my_server INTO public;withOPTIONS (import_default 'true')regenerates definitions that match the remote exactly, which is usually faster and safer than hand-editing.Alternatively, add or remove only the differing columns. If the schema is stable and you do not want to rebuild, use
ALTER FOREIGN TABLE ... ADD COLUMNto add the missing ones, orALTER FOREIGN TABLE ... DROP COLUMNto remove stale ones.ALTER FOREIGN TABLE ... ALTER COLUMN ... OPTIONS (SET column_name '...')corrects a wrong remote name. Test each change against the failing query before moving on.Re-check the user mapping and server options if nothing in the column list looks wrong. Some wrappers let you map a remote schema or owner explicitly, and a wrong mapping can make the wrapper look in a different namespace where a same-named table has a different shape. Verify with
SELECT * FROM pg_user_mapping;andSELECT srvname, srvoptions FROM pg_foreign_server;, and correct withALTER SERVERorALTER USER MAPPING.Invalidate any cached state and retry. Foreign table descriptors are rebuilt on the next use in a new session, so after changing the definition reconnect and rerun the query in psql rather than in a long-lived pooled session. Run
ANALYZEon the foreign table if your wrapper supports it; a stale statistics snapshot can keep the planner using a cached remote query. Confirm the fix by running both aSELECT *and a targetedSELECTof the previously failing column, and if it is a writable wrapper, a smallUPDATEorINSERTon that column.
Common Mistakes
- Editing the remote table to match the local definition instead of the other way around. That breaks the application that owns the remote schema.
- Forgetting column options. On wrappers where the local column name may differ from the remote one, the option is mandatory; a missing
column_nameoption silently falls back to the local name. - Assuming quoted and unquoted names are the same. They are not, in either direction.
- Dropping the foreign table without checking dependents, then discovering local views and reports are broken.
- Testing from a pooled connection after recreating the table. The new session must be the one to prove the fix.
- Fixing the type instead of the name. HV091 is about identifiers; a type or format mismatch produces a different error.
Tips
- Keep foreign table definitions generated from
IMPORT FOREIGN SCHEMAwhere possible, so they stay in step with the remote by construction. - Add a comment on each foreign table naming the remote schema and table, so the next person knows where to look.
- When the remote schema changes often, capture the import as a script and rerun it after each change instead of patching columns by hand.
- Test the failing query inside a transaction with the definition change where it helps isolate the cause:
BEGIN; ... ROLLBACK;lets you try add-column variants without keeping them.
Troubleshooting
If the error persists after rebuilding the foreign table, the descriptor that is wrong may be the remote one. Connect to the remote database as the user named in the mapping and repeat the failing query there; if the remote user cannot see the column, its privileges are the problem, and HV091 is the wrapper's way of reporting an object it cannot describe. Grant the missing privilege on the remote, or correct the user mapping to point at the right role.
If the error only appears for some queries, suspect a query-rewriting feature: a view that references a renamed column, or a client library that builds field lists from stale metadata. Compare the exact SQL sent by the application with the SQL you typed in psql.
If the whole foreign table fails to be described at plan time, check that the remote server and user mapping resolve in the current search path and that the wrapper library is installed, then update the wrapper extension in place with ALTER EXTENSION.
If nothing resolves, disable the connection cache on the server and restart the affected backend, then reproduce. If the error remains reproducible in a fresh session after a verified-identical definition, escalate the extra log detail with the wrapper's own debug option rather than changing unrelated settings.
Frequently Asked Questions
Does HV091 mean my data is corrupted?
No. It is a definition mismatch, not corruption, and the remote data is untouched.
Can I ignore the code and just retry?
No. The statement will fail the same way until the identifier matches the descriptor.
Will recreating the foreign table delete remote rows?
No. Dropping a foreign table removes only the local definition; the data stays on the remote server.
Why does the error appear only after a remote schema change?
The local definition still lists the old columns, so the descriptor no longer matches the remote relation.
Does every foreign data wrapper raise HV091 the same way?
No. The SQLSTATE is standard, but the message and whether the culprit is a column, option or mapping depend on the wrapper and its version.