From 72fdac15babdc597fbda99a7e7437bfe39a5413b Mon Sep 17 00:00:00 2001 From: Eran Ifrach Date: Thu, 11 Apr 2024 15:08:21 +0300 Subject: [PATCH] adding upgrade flow for postgresql in c9s, RHEL8 and later Add postgresql16-upgrade package into fedora dockerfile --- .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 12/Dockerfile.fedora | 4 ++-- 12/Dockerfile.rhel8 | 1 + .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 13/Dockerfile.c9s | 1 + 13/Dockerfile.fedora | 4 ++-- 13/Dockerfile.rhel8 | 1 + 13/Dockerfile.rhel9 | 1 + .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 14/Dockerfile.fedora | 4 ++-- .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 15/Dockerfile.c9s | 1 + 15/Dockerfile.fedora | 4 ++-- 15/Dockerfile.rhel8 | 1 + 15/Dockerfile.rhel9 | 1 + .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 16/Dockerfile.c9s | 1 + 16/Dockerfile.fedora | 3 ++- 16/Dockerfile.rhel8 | 1 + 16/Dockerfile.rhel9 | 1 + .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- src/Dockerfile | 1 + src/Dockerfile.fedora | 5 +++-- .../container-scripts/postgresql/common.sh | 19 ++++++++++++++----- 24 files changed, 122 insertions(+), 46 deletions(-) diff --git a/10/root/usr/share/container-scripts/postgresql/common.sh b/10/root/usr/share/container-scripts/postgresql/common.sh index 1e23f839..0b57e599 100644 --- a/10/root/usr/share/container-scripts/postgresql/common.sh +++ b/10/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/12/Dockerfile.fedora b/12/Dockerfile.fedora index f5ce3586..afcc8bc9 100644 --- a/12/Dockerfile.fedora +++ b/12/Dockerfile.fedora @@ -44,8 +44,8 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # This image must forever use UID 26 for postgres user so our volumes are # safe in the future. This should *never* change, the last test is there # to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ - INSTALL_PKGS+="findutils xz" && \ +RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper postgresql-upgrade procps-ng util-linux" && \ + INSTALL_PKGS+=" findutils xz" && \ INSTALL_PKGS+=" pgaudit" && \ dnf -y module enable postgresql:12 && \ dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ diff --git a/12/Dockerfile.rhel8 b/12/Dockerfile.rhel8 index 9c8aa1e5..c9b76963 100644 --- a/12/Dockerfile.rhel8 +++ b/12/Dockerfile.rhel8 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN yum -y module enable postgresql:12 && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/12/root/usr/share/container-scripts/postgresql/common.sh b/12/root/usr/share/container-scripts/postgresql/common.sh index 6a3c6f2b..eff22d87 100644 --- a/12/root/usr/share/container-scripts/postgresql/common.sh +++ b/12/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/13/Dockerfile.c9s b/13/Dockerfile.c9s index a868fb13..075839d2 100644 --- a/13/Dockerfile.c9s +++ b/13/Dockerfile.c9s @@ -44,6 +44,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:13 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/13/Dockerfile.fedora b/13/Dockerfile.fedora index aa7f63a6..124e1bb2 100644 --- a/13/Dockerfile.fedora +++ b/13/Dockerfile.fedora @@ -44,8 +44,8 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # This image must forever use UID 26 for postgres user so our volumes are # safe in the future. This should *never* change, the last test is there # to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ - INSTALL_PKGS+="findutils xz" && \ +RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper postgresql-upgrade procps-ng util-linux" && \ + INSTALL_PKGS+=" findutils xz" && \ INSTALL_PKGS+=" pgaudit" && \ dnf -y module enable postgresql:13 && \ dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ diff --git a/13/Dockerfile.rhel8 b/13/Dockerfile.rhel8 index 38e3b951..b6e39c72 100644 --- a/13/Dockerfile.rhel8 +++ b/13/Dockerfile.rhel8 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN yum -y module enable postgresql:13 && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/13/Dockerfile.rhel9 b/13/Dockerfile.rhel9 index 063ec1f4..a53a917f 100644 --- a/13/Dockerfile.rhel9 +++ b/13/Dockerfile.rhel9 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:13 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/13/root/usr/share/container-scripts/postgresql/common.sh b/13/root/usr/share/container-scripts/postgresql/common.sh index 9da493a2..afcfc059 100644 --- a/13/root/usr/share/container-scripts/postgresql/common.sh +++ b/13/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/14/Dockerfile.fedora b/14/Dockerfile.fedora index a1ece9c2..888ebc88 100644 --- a/14/Dockerfile.fedora +++ b/14/Dockerfile.fedora @@ -44,8 +44,8 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # This image must forever use UID 26 for postgres user so our volumes are # safe in the future. This should *never* change, the last test is there # to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ - INSTALL_PKGS+="findutils xz" && \ +RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper postgresql-upgrade procps-ng util-linux" && \ + INSTALL_PKGS+=" findutils xz" && \ INSTALL_PKGS+=" pgaudit" && \ dnf -y module enable postgresql:14 && \ dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ diff --git a/14/root/usr/share/container-scripts/postgresql/common.sh b/14/root/usr/share/container-scripts/postgresql/common.sh index 4a81bf4f..b2b7b762 100644 --- a/14/root/usr/share/container-scripts/postgresql/common.sh +++ b/14/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/15/Dockerfile.c9s b/15/Dockerfile.c9s index 378ea8f3..25ab942f 100644 --- a/15/Dockerfile.c9s +++ b/15/Dockerfile.c9s @@ -44,6 +44,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:15 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/15/Dockerfile.fedora b/15/Dockerfile.fedora index 560e3bd6..130f7cca 100644 --- a/15/Dockerfile.fedora +++ b/15/Dockerfile.fedora @@ -44,8 +44,8 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # This image must forever use UID 26 for postgres user so our volumes are # safe in the future. This should *never* change, the last test is there # to make sure of that. -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ - INSTALL_PKGS+="findutils xz" && \ +RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper postgresql-upgrade procps-ng util-linux" && \ + INSTALL_PKGS+=" findutils xz" && \ INSTALL_PKGS+=" pgaudit" && \ dnf -y module enable postgresql:15 && \ dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ diff --git a/15/Dockerfile.rhel8 b/15/Dockerfile.rhel8 index 76a568c0..09304483 100644 --- a/15/Dockerfile.rhel8 +++ b/15/Dockerfile.rhel8 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN yum -y module enable postgresql:15 && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/15/Dockerfile.rhel9 b/15/Dockerfile.rhel9 index c464d0b5..23566a5b 100644 --- a/15/Dockerfile.rhel9 +++ b/15/Dockerfile.rhel9 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:15 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/15/root/usr/share/container-scripts/postgresql/common.sh b/15/root/usr/share/container-scripts/postgresql/common.sh index 35d7cc37..be2eb759 100644 --- a/15/root/usr/share/container-scripts/postgresql/common.sh +++ b/15/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/16/Dockerfile.c9s b/16/Dockerfile.c9s index 91b16096..7eafdcf5 100644 --- a/16/Dockerfile.c9s +++ b/16/Dockerfile.c9s @@ -44,6 +44,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:16 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/16/Dockerfile.fedora b/16/Dockerfile.fedora index 9c0bb6f0..a759f112 100644 --- a/16/Dockerfile.fedora +++ b/16/Dockerfile.fedora @@ -45,7 +45,8 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # safe in the future. This should *never* change, the last test is there # to make sure of that. RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql16-server postgresql16-contrib nss_wrapper " && \ - INSTALL_PKGS+="findutils xz" && \ + INSTALL_PKGS+=" procps-ng util-linux postgresql16-upgrade" && \ + INSTALL_PKGS+=" findutils xz" && \ INSTALL_PKGS+=" postgresql16-pgaudit" && \ dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ diff --git a/16/Dockerfile.rhel8 b/16/Dockerfile.rhel8 index 70be99fe..510b8f10 100644 --- a/16/Dockerfile.rhel8 +++ b/16/Dockerfile.rhel8 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN yum -y module enable postgresql:16 && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/16/Dockerfile.rhel9 b/16/Dockerfile.rhel9 index bc1009b5..a81820a1 100644 --- a/16/Dockerfile.rhel9 +++ b/16/Dockerfile.rhel9 @@ -45,6 +45,7 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions RUN { yum -y module enable postgresql:16 || :; } && \ INSTALL_PKGS="rsync tar gettext bind-utils nss_wrapper postgresql-server postgresql-contrib" && \ INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ postgres -V | grep -qe "$POSTGRESQL_VERSION\." && echo "Found VERSION $POSTGRESQL_VERSION" && \ diff --git a/16/root/usr/share/container-scripts/postgresql/common.sh b/16/root/usr/share/container-scripts/postgresql/common.sh index cd80bbd5..b7482bdb 100644 --- a/16/root/usr/share/container-scripts/postgresql/common.sh +++ b/16/root/usr/share/container-scripts/postgresql/common.sh @@ -297,7 +297,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -311,8 +311,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -350,9 +359,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop diff --git a/src/Dockerfile b/src/Dockerfile index dd934cd4..1a896cc7 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -75,6 +75,7 @@ RUN {{ spec.environment_setup }} INSTALL_PKGS="$INSTALL_PKGS rh-postgresql{{ spec.short }}-pgaudit" && \ {% elif spec.prod == 'rhel8' or spec.prod == 'rhel9' or spec.prod == 'c9s' %} INSTALL_PKGS="$INSTALL_PKGS pgaudit" && \ + INSTALL_PKGS="$INSTALL_PKGS procps-ng util-linux postgresql-upgrade" && \ {% endif %} {% endif %} yum -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ diff --git a/src/Dockerfile.fedora b/src/Dockerfile.fedora index 48accf6f..b5d6cd38 100644 --- a/src/Dockerfile.fedora +++ b/src/Dockerfile.fedora @@ -50,10 +50,11 @@ COPY root/usr/libexec/fix-permissions /usr/libexec/fix-permissions # to make sure of that. {% if spec.version == "16" %} RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql16-server postgresql16-contrib nss_wrapper " && \ + INSTALL_PKGS+=" procps-ng util-linux postgresql16-upgrade" && \ {% else %} -RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper " && \ +RUN INSTALL_PKGS="rsync tar gettext bind-utils postgresql-server postgresql-contrib nss_wrapper postgresql-upgrade procps-ng util-linux" && \ {% endif %} - INSTALL_PKGS+="findutils xz" && \ + INSTALL_PKGS+=" findutils xz" && \ {% if spec.version not in ["9.6", "10", "11", "16"] %} INSTALL_PKGS+=" pgaudit" && \ {% endif %} diff --git a/src/root/usr/share/container-scripts/postgresql/common.sh b/src/root/usr/share/container-scripts/postgresql/common.sh index df39caed..7afc7ce3 100644 --- a/src/root/usr/share/container-scripts/postgresql/common.sh +++ b/src/root/usr/share/container-scripts/postgresql/common.sh @@ -298,7 +298,7 @@ function wait_for_postgresql_master() { run_pgupgrade () ( # Remove .pid file if the file persists after ugly shut down - if [ -f "$PGDATA/postmaster.pid" ] && ! pgrep -f "postgres" > /dev/null; then + if [ -f "$PGDATA/postmaster.pid" ] && ! pg_isready > /dev/null; then rm -rf "$PGDATA/postmaster.pid" fi @@ -312,8 +312,17 @@ run_pgupgrade () old_collection=rh-postgresql$old_raw_version fi - old_pgengine=/opt/rh/$old_collection/root/usr/bin - new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + # Backward compatibility for RHEL/CentOS 7 + source /etc/os-release + + if [[ $VERSION_ID -lt 8 ]]; then + old_pgengine=/opt/rh/$old_collection/root/usr/bin + new_pgengine=/opt/rh/rh-postgresql${new_raw_version}/root/usr/bin + else + old_pgengine=/usr/lib64/pgsql/postgresql-$old_raw_version/bin + new_pgengine=/usr/bin + fi + PGDATA_new="${PGDATA}-new" printf >&2 "\n========== \$PGDATA upgrade: %s -> %s ==========\n\n" \ @@ -351,9 +360,9 @@ run_pgupgrade () # boot up data directory with old postgres once again to make sure # it was shut down properly, otherwise the upgrade process fails info_msg "Starting old postgresql once again for a clean shutdown..." - "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h ''" + "${old_pgengine}/pg_ctl" start -w --timeout 86400 -o "-h 127.0.0.1''" info_msg "Waiting for postgresql to be ready for shutdown again..." - "${old_pgengine}/pg_isready" + "${old_pgengine}/pg_isready" -h 127.0.0.1 info_msg "Shutting down old postgresql cleanly..." "${old_pgengine}/pg_ctl" stop