Skip to content

Commit

Permalink
adding upgrade flow for postgresql in c9s, RHEL8 and later
Browse files Browse the repository at this point in the history
Add postgresql16-upgrade package into fedora dockerfile
  • Loading branch information
eifrach authored and fila43 committed Jun 18, 2024
1 parent fbba2c4 commit 72fdac1
Show file tree
Hide file tree
Showing 24 changed files with 122 additions and 46 deletions.
19 changes: 14 additions & 5 deletions 10/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions 12/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions 12/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
19 changes: 14 additions & 5 deletions 12/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions 13/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
4 changes: 2 additions & 2 deletions 13/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions 13/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
1 change: 1 addition & 0 deletions 13/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
19 changes: 14 additions & 5 deletions 13/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions 14/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
19 changes: 14 additions & 5 deletions 14/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions 15/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
4 changes: 2 additions & 2 deletions 15/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions 15/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
1 change: 1 addition & 0 deletions 15/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
19 changes: 14 additions & 5 deletions 15/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
3 changes: 2 additions & 1 deletion 16/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -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" && \
Expand Down
19 changes: 14 additions & 5 deletions 16/root/usr/share/container-scripts/postgresql/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" \
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
Loading

0 comments on commit 72fdac1

Please sign in to comment.