no schema has been selected to create in ... error

no schema has been selected to create in

You get this error when your search_path setting has no valid first entry (typically empty). Postgres does not know in which schema to create the table.

Fix your search_path setting, or schema-qualify object names (like: public.users). But fix your search_path in any case.
Details:

  • How does the search_path influence identifier resolution and the "current schema"

I found the file created by pg_dump (under postgres 10.7) had

SELECT pg_catalog.set_config('search_path', '', false);

near the top of it. So when importing the file, it manipulated the search path, which persisted throughout the current session.

Commenting that line out (and starting a new session) fixed the problem.


This issue was answered already: https://dba.stackexchange.com/a/275116/114247

The fix is:

grant usage on schema public to public;
grant create on schema public to public;