ExecInAllDatabases uses "bash" and "psql" to execute sql in every database that allows connections, including templates. The sql command(s) may contain psql variables that are assigned from the variables map. - https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES
( ctx context.Context, sql string, variables map[string]string, )
| 46 | // psql variables that are assigned from the variables map. |
| 47 | // - https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-VARIABLES |
| 48 | func (exec Executor) ExecInAllDatabases( |
| 49 | ctx context.Context, sql string, variables map[string]string, |
| 50 | ) (string, string, error) { |
| 51 | const databases = "" + |
| 52 | // Prevent unexpected dereferences by emptying "search_path". |
| 53 | // The "pg_catalog" schema is still searched. |
| 54 | // - https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-SEARCH-PATH |
| 55 | `SET search_path = '';` + |
| 56 | |
| 57 | // Return the names of databases that allow connections, including |
| 58 | // "template1". Exclude "template0" to ensure it is never manipulated. |
| 59 | // - https://www.postgresql.org/docs/current/managing-databases.html |
| 60 | `SELECT datname FROM pg_catalog.pg_database` + |
| 61 | ` WHERE datallowconn AND datname NOT IN ('template0')` |
| 62 | |
| 63 | return exec.ExecInDatabasesFromQuery(ctx, databases, sql, variables) |
| 64 | } |
| 65 | |
| 66 | // ExecInDatabasesFromQuery uses "bash" and "psql" to execute sql in every |
| 67 | // database returned by the databases query. The sql statement(s) may contain |