Postgresql database cleanup

How to completely erase a Postgres database? I am sending requests through Django in a PaaS service, and I think I can’t access the command line utilities. I would just reset the entire database and recreate it, but I do not have rights to do this.

I am looking for a simple command that will return the database to a completely virgin state.

+4
source share
1 answer

you can cascade the circuit and then drop db:

drop schema myschema CASCADE; drop database mydb; 

if you do not have rights to do so, you will have to abandon table after table.

EDIT: if you can only drop tables, this will give you SQL queries to run:

 select 'drop table '||schemaname||'.'||tablename||' CASCADE;' from pg_tables where schemaname = 'myschema' order by schemaname, tablename; 
+7
source

Source: https://habr.com/ru/post/1379176/


All Articles