PostgreSQL DROP DATABASE Syntax: Here:-

IF EXISTS: This is an optional parameter. In case of the database does not exist, a warning is displayed instead of an error name: mention the DB name that you want to drop

Let’s see an PostgreSQL drop database command line example in action

PostgreSQL Drop Database Using SQL Shell(Command Line)

Below is a step by step process to drop database in Postgres command line: Step 1) Use command \l to determine the currently available database.

Step 2) To drop database in Postgres, enter command Use command \l to check whether DB is deleted

Step 3) Try to drop the same database again, you will get an error.

Step 4) Drop the database with IF exists clause and you get a warning

PostgreSQL Drop Database PgAdmin (GUI)

Step 1) Right Click on database “guru99” and click “Delete/Drop.”

Step 2) Click OK on the confirmation pop-up

Database is deleted.

dropdb command

The dropdb command allows you to delete database in PostgreSQL remotely. But, the user must be the owner of the database in order use PostgreSQL delete database command to delete that database. Syntax:

PostgreSQL DROP DATABASE Example

We want to destroy a database guru99 with the help of a server on host rome, port 4565, with verification and you need to use following drop database PostgreSQL command: Database “guru99” will be permanently deleted. Are you sure? (y/n) if you select y, then you can DROP DATABASE guru99;

Summary

The PSQL DROP DATABASE statement removes all the catalog entries and data directory permanently from the PostgreSQL environment You can use If exists clause so that no error is displayed You can also drop a database using pgadmin dropdb command allows you to remotely drop or delete database in PSQL