Cannot create a new table after “DROP SCHEMA public”

后端 未结 2 965
遥遥无期
遥遥无期 2020-12-24 11:56

Since I wanted to drop some tables and somebody suggested the below and I did it:

postgres=# drop schema public cascade;
DROP SCHEMA
postgres=# create schema         


        
2条回答
  •  误落风尘
    2020-12-24 12:08

    The error message pops up when none of the schemas in your search_path can be found.
    Either it is misconfigured. What do you get for this?

    SHOW search_path;
    

    Or you deleted the public schema from your standard system database template1. You may have been connected to the wrong database when you ran drop schema public cascade;

    As the name suggests, this is the template for creating new databases. Therefore, every new database starts out without the (default) schema public now - while your default search_path probably has 'public' in it.

    Just run (as superuser public or see mgojohn's answer):

    CREATE SCHEMA public;
    

    in the database template1 (or any other database where you need it).

    The advice with DROP SCHEMA ... CASCADE to destroy all objects in it quickly is otherwise valid.

提交回复
热议问题