DEV Community

Cover image for PostgreSQL: Delete database and user
Sergio Peris
Sergio Peris

Posted on • Originally published at sertxu.dev

PostgreSQL: Delete database and user

Using PostgreSQL you might want to delete a database or a user you previously created.

To delete a database, you should run the following query.

DROP DATABASE "project";
Enter fullscreen mode Exit fullscreen mode

To delete a user, you should run the following query.

DROP USER "username";
Enter fullscreen mode Exit fullscreen mode

If the user to be deleted is the owner of a database, you're required to change the owner or delete the database, or you will receive the error role "username" cannot be dropped because some objects depend on it.

Top comments (0)