11

I'm sending queries through Django on a PaaS service, and I think I can't access any command line utilities. I would have just dropped the entire database and recreated it, but I don't have permissions for that.

I'm looking for a simple command that would return the database to a completely virgin state.

Piper
  • 1,266
  • 3
  • 15
  • 26
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
  • see also: [Drop all tables in postgresql?](http://stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql) – tedder42 Feb 28 '14 at 18:01

1 Answers1

11

you could cascade drop the schema and then drop the db:

drop schema myschema CASCADE;
drop database mydb;

if you do not have the rights to do so, you will have to drop table by table.

EDIT: If you can only drop tables, this will give you the SQL statements to run:

select 'drop table '||schemaname||'.'||tablename||' CASCADE;' 
from pg_tables where schemaname = 'myschema' order by schemaname, tablename;
Community
  • 1
  • 1
Martin Samson
  • 3,970
  • 21
  • 25