PostgreSQL Error HV00Q FDW Schema Not Found: Fix Guide
In this article
The PostgreSQL error HV00Q: FDW schema not found occurs when a foreign data wrapper (FDW) tries to access a schema that doesn’t exist or isn’t visible to the current user. This typically happens during foreign table creation or queries against external data sources like other PostgreSQL databases, MySQL, or CSV files via extensions like postgresql_fdw or mysql_fdw. The fix requires verifying schema existence, user permissions, and FDW configuration—no external tools are needed beyond standard PostgreSQL commands.
What You'll Need
- Access to the PostgreSQL server with superuser or sufficient privileges (CREATE, USAGE on foreign data wrapper and schema)
- The name of the foreign data wrapper extension installed (e.g., postgresql_fdw)
- The name of the foreign server and foreign table involved
- Access to the target database or external system the FDW connects to (if applicable)
Step-by-Step
- Connect to the PostgreSQL database where the error occurs using psql or a GUI tool like pgAdmin:
psql -U username -d database_name. Replaceusernameanddatabase_namewith your actual credentials and database. - Check if the foreign data wrapper extension is installed and active in the current database by running:
SELECT extname FROM pg_extension WHERE extname = 'postgresql_fdw';. If no rows return, install it withCREATE EXTENSION IF NOT EXISTS postgresql_fdw;. Repeat this step for any other FDW extensions you’re using (e.g., mysql_fdw, file_fdw). - List all schemas in the current database with:
SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_' AND nspname != 'information_schema';. This excludes system schemas. Identify the schema name referenced in your foreign table definition—this is often the schema listed in the CREATE FOREIGN TABLE statement or in the error message. - Verify that the schema exists in the target database if the FDW connects externally. For example, if your FDW points to a remote PostgreSQL database, connect to that remote database and run the same schema query. The schema must exist there too. If it doesn’t, create it using
CREATE SCHEMA schema_name;on the remote side. - Check the user permissions for the schema. Run:
SELECT pg_has_role('current_user', 'schema_name', 'usage');. Replace 'current_user' with the actual role name used in the FDW connection (often defined in the FOREIGN SERVER definition). If this returns false, grant usage:GRANT USAGE ON SCHEMA schema_name TO username;. - Examine the foreign server definition:
SELECT * FROM pg_foreign_server WHERE srvname = 'your_server_name';. Confirm the server is configured to connect to the correct database and host. If the server points to a different database than expected, update it withALTER SERVER your_server_name OPTIONS (SET dbname 'correct_db_name');. - Review the foreign table definition:
\d+ schema_name.table_name(in psql) or querySELECT ft.ftoptions FROM pg_foreign_table ft JOIN pg_class c ON ft.ftrelid = c.oid WHERE c.relname = 'table_name' AND c.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'schema_name');. Ensure the schema name in the foreign table matches exactly (case-sensitive) one of the schemas listed in step 3. - If the schema name is correct but still not found, ensure the user running the query has the correct search_path. Run
SHOW search_path;. If it doesn’t include the target schema, set it:SET search_path TO schema_name, public;. To make it permanent for the user, runALTER USER username SET search_path TO schema_name, public;. - If you’re using a foreign server that maps to another PostgreSQL instance, confirm the remote server allows the connection. Test connectivity from the PostgreSQL host using
psql -h remote_host -p 5432 -U remote_user -d remote_db. If this fails, check firewall rules, pg_hba.conf on the remote server, and that the remote database is accepting TCP connections. - After correcting any issues, restart the PostgreSQL service only if you modified pg_hba.conf or postgresql.conf. Otherwise, simply reconnect to the database and re-run your query. The error should disappear.
Common Mistakes
- Assuming the schema exists on the local database when it’s actually on the remote server—FDWs reference schemas on the foreign server, not the local one.
- Typo in schema name: PostgreSQL is case-sensitive. Schema "MySchema" ≠ "myschema". Always copy the exact name from
pg_namespace. - Granting permissions to the wrong user: The user in the FOREIGN SERVER definition must have USAGE on the remote schema, not just the local user.
- Forgetting to install the FDW extension in the target database—extensions are database-specific, not instance-wide.
- Using a schema name that’s reserved or system-generated (e.g., "pg_catalog"), which cannot be used as a foreign schema.
Tips
- Use descriptive names for foreign servers and schemas to avoid confusion—e.g., "remote_sales_db" instead of "server1".
- Always test the remote connection manually before creating the FDW. If psql can’t connect, the FDW won’t work.
- Keep a log of all foreign tables and their mappings. Use a comment:
COMMENT ON FOREIGN TABLE schema.table IS 'Mapped from remote_db.public.sales';. - When migrating databases, recreate FDWs in the new environment—they don’t transfer with backups unless explicitly scripted.
- Use
SHOW client_min_messages;and set it to NOTICE to see more detailed warnings about FDW connections during execution.
Troubleshooting
If the error persists after following all steps:
- Check the PostgreSQL logs on the server (typically in /var/lib/postgresql/data/log/ or /var/log/postgresql/). Look for lines containing "FDW" or the schema name—often they reveal connection failures or permission denials not shown in client output.
- Verify the remote database’s pg_hba.conf includes an entry allowing the local server’s IP address with the correct authentication method (e.g., md5 or scram-sha-256). Restart the remote PostgreSQL service after changes.
- If using SSL, ensure the remote server has a valid certificate and the local server trusts it. Add
sslmode=requireto the foreign server’s OPTIONS if needed. - Test with a minimal setup: create a new schema on the remote side, create a simple table, then build a new FDW pointing to just that table and schema. If this works, the problem lies in your original schema or table structure.
- If you’ve dropped and recreated a schema, any foreign tables referencing it are now invalid. Drop and recreate them:
DROP FOREIGN TABLE schema.table_name;, then re-run the CREATE FOREIGN TABLE command. - As a last resort, re-install the FDW extension entirely:
DROP EXTENSION postgresql_fdw;followed byCREATE EXTENSION postgresql_fdw;. This clears any internal corruption in the extension catalog.
Frequently Asked Questions
Why does PostgreSQL say the schema isn’t found even though I can see it in pgAdmin?
pgAdmin may show schemas from multiple databases or roles. The FDW query runs under a specific user context and only sees schemas that user has USAGE rights to. Check permissions and the active search_path.
Can I use a schema from a different PostgreSQL instance without creating a foreign server?
No. Foreign Data Wrappers require a foreign server definition to establish the connection. You cannot access remote schemas without defining the server, user credentials, and options.
Does the schema name need to match between local and remote databases?
No. The local foreign table can map to any schema on the remote server. The local schema is just a namespace for your table—remote schema is defined in the foreign server’s connection options.
Why does the error appear only for some users and not others?
Each user has separate permissions and search_path settings. The user encountering the error likely lacks USAGE on the remote schema or has a restricted search_path. Grant permissions and adjust search_path per user.
Can I fix this without restarting PostgreSQL?
Yes, in 99% of cases. Restarting is only needed if you changed postgresql.conf or pg_hba.conf. Most fixes involve database-level commands that take effect immediately.
Is this error related to network issues?
Only indirectly. The schema not found error is a logical or permission error. But if the foreign server can’t connect due to network failure, you’ll get a different error first (e.g., connection refused). Fix connectivity before checking schema existence.