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
1 Answer
Reset to default 5Unless 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;