Created
May 28, 2019 22:09
-
-
Save AlexArcPy/f62de066f607acb6699e37a8e14cef1c to your computer and use it in GitHub Desktop.
Drop PostgreSQL database matching name pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Drop PostgreSQL database matching a pattern" | |
cd C:/Temp | |
sql_query="select 'drop database \"'||datname||'\";' from pg_database WHERE datistemplate = false and datname like 'operat%';" | |
echo $sql_query | |
PGPASSWORD=postgres psql -p 5432 -d postgres -U postgres -t -A -F"," -c "${sql_query}" > drop_dbs.sql | |
cat drop_dbs.sql | while read line | |
do | |
echo $line; | |
PGPASSWORD=postgres psql -p 5432 -d postgres -U postgres -t -A -F"," -c "${line}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment