最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PostgreSQL ERROR: must be owner of schema public - Stack Overflow

programmeradmin3浏览0评论

I am new to Postgres and am having an issue dropping all tables in a database. I have a database named "mvp" and the owner is set as "postgres." I did the following in my terminal:

psql -d mvp postgres -W
postgres=> \l
                            List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |  Access privileges  
-----------+----------+----------+---------+-------+---------------------
 mvp       | postgres | UTF8     | C       | C     | 
postgres=> \c mvp
You are now connected to database "mvp" as user "postgres".
mvp=> DROP SCHEMA public CASCADE;
ERROR:  must be owner of schema public

It is showing that I am logged in as the user "postgres" which happens to be the owner of the "mvp" database. However, I am receiving an error message saying I am not the owner.

I am new to Postgres and am having an issue dropping all tables in a database. I have a database named "mvp" and the owner is set as "postgres." I did the following in my terminal:

psql -d mvp postgres -W
postgres=> \l
                            List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |  Access privileges  
-----------+----------+----------+---------+-------+---------------------
 mvp       | postgres | UTF8     | C       | C     | 
postgres=> \c mvp
You are now connected to database "mvp" as user "postgres".
mvp=> DROP SCHEMA public CASCADE;
ERROR:  must be owner of schema public

It is showing that I am logged in as the user "postgres" which happens to be the owner of the "mvp" database. However, I am receiving an error message saying I am not the owner.

Share Improve this question asked Feb 18, 2023 at 19:20 kirasam72kirasam72 1652 silver badges10 bronze badges 2
  • 1 To your question add the answers to the following mands run in psql 1) select version(); 2) \du postgres 3) \dn public – Adrian Klaver Commented Feb 18, 2023 at 21:53
  • The \l does confirm that postgres is the owner of the database. However, the error messages says that postgres is not the owner of the schema. – Bergi Commented Feb 19, 2023 at 1:36
Add a ment  | 

1 Answer 1

Reset to default 5

Unless you have changed the ownership of schema public before, postgres (the owner of the database) would be the owner of that schema. So you'd have to connect as user postgres or a superuser to drop the schema.

To approach that methodically:

  • find out who owns schema public

    \dn public
    
  • bee that user

    \c - username
    
  • drop the schema

    DROP SCHEMA public CASCADE;
    
发布评论

评论列表(0)

  1. 暂无评论