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 <mrylander@gmail.com>
--- /dev/null
+#!/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
+
+