Last Updated: February 25, 2016
·
809
· wojtekkruszewsk

Remove all tables in Postgres

Got access to psql console on remote server and want to remove tables to import something else?

> DROP TABLE stuff;
ERROR:  cannot drop table stuff because other objects depend on it
DETAIL:  table other_stuff depends on table stuff.

Whops. Let's try - remove it with all tables that reference stuff:

> DROP TABLE stuff CASCADE;
drop cascades to table other_stuff
DROP TABLE

This was the shotgun way. Now nuclear option:

> DROP SCHEMA public CASCADE;
drop cascades to table stuff
drop cascades to table other_stuf
drop cascades to table even_more_stuff;
DROP SCHEMA