'Postgresql schema "public" does not exist

When I was working on postgresql database, I delete some users using command

=>set role "test-admin" ;
SET
=> drop owned by "test-admin" cascade;
DROP OWNED.   
=> drop user "test-temp";
DROP ROLE

but when I do

\dn
List of schemas
 Name | Owner
------+-------
(0 rows)

The public schema does not exist anymore. I can still see a bunch of users when run \du, I can also see names of database when do \l.

The error I saw is: "Error: could not find schema 'public' while looking for owner".

Looks like public schema was either dropped or not accessible. I did not drop schema explicitly.

My questions are:

  • why does public schema disappear?
  • will drop owner of schema public also drop public schema?
  • how can I bring it back?
  • Should I manually recreate it?
  • Since I can still see databases, how can I associate the database with public schema again?

I tried all the approaches I can think of (such as login as users with different privileges), the public schema is still no available.

Thanks for the help in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source