Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • PostgreSQL - Get Started
  • Install PostgreSQL
  • Connect to PostgreSQL DB
  • Create Database
  • Create Table
  • Copy Table
  • Drop Table
  • Drop Database
  • Truncate Table
  • ALTER Table
  • Rename Table
  • Rename Columns
  • Add Columns
  • Modify Column Type
  • Set Default Value of Column
  • Remove Columns
  • Add Constraints to Table
  • Insert Data
  • Upsert Data
  • Update Data
  • Delete Data
  • SELECT Statement
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • DISTINCT Clause
  • Inner Join
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join
  • Self Join
  • Natural Join
  • Cross Join
  • LIMIT OFFSET Clause
  • GROUPING SETS
  • GROUPING() Function
  • GROUP BY CUBE
  • GROUP BY ROLLUP
  • Sub Query
  • ALL Operator
  • ANY Operator
  • UNION Operator
  • INTERSECT Operator
  • EXCEPT Operator
  • IS NULL Operator
  • BETWEEN Operator
  • LIKE Operator
  • CAST Operator
  • CASE Expressions
  • NULLIF()
  • COALESCE()
  • GREATEST(), LEAST()
  • WITH Queries (CTE)
  • Constraints
  • NOT NULL Constraint
  • Unique Constraint
  • Check Constraint
  • Primary Key
  • Foreign Key
  • Sequence
  • Serial Type
  • Identity Columns
  • Generated Columns
  • Data Types
  • Boolean Type
  • Character Type
  • Integer Type
  • Numeric Type
  • Date Type
  • Time Type
  • TimeStamp Type
  • Interval Type
  • Array Type
  • Json Type
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

PostgreSQL: Drop Database

PostgreSQL supports the DROP command to externally delete the database from PostgreSQL.

Use this command carefully as it drops the database permanently along with all the objects that belong to the database like tables, views, indexes, sequences, etc., which cannot be reverted.

In PostgreSQL, database can be dropped in two ways

  • Drop database from pgAdmin
  • Drop database using psql

Drop database from pgAdmin

To drop database from pgAdmin, follow these steps.

Open pgAdmin in your local system. Expand the Databases section, you will see a list of databases. Right-click on tutorials database and select Delete/Drop from the list of dropdown options to delete the database.

It will show confirmation popup before deleting the database

Once you click on the Yes button, the database will be deleted immediately. You will not find that database in the list of Databases as it is deleted permanently.

Drop Database using psql

The database can be deleted using psql also.

Syntax
DROP DATABASE [IF EXISTS] <database_name>

Use the IF EXISTS option to drop the database only if it exists. If the specified database does not exist, then it will give a warning and skip the drop command.

Open SQL Shell (psql) and make a database connection. Give the \l command to view a list of all databases, as shown below.

Now, give the following command to drop a database.

drop database tutorials;

You may receive bellow error while dropping database if database you try to drop has another active sessions connected to it.

You can explicitly ask users to disconnect from the database before dropping the database or revoke connection access on a database from the public and then try to drop the database.

Example: Disconnect Database
REVOKE CONNECT ON DATABASE tutorials from public;

Now execute the drop database command again, drop database tutorials to drop the database. You can validate it by running a command to show the list of all databases.

If you try to drop a database that does not exist, you will get the following error.

Use the IF EXISTS clause along with the drop database to drop the database only if it exists, otherwise, just show the warning and skip the drop command.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.