Skip to content

Instantly share code, notes, and snippets.

@charyorde
Forked from dsci/drop.sh
Created June 10, 2018 12:14
Show Gist options
  • Save charyorde/491c186bf8fcaaa41aac45f63d1fd3c0 to your computer and use it in GitHub Desktop.
Save charyorde/491c186bf8fcaaa41aac45f63d1fd3c0 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