From ec8e7c6959cdec72bc612e5c733c8d49947efc5e Mon Sep 17 00:00:00 2001 From: Yukha Dharmeswara Date: Tue, 29 Oct 2024 12:43:50 +0700 Subject: [PATCH] [bitnami/postgresql-repmgr] fix init script tries to recreate repmgr Signed-off-by: Yukha Dharmeswara --- .../12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh | 7 ++++++- .../13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh | 7 ++++++- .../14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh | 7 ++++++- .../15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh | 7 ++++++- .../16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh | 7 ++++++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index f49f312a0cdbe..78980983054e6 100644 --- a/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/12/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -348,7 +348,12 @@ repmgr_create_repmgr_user() { [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) - echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + # In case REPMGR_USERNAME == POSTGRESQL_REPLICATION_USER, we just need to grant repmgr with CREATEDB + if [[ "$REPMGR_USERNAME" == "$POSTGRESQL_REPLICATION_USER" ]]; then + echo "ALTER USER ${REPMGR_USERNAME} WITH CREATEDB;" | postgresql_execute "" "postgres" "$postgres_password" + else + echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + fi echo "ALTER USER ${REPMGR_USERNAME} WITH SUPERUSER;" | postgresql_execute "" "postgres" "$postgres_password" # set the repmgr user's search path to include the 'repmgr' schema name (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) echo "ALTER USER ${REPMGR_USERNAME} SET search_path TO repmgr, \"\$user\", public;" | postgresql_execute "" "postgres" "$postgres_password" diff --git a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index f49f312a0cdbe..78980983054e6 100644 --- a/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/13/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -348,7 +348,12 @@ repmgr_create_repmgr_user() { [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) - echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + # In case REPMGR_USERNAME == POSTGRESQL_REPLICATION_USER, we just need to grant repmgr with CREATEDB + if [[ "$REPMGR_USERNAME" == "$POSTGRESQL_REPLICATION_USER" ]]; then + echo "ALTER USER ${REPMGR_USERNAME} WITH CREATEDB;" | postgresql_execute "" "postgres" "$postgres_password" + else + echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + fi echo "ALTER USER ${REPMGR_USERNAME} WITH SUPERUSER;" | postgresql_execute "" "postgres" "$postgres_password" # set the repmgr user's search path to include the 'repmgr' schema name (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) echo "ALTER USER ${REPMGR_USERNAME} SET search_path TO repmgr, \"\$user\", public;" | postgresql_execute "" "postgres" "$postgres_password" diff --git a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index f49f312a0cdbe..78980983054e6 100644 --- a/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/14/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -348,7 +348,12 @@ repmgr_create_repmgr_user() { [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) - echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + # In case REPMGR_USERNAME == POSTGRESQL_REPLICATION_USER, we just need to grant repmgr with CREATEDB + if [[ "$REPMGR_USERNAME" == "$POSTGRESQL_REPLICATION_USER" ]]; then + echo "ALTER USER ${REPMGR_USERNAME} WITH CREATEDB;" | postgresql_execute "" "postgres" "$postgres_password" + else + echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + fi echo "ALTER USER ${REPMGR_USERNAME} WITH SUPERUSER;" | postgresql_execute "" "postgres" "$postgres_password" # set the repmgr user's search path to include the 'repmgr' schema name (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) echo "ALTER USER ${REPMGR_USERNAME} SET search_path TO repmgr, \"\$user\", public;" | postgresql_execute "" "postgres" "$postgres_password" diff --git a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index f49f312a0cdbe..78980983054e6 100644 --- a/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/15/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -348,7 +348,12 @@ repmgr_create_repmgr_user() { [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) - echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + # In case REPMGR_USERNAME == POSTGRESQL_REPLICATION_USER, we just need to grant repmgr with CREATEDB + if [[ "$REPMGR_USERNAME" == "$POSTGRESQL_REPLICATION_USER" ]]; then + echo "ALTER USER ${REPMGR_USERNAME} WITH CREATEDB;" | postgresql_execute "" "postgres" "$postgres_password" + else + echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + fi echo "ALTER USER ${REPMGR_USERNAME} WITH SUPERUSER;" | postgresql_execute "" "postgres" "$postgres_password" # set the repmgr user's search path to include the 'repmgr' schema name (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) echo "ALTER USER ${REPMGR_USERNAME} SET search_path TO repmgr, \"\$user\", public;" | postgresql_execute "" "postgres" "$postgres_password" diff --git a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh index f49f312a0cdbe..78980983054e6 100644 --- a/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh +++ b/bitnami/postgresql-repmgr/16/debian-12/rootfs/opt/bitnami/scripts/librepmgr.sh @@ -348,7 +348,12 @@ repmgr_create_repmgr_user() { [[ "$POSTGRESQL_USERNAME" != "postgres" ]] && [[ -n "$POSTGRESQL_POSTGRES_PASSWORD" ]] && postgres_password="$POSTGRESQL_POSTGRES_PASSWORD" # The repmgr user is created as superuser for simplicity (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) - echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + # In case REPMGR_USERNAME == POSTGRESQL_REPLICATION_USER, we just need to grant repmgr with CREATEDB + if [[ "$REPMGR_USERNAME" == "$POSTGRESQL_REPLICATION_USER" ]]; then + echo "ALTER USER ${REPMGR_USERNAME} WITH CREATEDB;" | postgresql_execute "" "postgres" "$postgres_password" + else + echo "CREATE ROLE \"${REPMGR_USERNAME}\" WITH LOGIN CREATEDB PASSWORD '${escaped_password}';" | postgresql_execute "" "postgres" "$postgres_password" + fi echo "ALTER USER ${REPMGR_USERNAME} WITH SUPERUSER;" | postgresql_execute "" "postgres" "$postgres_password" # set the repmgr user's search path to include the 'repmgr' schema name (ref: https://repmgr.org/docs/4.3/quickstart-repmgr-user-database.html) echo "ALTER USER ${REPMGR_USERNAME} SET search_path TO repmgr, \"\$user\", public;" | postgresql_execute "" "postgres" "$postgres_password"