Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psql how to drop current database [duplicate]

Tags:

postgresql

Trying to drop the primary database "foo", I get the error

ERROR: cannot drop the currently open database

Whats the right way to drop the primary psql database?

like image 486
ThorSummoner Avatar asked Mar 07 '18 01:03

ThorSummoner


People also ask

How do I drop duplicates in PostgreSQL?

For finding the duplicates, we can utilize the Postgres COUNT() function. While to remove duplicate rows, we can use the “DELETE USING” Statement, subquery, or Postgres immediate Table.

How do I drop a current database?

Once a database is no longer needed, you can drop it by using the DROP DATABASE statement. To delete a database: Specify the name of the database that you want to delete after the DROP DATABASE clause. Use IF EXISTS to prevent an error from removing a non-existent database.

How do I drop a PostgreSQL database?

The first method to remove a PostgreSQL database is to use the following SQL statement: DROP DATABASE <database name>; The command removes the directory containing the database information and the catalog entries. Only the database owner can execute the DROP DATABASE command.

What does \d do in psql?

The command \d in psql lists all tables, views, and sequences.


2 Answers

Create a new database to log into while you drop the original one - I guess?

create database _;
(relog with -d _ )
drop database dbname;
create database dbname;
(relog)
drop database _;
like image 45
ThorSummoner Avatar answered Sep 19 '22 05:09

ThorSummoner


That's what the database postgres is there for.

Connect to it to drop your database.

like image 187
Laurenz Albe Avatar answered Sep 17 '22 05:09

Laurenz Albe