Skip to content

Instantly share code, notes, and snippets.

@viewpointsa
Created February 7, 2019 13:08
Show Gist options
  • Save viewpointsa/e230f6171762f52b36405c3b8df24ba0 to your computer and use it in GitHub Desktop.
Save viewpointsa/e230f6171762f52b36405c3b8df24ba0 to your computer and use it in GitHub Desktop.
#/bin/bash
if [ $# -ne 2 ]; then
echo $0: usage: myscript databasename zipfile
exit 1
fi
dbname=$1
psql --command "select pg_terminate_backend(procpid) from pg_stat_activity where datname = '$dbname';"
dropdb $dbname
createdb $dbname
gunzip -c ${2} | psql $dbname
psql $dbname --command "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO admin ;"
psql $dbname --command "GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO admin ;"
if [ -f "post_$dbname.sql" ]
then
cat "post_$dbname.sql" | psql $dbname
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment