Skip to content

Instantly share code, notes, and snippets.

@shilovk
Forked from dsci/drop.sh
Last active July 12, 2021 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shilovk/748466a23bc2a146d60d8b2f5ea7370e to your computer and use it in GitHub Desktop.
Save shilovk/748466a23bc2a146d60d8b2f5ea7370e to your computer and use it in GitHub Desktop.
Dropping tables in a PostgreSQL database by table owner
# first, login with psql
psql -U user_name -W -d database_name -h ip_address
# set output for all queries
\o file_name.sql
# run this query
select 'drop table if exist "'|| tablename ||'" cascade;' from pg_tables where tableowner='user_name' and schemaname='public';
# logout from psql
\q
# run sql script from commandline
psql -U user_name -W -d database_name -f file_name.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment