commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
This command drops all the tables of the 'public' schema from the database.
First, it constructs a 'drop table' instruction for each table found in the schema, then it pipes the result to the psql interactive command.
Useful when you have to recreate your schema from scratch in development for example.
I mainly use this command in conjunction with a similar command which drop all sequences as well.
psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db> -t -c "select 'drop table \"' || tablename || '\" cascade;' from pg_tables where schemaname='public'" | psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db>
psql -h <ph_host> -p <pg_port> -U <pg_user> <pg_db> -t -c "select 'drop sequence \"' || relname || '\" cascade;' from pg_class where relkind='S'" | psql -h <ph_host> -p <pg_port> -U <pg_user> <pg_db>
See it scripted here : https://gist.github.com/cuberri/6868774#file-postgresql-drop-create-sh
There is 1 alternative - vote for the best!
If you can do better, submit your command here.
You must be signed in to comment.