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?
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.
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.
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.
You can delete the postgres but do not touch template0 or template1.
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.
If you are using something debian-like, the cleanest way is to run pg_dropcluster
pg_dropcluster --stop 9.4 main
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With