From 84a1a8011df629e385ba6f12621804639b85b20e Mon Sep 17 00:00:00 2001 From: Igor Artemenko Date: Tue, 21 Mar 2023 10:13:10 +0000 Subject: [PATCH] Connect to default database to find all databases The psql call for finding all databases (which happens when DB_NAME is ALL or SPLIT_DB is FALSE) fails if DB_USER is not an existing database. This change stops using DB_USER for the -d option. If you run psql without specifying -d/--dbname, it uses "postgres" by default, going so far as to raise an error if it is missing: / # psql -U postgres psql: error: FATAL: database "postgres" does not exist I think it makes sense to use the same assumption for the psql call mentioned above. --- install/assets/functions/10-db-backup | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/install/assets/functions/10-db-backup b/install/assets/functions/10-db-backup index 29f6615..14fb3ae 100644 --- a/install/assets/functions/10-db-backup +++ b/install/assets/functions/10-db-backup @@ -268,10 +268,9 @@ backup_mysql() { backup_pgsql() { export PGPASSWORD=${DB_PASS} - authdb=${DB_USER} if [ "${DB_NAME,,}" = "all" ] ; then print_debug "Preparing to back up all databases" - db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) + db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) if [ -n "${DB_NAME_EXCLUDE}" ] ; then db_names_exclusions=$(echo "${DB_NAME_EXCLUDE}" | tr ',' '\n') for db_exclude in ${db_names_exclusions} ; do @@ -306,7 +305,7 @@ backup_pgsql() { compression pre_dbbackup all print_notice "Dumping all PostgreSQL databases: '$(echo ${db_names} | xargs | tr ' ' ',')' ${compression_string}" - tmp_db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -d ${authdb} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) + tmp_db_names=$(psql -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} -c 'COPY (SELECT datname FROM pg_database WHERE datistemplate = false) TO STDOUT;' ) for r_db_name in $(echo $db_names | xargs); do tmp_db_names=$(echo "$tmp_db_names" | xargs | sed "s|${r_db_name}||g" ) done