Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql: how to delete database cluster

Tags:

postgresql

I have used the command initdb to create a database cluster:

sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb' 

If I want to delete this database cluster, can I simply remove the folder defaultdb? Or is there some command I should use?

like image 630
matthiash Avatar asked Aug 09 '11 07:08

matthiash


People also ask

What is database cluster in PostgreSQL?

A database cluster is a collection of databases that is managed by a single instance of a running database server. After initialization, a database cluster will contain a database named postgres , which is meant as a default database for use by utilities, users and third party applications.

How do you delete a database in PostgreSQL?

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.

How do I force delete a database in PostgreSQL?

A new command-line option is added to dropdb command, and a similar SQL option “FORCE” is also added in DROP DATABASE. Using the option -f or –force with dropdb command or FORCE with DROP DATABASE to drop the database, it will terminate all existing connections with the database.

Can I delete Postgres default database?

You can delete the postgres but do not touch template0 or template1.


2 Answers

Yes, If you want to delete the database cluster you just created just remove the data directory /opt/local/var/db/postgresql83/defaultdb.

By the way, if the PG server is running, shut it down before.

like image 67
francs Avatar answered Sep 28 '22 09:09

francs


If you are using something debian-like, the cleanest way is to run pg_dropcluster

pg_dropcluster --stop 9.4 main  
like image 31
Javier Parra Avatar answered Sep 28 '22 08:09

Javier Parra