Drop all tables from PostgreSQL DB without superuser

Drop all tables from PostgreSQL DB without superuser

Posted January 1st, 2010 by shunting

Via:

psql -t -d my_dbname -c "SELECT 'DROP TABLE ' || n.nspname || '.' ||
c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN
pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =
'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
pg_catalog.pg_table_is_visible(c.oid)"
>/tmp/droptables

psql -d my_dbname -f /tmp/droptables

Awesome.