---
description: The DROP DATABASE statement removes all the catalog entries and data directory permanently from the PostgreSQL environment. So, you should be extra cautious when performing this operation. However, th
title: PostgreSQL DROP/Delete DATABASE Using Command Line
image: https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

PostgreSQL DROP DATABASE permanently removes a database, including all its catalog entries and data files. You can run it from the psql shell, delete a database visually in pgAdmin, or use the dropdb command to remove a database remotely.

* ⚠️ **Permanent Action:** DROP DATABASE deletes all catalog entries and the data directory, so the operation cannot be undone.
* 🔒 **Owner Only:** Only the database owner can drop it, and no active sessions can be connected to the target database.
* 💻 **SQL Shell:** In psql, run DROP DATABASE name after connecting to a different database, then use \\l to confirm removal.
* 🛡️ **IF EXISTS Clause:** Adding IF EXISTS returns a warning instead of an error when the database does not exist.
* 🖱️ **pgAdmin GUI:** Right-click the database in the Object Tree, choose Delete/Drop, and confirm to remove it visually.
* 🌐 **dropdb Command:** The dropdb command-line utility drops a database remotely, with options for host, port, and confirmation.

[ Read More ](javascript:void%280%29;) 

![PostgreSQL DROP/Delete DATABASE](https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png)

## Drop Database in PostgreSQL

The **DROP DATABASE** in PostgreSQL is a statement to permanently remove all catalog entries and data directory. The database owner can only execute this command. It can not be executed while someone is connected with the target database. You need to connect to some other database to execute the DROP DATABASE command.

So, you should be extra cautious when performing this operation.

**PostgreSQL DROP DATABASE Syntax:**

DROP DATABASE [IF EXISTS] name;

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.

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD1.png)

**Step 2)** To drop database in Postgres, enter command

drop database guru99

Use command \\l to check whether DB is deleted

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD2.png)

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

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD3.png)

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

drop database IF EXISTS guru99

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD4.png)

## PostgreSQL Drop Database PgAdmin (GUI)

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

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD5.png)

**Step 2)** Click OK on the confirmation pop-up

[](https://www.guru99.com/images/1/092818%5F0625%5FPostgreSQLD6.png)

Database is deleted.

### RELATED ARTICLES

* [PostgreSQL Tutorial for Beginners ](https://www.guru99.com/postgresql-tutorial.html "PostgreSQL Tutorial for Beginners")
* [PostgreSQL Union, Union ALL with Examples ](https://www.guru99.com/postgresql-union-example.html "PostgreSQL Union, Union ALL with Examples")
* [PostgreSQL Array: Functions, Type, Example ](https://www.guru99.com/postgresql-array-functions.html "PostgreSQL Array: Functions, Type, Example")
* [PostgreSQL EXISTS with SELECT Operator (Example) ](https://www.guru99.com/postgresql-exists.html "PostgreSQL EXISTS with SELECT Operator (Example)")

## 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:**

dropdb [option...] dbname

| Option                 | Description                                                                                                                               |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| \-e                    | Echo commands that dropdb creates and sends to the server.                                                                                |
| \-i                    | Display a verification prompt before performing any destructive job                                                                       |
| \-V                    | Use this option to print the dropdb version.                                                                                              |
| –help                  | Provide help with dropdb command-line arguments.                                                                                          |
| \-h host               | Helps you to specify the name of the host of the system on which the server is currently running.                                         |
| \-p port               | Option allows you to specify the TCP port or the local Unix domain socket file extension on which the server is establishing connections. |
| –if-exists             | Issues a notice instead of an error if the database does not exist.                                                                       |
| \-U username           | User name to connect as.                                                                                                                  |
| \-w                    | Use this option if you don’t want a password prompt                                                                                       |
| \-W                    | Use this parameter to prompt for a password before dropping the database.                                                                 |
| –maintenance-db=dbname | Specifies the name of the database to connect to in order to drop the target database.                                                    |

### 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:

dropdb -p 4565 -h rome -i -e guru99

Database “guru99” will be permanently deleted.

Are you sure? (y/n) if you select y, then you can

DROP DATABASE guru99;

## FAQs

💾 Can you recover a database after DROP DATABASE in PostgreSQL?

No. DROP DATABASE permanently deletes the data directory, so there is no built-in undo. Recovery is only possible if you have a prior backup, a dump file, or point-in-time recovery configured before the drop.

🔗 How do you fix the “database is being accessed by other users” error?

This error means active sessions are connected. Disconnect them, or run pg\_terminate\_backend() on their process IDs from another database, then retry DROP DATABASE. You cannot drop a database you are currently connected to.

⚖️ What is the difference between DROP DATABASE and dropdb?

DROP DATABASE is an SQL statement run inside psql or pgAdmin. dropdb is a command-line utility that wraps it, letting you drop a database remotely with options for host, port, and confirmation prompts.

🤖 How can AI help safely drop a PostgreSQL database?

AI can generate the correct DROP DATABASE or dropdb command, remind you to back up first, and add the IF EXISTS clause. It can also list active connections you must close before dropping.

🤖 Can AI help recover from an accidental DROP DATABASE?

AI cannot restore deleted data, but it can guide you through restoring from a backup or dump file, and help write a point-in-time recovery plan to prevent future accidental data loss.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png","url":"https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png","width":"700","height":"250","caption":"PostgreSQL DROP/Delete DATABASE","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/postgresql-drop-database.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/postgresql","name":"PostgreSQL"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/postgresql-drop-database.html","name":"PostgreSQL DROP/Delete DATABASE Using Command Line"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/postgresql-drop-database.html#webpage","url":"https://www.guru99.com/postgresql-drop-database.html","name":"PostgreSQL DROP/Delete DATABASE Using Command Line","dateModified":"2026-07-02T10:48:19+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/postgresql-drop-database.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/juniper","name":"Juniper Willow","description":"I am Juniper Willow, a PostgreSQL Developer, offering expert guidance to help you optimize and master PostgreSQL database development.","url":"https://www.guru99.com/author/juniper","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/juniper-willow-author.png","url":"https://www.guru99.com/images/juniper-willow-author.png","caption":"Juniper Willow","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"PostgreSQL","headline":"PostgreSQL DROP/Delete DATABASE Using Command Line","description":"The DROP DATABASE statement removes all the catalog entries and data directory permanently from the PostgreSQL environment. So, you should be extra cautious when performing this operation. However, th","keywords":"postgresql, sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/juniper","name":"Juniper Willow"},"dateModified":"2026-07-02T10:48:19+05:30","image":{"@id":"https://www.guru99.com/images/postgresql-drop-delete-database-guru99.png"},"copyrightYear":"2026","name":"PostgreSQL DROP/Delete DATABASE Using Command Line","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can you recover a database after DROP DATABASE in PostgreSQL?","acceptedAnswer":{"@type":"Answer","text":"No. DROP DATABASE permanently deletes the data directory, so there is no built-in undo. Recovery is only possible if you have a prior backup, a dump file, or point-in-time recovery configured before the drop."}},{"@type":"Question","name":"How do you fix the \"database is being accessed by other users\" error?","acceptedAnswer":{"@type":"Answer","text":"This error means active sessions are connected. Disconnect them, or run pg_terminate_backend() on their process IDs from another database, then retry DROP DATABASE. You cannot drop a database you are currently connected to."}},{"@type":"Question","name":"What is the difference between DROP DATABASE and dropdb?","acceptedAnswer":{"@type":"Answer","text":"DROP DATABASE is an SQL statement run inside psql or pgAdmin. dropdb is a command-line utility that wraps it, letting you drop a database remotely with options for host, port, and confirmation prompts."}},{"@type":"Question","name":"How can AI help safely drop a PostgreSQL database?","acceptedAnswer":{"@type":"Answer","text":"AI can generate the correct DROP DATABASE or dropdb command, remind you to back up first, and add the IF EXISTS clause. It can also list active connections you must close before dropping."}},{"@type":"Question","name":"Can AI help recover from an accidental DROP DATABASE?","acceptedAnswer":{"@type":"Answer","text":"AI cannot restore deleted data, but it can guide you through restoring from a backup or dump file, and help write a point-in-time recovery plan to prevent future accidental data loss."}}]}],"@id":"https://www.guru99.com/postgresql-drop-database.html#schema-1128578","isPartOf":{"@id":"https://www.guru99.com/postgresql-drop-database.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/postgresql-drop-database.html#webpage"}}]}
```
