Created
May 22, 2015 14:22
-
-
Save PeloNZ/5035fba1eb5f5168936e to your computer and use it in GitHub Desktop.
quick db upgrade script
This file contains hidden or 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
#!/bin/bash | |
set -x | |
if [ $1 ] ; then | |
DBFROM=$1 | |
fi | |
if [ $2 ]; then | |
DBTO=$2 | |
fi | |
# shrink tables | |
sudo -u postgres psql -ec "TRUNCATE mdl_log, mdl_backup_logs, mdl_tool_sync_preprocess_report, mdl_totara_sync_log;" $DBFROM | |
# drop connections | |
sudo -u postgres psql -ec "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname IN ('$DBFROM', '$DBTO') AND pid <> pg_backend_pid();" postgres | |
sudo -u postgres dropdb $DBTO | |
sudo -u postgres createdb -T $DBFROM -O $DBFROM $DBTO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment