PostgreSQL HV024 FDW Invalid Attribute Value Fix
In this article
The PostgreSQL error HV024 with the message "invalid attribute value" from a foreign data wrapper (FDW) means the FDW rejected a value you supplied in an option or column mapping. The fix is to inspect the FDW options on the foreign server, user mapping, foreign table, and column definitions, then correct the value so it matches what the FDW expects. This guide walks through locating the bad value and correcting it.
What You'll Need
- Access to a PostgreSQL client (psql, pgAdmin, or another SQL client) with a role that can read FDW definitions.
- Superuser or owner privileges on the foreign server, user mapping, or foreign table you need to alter.
- The name of the FDW in use (for example, postgres_fdw, file_fdw, or a third-party wrapper).
- The exact error text, including the FDW name and any option name mentioned.
Step-by-Step
- Read the full error message. PostgreSQL usually includes the FDW name and the offending option. For example:
ERROR: HV024: invalid attribute value: "utf8" is not a valid encodingorinvalid value for option "fetch_size". The option name is your starting point. - Identify the FDW and its objects. Run
SELECT fdwname FROM pg_foreign_data_wrapper;to list installed wrappers. Then find the server:SELECT srvname, fdwname, srvoptions FROM pg_foreign_server;. Thesrvoptionscolumn shows server-level options that may contain the bad value. - Check user mappings. Run
SELECT umuser, srvname, umoptions FROM pg_user_mappings;. User mappings often hold credentials or connection parameters; an invalid value here can trigger HV024 when a query starts. - Inspect the foreign table and column options. Run
SELECT ftoptions FROM pg_foreign_table WHERE ftrelid = 'your_table'::regclass;andSELECT attname, attfdwoptions FROM pg_attribute WHERE attrelid = 'your_table'::regclass AND attfdwoptions IS NOT NULL;. Column-level options are a common source of invalid values, especially for file_fdw (for example, aforce_not_nullornullvalue that does not match the file format). - Compare each value against the FDW's documentation. For postgres_fdw, valid options include
host,port,dbname,user,password,fetch_size,use_remote_estimate, andupdatable. For file_fdw, options includefilename,format,delimiter,header,quote,escape,null, andencoding. A value likefetch_size = 'abc'orencoding = 'utf-99'will fail. - Correct the value with ALTER. For a server option:
ALTER SERVER my_server OPTIONS (SET fetch_size '1000');. For a user mapping:ALTER USER MAPPING FOR my_user SERVER my_server OPTIONS (SET password 'newpass');. For a foreign table:ALTER FOREIGN TABLE my_table OPTIONS (SET filename '/data/file.csv');. For a column:ALTER FOREIGN TABLE my_table ALTER COLUMN col OPTIONS (SET null 'NULL');. UseSETto replace an existing option,ADDfor a new one, andDROPto remove it. - Test with a simple query. Run
SELECT * FROM my_table LIMIT 1;. If the error persists, the bad value is on a different object (for example, a different column or the user mapping). Repeat steps 3–5 for each object. - Check for encoding and locale mismatches. If the FDW connects to another database, ensure the client encoding and server encoding are compatible. Run
SHOW client_encoding;and, on the remote side,SHOW server_encoding;. A value likeencoding 'LATIN1'on a UTF8 database can raise HV024. - Validate numeric and boolean options. Options such as
fetch_sizemust be integers, andupdatablemust betrueorfalse. Remove quotes where the FDW expects a bare boolean, and ensure numbers are not quoted as strings if the FDW rejects them. - Reload or reconnect if needed. Some FDWs cache connection state. Disconnect and reconnect your session, or restart the PostgreSQL service if the change affects a pooled connection. Do not restart a production server without confirming it is safe to do so.
Common Mistakes
- Editing the wrong object: the bad value may be on the user mapping rather than the foreign table.
- Using
ADDwhen the option already exists; useSETto replace it. - Quoting boolean values:
updatable 'true'may be rejected whereupdatable 'true'is expected as a string, or vice versa depending on the FDW. - Assuming the error comes from the remote server; HV024 is raised locally by the FDW validator.
- Forgetting that column-level options override table-level options, so a bad column value can hide a correct table setting.
Tips
- Use
\des+,\det+, and\deu+in psql to inspect foreign servers, tables, and user mappings quickly. - Keep a copy of the original options before altering them, so you can roll back.
- Test changes on a staging database first; FDW option changes take effect immediately for new queries.
- If you use a third-party FDW, check its version-specific documentation; option names and accepted values vary.
Troubleshooting
If the error persists after correcting the obvious option, check every object that references the FDW. Run SELECT srvname, srvoptions FROM pg_foreign_server;, SELECT * FROM pg_user_mappings;, and query pg_foreign_table and pg_attribute for all tables using that server. A single bad column option on any table can raise HV024 when that table is queried. If you cannot find the value, enable log_min_messages = debug1 temporarily and reproduce the query; the FDW validator often logs the exact option it rejected. If the FDW is postgres_fdw and the error mentions fetch_size, ensure the value is a positive integer. If it mentions use_remote_estimate, ensure it is a boolean. For file_fdw, verify that format is one of text, csv, or binary, and that encoding is a valid PostgreSQL encoding name. If you recently upgraded the FDW extension, run ALTER EXTENSION fdw_name UPDATE; and re-check options, because valid values can change between versions. If none of this resolves it, drop and recreate the foreign table with only the options you are certain about, then add options back one at a time until the error returns.
Frequently Asked Questions
What does SQLSTATE HV024 mean?
HV024 is the SQL standard code for "invalid attribute value". In PostgreSQL it is raised by an FDW's option validator when a supplied option value is not acceptable.
Does HV024 come from the remote server?
No. It is raised locally by the foreign data wrapper when it validates options, before or during query planning. The remote server may never see the query.
Can I see which option caused the error?
Often yes. The error text usually names the option or the value. If not, inspect all FDW options on the server, user mapping, foreign table, and columns, or enable debug logging to capture the validator's message.
Why did this start after an upgrade?
Newer FDW versions may validate options more strictly or rename accepted values. Check the extension's release notes and update any options that are no longer valid.
Is it safe to drop and recreate a foreign table?
Dropping a foreign table removes only the local definition, not the remote data, but it also removes grants and dependent objects. Back up the definition with \d+ first, and recreate grants afterward.