From: Mike Rylander Date: Wed, 3 Apr 2013 16:43:20 +0000 (-0400) Subject: A script for parallelizing db updates, where possible X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=094194d8e99306ca99571a057b4f984ac8f78a52;p=working%2FEvergreen.git A script for parallelizing db updates, where possible This script takes a file of SQL commands, one complete command per line, and applies them in parallel via psql. Caveats: * no multi-line commands * no protection against foot-guns in the SQL (check for injections!) * probably will cause puppies to be eaten Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/support-scripts/parallel_db_upgrade.sh b/Open-ILS/src/support-scripts/parallel_db_upgrade.sh new file mode 100644 index 0000000000..21fb1a3a08 --- /dev/null +++ b/Open-ILS/src/support-scripts/parallel_db_upgrade.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# $0 db-name file-of-commands + +TEST_PSQL=$(PG_DATABASE=$1 psql -tAc 'select 42' 2>/dev/null); + +if [ "_$2" == "_" ]; then + echo "Usage: $0 db-name file-of-commands" + exit 1; +fi + +if [ -z $TEST_PSQL ]; then + echo "Can't connect to postgres" + exit 1; +fi + +N=0 +cat $2 | while read LINE; do + N=$((N+1)) + (PG_DATABASE=$1 echo $LINE | psql -tA -f - 2>&1 | tee $0.output.$N &) +done + +