Run script on multiple schemas on PostgreSQL DB
You could run the following bash script. It will expect the list of schemas in the schemas.txt file, and your script in myscript.sql. It will run the script on each schema (as a default schema) in mydatabase, and will produce, for each schema, a file named myscript-output-&lt;the_schema_name&gt;.txt.

For Unix, the script is:

cat schemas.txt | while read schema; do
  (
    echo "SET search_path TO $schema,public;"
    cat myscript.sql
  ) | psql -f - -o myscript-output-${schema}.txt mydatabase
done


For windows, the script is (use %%S instead of %S when used in a batch file):

for /F %S in (schemas.txt) do @(
  echo SET search_path TO %S,public;
  type myscript.sql
) | "C:\Program Files\PostgreSQL\9.3\bin\psql" -f - -o  myscript-output-%S.txt mydatabase