Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all databases on Postgres?

Tags:

postgresql

I take daily backs of our postgres development box using: pg_dumpall -h 127.0.0.1 -U user -w | gzip blah.gz

Since 9.0 is now a release candidate I would like to restore this daily backup on a daily basis to a postgres9.0rc1 box for testing, however I'm not sure how to script it repeatedly. Is there some directory I can nuke to do this?

like image 333
chotchki Avatar asked Sep 16 '10 19:09

chotchki


People also ask

How do I delete multiple databases in PostgreSQL?

Version (3.0. 2b) of OmniDB does not have an option for selecting and dropping multiple databases. To drop a database in OmniDB, you right-click on a database, select Drop Database from the context menu, run the query to drop the database, and finally close the query window.

How do you delete all databases in pgAdmin 4?

But there is another way in pgAdmin4: Close connections to the databases you would like to delete by right-clicking on it and selecting "Disconnect database..." Left-click on "Databases" (One up in the hierarchy: The folder that contains all your databases)

Can I delete default Postgres database?

You can delete the postgres but do not touch template0 or template1. The postgres database is there for convenience.


2 Answers

You can do "drop cluster" and "create cluster" which will automtically erase all databases. Erase all data in you $PGDATA directory and reinit the cluster using:

initdb -D /usr/local/pgsql/data 
like image 97
halfdan Avatar answered Oct 02 '22 21:10

halfdan


You can use:

$ pg_dropcluster 9.2 main $ pg_createcluster 9.2 main $ pg_ctlcluster 9.2 main start $ pg_restore -f your_dump_file 

where 9.2 = cluster version and main = cluster name

like image 24
Fernando Almeida Avatar answered Oct 02 '22 23:10

Fernando Almeida