PostgreSQL Error HV00P FDW No Schemas Fix
In this article
The PostgreSQL error HV00P occurs when a Foreign Data Wrapper (FDW) cannot find any schemas that the remote user has permission to access. To fix this, you must ensure that the user defined in your USER MAPPING on the local server has the USAGE privilege on the target schema on the remote server. Without this permission, the remote server returns an empty list of schemas, triggering the HV00P error during the IMPORT FOREIGN SCHEMA process or when querying foreign tables.
What You'll Need
- Administrative access (superuser or owner) to the local PostgreSQL instance where the FDW is configured.
- Administrative access or a privileged account on the remote PostgreSQL instance where the actual data resides.
- The name of the remote user specified in the local
USER MAPPING. - The name of the schema you are attempting to import or access.
Step-by-Step
- Identify the Remote User: On your local server, check which remote user is being used for the connection. Run the following query to see your existing user mappings:
SELECT * FROM pg_user_mappings;. Note theumuser(local user) and theumoptions(which contains the remote user name). - Connect to the Remote Server: Open a psql terminal or a database management tool and connect directly to the remote database instance. You must be logged in as a superuser or the owner of the schema to grant permissions.
- Verify Schema Existence: Ensure the schema you are trying to access actually exists on the remote server. Run
\dnin psql or querySELECT schema_name FROM information_schema.schemata;. If the schema is missing, you must create it before proceeding. - Grant Usage Permission: This is the most critical step to resolve HV00P. The remote user must have
USAGErights on the schema. Run the following command on the remote server:GRANT USAGE ON SCHEMA your_schema_name TO remote_user_name;. Replaceyour_schema_nameandremote_user_namewith your actual values. - Grant Table Permissions: Even if the schema is visible, the user needs permission to read the tables within it. Run:
GRANT SELECT ON ALL TABLES IN SCHEMA your_schema_name TO remote_user_name;. If you plan to add more tables in the future, you should also run:ALTER DEFAULT PRIVILEGES IN SCHEMA your_schema_name GRANT SELECT ON TABLES TO remote_user_name;. - Verify Connection on Local Server: Return to your local PostgreSQL instance. Attempt to import the schema again using the
IMPORT FOREIGN SCHEMAcommand:IMPORT FOREIGN SCHEMA your_schema_name FROM SERVER your_foreign_server INTO your_local_schema;. - Test Data Retrieval: Run a simple
SELECT * FROM your_foreign_table LIMIT 10;to confirm that the mapping is working and the HV00P error is resolved.
Common Mistakes
One of the most frequent mistakes is granting permissions to the local user instead of the remote user. Remember that the USER MAPPING acts as a bridge; the remote server only cares about the credentials provided in that mapping. If you grant USAGE to the local admin but the mapping uses a restricted user called fdw_user, the remote server will still deny access and throw the HV00P error.
Another common error is forgetting the USAGE privilege entirely and only granting SELECT on tables. In PostgreSQL, the USAGE privilege on a schema is a prerequisite for accessing any object within that schema. You cannot select from a table if you cannot "use" the schema that contains it.
Users also frequently mistake the database name for the schema name. In PostgreSQL, a database contains multiple schemas (the default being public). If your IMPORT FOREIGN SCHEMA command specifies a database name instead of a schema name, the FDW will fail to locate the objects, potentially resulting in a "no schemas" error because it is looking for a schema that doesn't exist.
Tips
To avoid permission issues in the future, create a dedicated "read-only" role on your remote server specifically for FDW connections. Instead of granting permissions to individual users, grant them to this role and then assign the remote FDW user to that role using GRANT fdw_read_role TO remote_user_name;. This makes managing multiple foreign data wrappers much simpler.
When using IMPORT FOREIGN SCHEMA, consider using the LIMIT TO or EXCEPT clauses. If your remote schema contains hundreds of tables, importing all of them can clutter your local database and slow down metadata queries. For example, IMPORT FOREIGN SCHEMA remote_schema LIMIT TO (table1, table2) FROM SERVER remote_server INTO local_schema; allows you to be precise about what data is exposed locally.
Always use a secure connection for FDWs. If your remote server is on a different physical machine, ensure your CREATE SERVER command includes options (sslmode 'require') to prevent credentials and data from being transmitted in plain text over the network.
Troubleshooting
If you have granted USAGE and SELECT permissions but still see the HV00P error, check the pg_hba.conf file on the remote server. Ensure that the remote server is configured to allow connections from the IP address of the local server for the specific user defined in the mapping. If the connection is rejected at the network or authentication level, the FDW may report a generic failure or a schema error depending on the version.
Check for search path issues. While IMPORT FOREIGN SCHEMA usually bypasses the search path by explicitly naming the schema, general queries against foreign tables rely on the search_path setting. If you can import the schema but cannot query the tables, try setting the search path: SET search_path TO local_schema, public;.
Verify the case sensitivity of your schema and user names. PostgreSQL folds unquoted identifiers to lowercase. If your remote schema was created as "MySchema" (with double quotes), you must refer to it exactly as "MySchema" in your IMPORT command. If you refer to it as myschema, PostgreSQL will not find it, and the FDW will report that no such schema exists or is accessible.
If the error persists, try recreating the user mapping. Sometimes a typo in the password or username in the CREATE USER MAPPING command leads to authentication failures that manifest as access errors. Use ALTER USER MAPPING FOR local_user SERVER remote_server OPTIONS (user 'remote_user', password 'correct_password'); to update the credentials.
Frequently Asked Questions
Why does this happen if I am a superuser on the local server?
Superuser status on the local server does not grant permissions on the remote server. The remote server treats the FDW connection as a standard client connection and enforces its own internal Role-Based Access Control (RBAC) based on the user provided in the mapping.
Can I fix HV00P without accessing the remote server?
No. Because the error is caused by a lack of permissions on the remote side, you must have the ability to execute GRANT commands on the remote PostgreSQL instance to resolve the issue.
Does the public schema cause this error?
Usually, the public schema has USAGE granted to PUBLIC (all users) by default. However, in PostgreSQL 15 and later, default permissions for the public schema have been tightened. You may now need to explicitly grant USAGE on the public schema to your remote user.
Is this error related to the postgres-fdw extension?
Yes, this is a specific behavior of the postgres_fdw extension. It occurs during the handshake where the local server asks the remote server for a list of available schemas to map. If the remote server returns an empty list due to permissions, HV00P is triggered.
Will granting the remote user superuser status fix it?
Yes, making the remote user a superuser will resolve the error because superusers bypass all permission checks. However, this is strongly discouraged for security reasons. It is much safer to grant only the specific USAGE and SELECT permissions required.