The database name is being accessed by other users Postgres | drop the database with command line in Postgres

dropdb destroys an existing PostgreSQL database. The user who executes this command must be a database superuser or the owner of the database. dropdb is a wrapper around the SQL command DROP DATABASE. There is no effective difference between dropping databases via this utility and via other methods for accessing the server.

dropdb [connection-option...] [option...] dbname

To destroy the database demo on the default database server:

dropdb demo

To destroy the database demo using the server on host localhost, port 5000, with verification:

dropdb -p 5000 -h localhost demo

If you are not sure database exists or not before deleting then you can use --if-exists.

dropdb --if-exists demo

If dropdb command giving an error of existing connections then you can use -f parameter with command. It will attempt to terminate all existing connections to the target database before dropping it. ( It will work 13+ version)

dropdb -f demo

Leave a Reply