Skip to content

Instantly share code, notes, and snippets.

@dsci
Created August 7, 2012 09:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dsci/3283942 to your computer and use it in GitHub Desktop.
Save dsci/3283942 to your computer and use it in GitHub Desktop.
Dropping all tables in a PostgreSQL database
# first, login with psql
psql -U USERNAME -d databasename
# set output for all queries
\o FILENAME.sql
# run this query
select 'drop table ' || tablename || ' cascade;' from pg_tables;
# logout from psql
\q
# run sql script from commandline
psql -U USERNAME -d databasename -f FILENAME.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment