From 5a8fcd6f1e4addf5163d3aea014be0d24bdef766 Mon Sep 17 00:00:00 2001 From: Mwaniki Wairungu Date: Fri, 10 Jan 2025 12:09:55 +0300 Subject: [PATCH 1/3] FEATURE: Update base image and set default to postgresql 15 This updates the default PostgreSQL version to 15. * image/base: update default postgres version to 15 * launcher: bump base image * postgres.template.yml: update default version to 15 * postgres.15.template.yml: current version template Legacy version templates: * postgres.13.template.yml * postgres.12.template.yml * postgres.10.template.yml * postgres.9.5.template.yml --- image/base/Dockerfile | 2 +- launcher | 1 + templates/postgres.10.template.yml | 3 +- templates/postgres.12.template.yml | 3 +- templates/postgres.13.template.yml | 176 +++++++++++----------------- templates/postgres.15.template.yml | 33 +++--- templates/postgres.9.5.template.yml | 3 +- templates/postgres.template.yml | 91 ++++++++------ 8 files changed, 143 insertions(+), 169 deletions(-) diff --git a/image/base/Dockerfile b/image/base/Dockerfile index e9052ed66..acb5566cc 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -20,7 +20,7 @@ RUN /tmp/install-imagemagick FROM discourse/ruby:3.3.6-${DEBIAN_RELEASE}-slim AS discourse_dependencies ARG DEBIAN_RELEASE -ENV PG_MAJOR=13 \ +ENV PG_MAJOR=15 \ RUBY_ALLOCATOR=/usr/lib/libjemalloc.so \ LEFTHOOK=0 \ DEBIAN_RELEASE=${DEBIAN_RELEASE} diff --git a/launcher b/launcher index a8861696a..31dd4db11 100755 --- a/launcher +++ b/launcher @@ -92,6 +92,7 @@ kernel_min_version='4.4.0' config_file=containers/"$config".yml cidbootstrap=cids/"$config"_bootstrap.cid local_discourse=local_discourse +# TODO: replace base image before merging image="discourse/base:2.0.20250105-0017" docker_path=`which docker.io 2> /dev/null || which docker` git_path=`which git` diff --git a/templates/postgres.10.template.yml b/templates/postgres.10.template.yml index 89df40f47..07e7afb54 100644 --- a/templates/postgres.10.template.yml +++ b/templates/postgres.10.template.yml @@ -17,7 +17,7 @@ hooks: to: sv start postgres || exit 1 run: - - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-13 postgresql-client-13 postgresql-contrib-13 + - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-15 postgresql-client-15 postgresql-contrib-15 - exec: apt-get update && apt-get install -y postgresql-10 postgresql-client-10 postgresql-contrib-10 - exec: mkdir -p /shared/postgres_run - exec: chown postgres:postgres /shared/postgres_run @@ -141,6 +141,7 @@ run: - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"' + - exec: su postgres -c 'psql $db_name -c "create extension if not exists unaccent;"' - exec: stdin: | update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII'); diff --git a/templates/postgres.12.template.yml b/templates/postgres.12.template.yml index 4482c8acc..4ea46e858 100644 --- a/templates/postgres.12.template.yml +++ b/templates/postgres.12.template.yml @@ -17,7 +17,7 @@ hooks: to: sv start postgres || exit 1 run: - - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-13 postgresql-client-13 postgresql-contrib-13 + - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-15 postgresql-client-15 postgresql-contrib-15 - exec: apt-get update && apt-get install -y postgresql-12 postgresql-client-12 postgresql-contrib-12 - exec: mkdir -p /shared/postgres_run - exec: chown postgres:postgres /shared/postgres_run @@ -140,6 +140,7 @@ run: - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"' + - exec: su postgres -c 'psql $db_name -c "create extension if not exists unaccent;"' - exec: stdin: | update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII'); diff --git a/templates/postgres.13.template.yml b/templates/postgres.13.template.yml index c5d0814c0..2ec775f48 100644 --- a/templates/postgres.13.template.yml +++ b/templates/postgres.13.template.yml @@ -14,21 +14,16 @@ hooks: - replace: filename: /etc/service/unicorn/run from: "# postgres" - to: sv start postgres || exit 1 + to: | + if [ -f /root/install_postgres ]; then + /root/install_postgres + rm /root/install_postgres + fi + sv start postgres || exit 1 run: - - exec: sed -i "s/^# $LANG/$LANG/" /etc/locale.gen - - exec: locale-gen && update-locale - - exec: mkdir -p /shared/postgres_run - - exec: chown postgres:postgres /shared/postgres_run - - exec: chmod 775 /shared/postgres_run - - exec: rm -fr /var/run/postgresql - - exec: ln -s /shared/postgres_run /var/run/postgresql - - exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1 - - exec: rm -fr /shared/postgres_run/.s* - - exec: rm -fr /shared/postgres_run/*.pid - - exec: mkdir -p /shared/postgres_run/13-main.pg_stat_tmp - - exec: chown postgres:postgres /shared/postgres_run/13-main.pg_stat_tmp + - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-15 postgresql-client-15 postgresql-contrib-15 postgresql-15-pgvector + - exec: apt-get update && apt-get install -y postgresql-13 postgresql-client-13 postgresql-contrib-13 postgresql-13-pgvector - file: path: /etc/service/postgres/run chmod: "+x" @@ -53,79 +48,30 @@ run: sv stop postgres - file: - path: /root/upgrade_postgres - chmod: "+x" - contents: | - #!/bin/bash - PG_MAJOR_OLD=`cat /shared/postgres_data/PG_VERSION` - - if [ ! "13" = "$PG_MAJOR_OLD" ]; then - echo Upgrading PostgreSQL from version ${PG_MAJOR_OLD} to 13 - free_disk=$(df -P -B1 /shared | tail -n 1 | awk '{print $4}') - required=$(($(du -sb /shared/postgres_data | awk '{print $1}') * 2)) - - if [ "$free_disk" -lt "$required" ]; then - echo "WARNING: Upgrading PostgreSQL would require an additional $(numfmt --to=si $(($required - $free_disk))) of disk space" - echo "Please free up some space, or expand your disk, before continuing." - echo '' - echo 'To avoid upgrading change "templates/postgres.template.yml" TO "templates/postgres.12.template.yml" in containers/app.yml' - exit 1 - fi - - if [ -d /shared/postgres_data_old ]; then - mv /shared/postgres_data_old /shared/postgres_data_older - fi - - rm -fr /shared/postgres_data_new - install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data_new || exit 0 - apt-get update - apt-get install -y postgresql-${PG_MAJOR_OLD} - chown -R postgres:postgres /var/lib/postgresql/13 - /etc/init.d/postgresql stop - rm -fr /shared/postgres_data/postmaster.pid - cd ~postgres - cp -pr /etc/postgresql/${PG_MAJOR_OLD}/main/* /shared/postgres_data - echo >> /shared/postgres_data/postgresql.conf - echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf - SUCCESS=true - sudo -u postgres /usr/lib/postgresql/13/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/13/bin || SUCCESS=false - - if [[ "$SUCCESS" == 'false' ]]; then - echo ------------------------------------------------------------------------------------- - echo UPGRADE OF POSTGRES FAILED - echo - echo Please visit https://meta.discourse.org/t/postgresql-13-update/172563 for support. - echo - echo You can run "./launcher start app" to restart your app in the meanwhile - echo - exit 1 - fi - - mv /shared/postgres_data /shared/postgres_data_old - mv /shared/postgres_data_new /shared/postgres_data - - echo ------------------------------------------------------------------------------------- - echo UPGRADE OF POSTGRES COMPLETE - echo - echo Old ${PG_MAJOR_OLD} database is stored at /shared/postgres_data_old - echo - echo To complete the upgrade, rebuild again using: - echo - echo ./launcher rebuild app - echo ------------------------------------------------------------------------------------- - # Magic exit status to denote no failure - exit 77 - fi - - - exec: - cmd: - - chown -R root /var/lib/postgresql/13/main - - "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data || exit 0" - - chown -R postgres:postgres /shared/postgres_data - - chown -R postgres:postgres /var/run/postgresql - - - exec: /root/upgrade_postgres - - exec: rm /root/upgrade_postgres + path: /root/install_postgres + chmod: "+x" + contents: | + #!/bin/bash -x + sed -i "s/^# $LANG/$LANG/" /etc/locale.gen + locale-gen && update-locale + mkdir -p /shared/postgres_run + chown postgres:postgres /shared/postgres_run + chmod 775 /shared/postgres_run + rm -fr /var/run/postgresql + ln -s /shared/postgres_run /var/run/postgresql + if [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then + socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1 + fi + rm -fr /shared/postgres_run/.s* + rm -fr /shared/postgres_run/*.pid + mkdir -p /shared/postgres_run/13-main.pg_stat_tmp + chown postgres:postgres /shared/postgres_run/13-main.pg_stat_tmp + chown -R root /var/lib/postgresql/13/main + [ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data || exit 0 + chown -R postgres:postgres /shared/postgres_data + chown -R postgres:postgres /var/run/postgresql + # Necessary to enable backups + install -d -m 0755 -o postgres -g postgres /shared/postgres_backup - replace: filename: "/etc/postgresql/13/main/postgresql.conf" @@ -162,11 +108,6 @@ run: from: /#?default_text_search_config *=.*/ to: "default_text_search_config = '$db_default_text_search_config'" - # Necessary to enable backups - - exec: - cmd: - - install -d -m 0755 -o postgres -g postgres /shared/postgres_backup - - replace: filename: "/etc/postgresql/13/main/postgresql.conf" from: /#?checkpoint_segments *=.*/ @@ -200,29 +141,39 @@ run: to: "host all all ::/0 md5" - exec: + tag: db + cmd: | + if [ -f /root/install_postgres ]; then + /root/install_postgres && rm -f /root/install_postgres + elif [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then + socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1 + fi + + - exec: + tag: db background: true # use fast shutdown for pg stop_signal: INT cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main - # give db a few secs to start up - - exec: "sleep 5" - - - exec: su postgres -c 'createdb $db_name' || true - - exec: su postgres -c 'psql $db_name -c "create user $db_user;"' || true - - exec: su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true - - exec: su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"' - - exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"' - - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' - - exec: su postgres -c 'psql template1 -c "create extension if not exists vector;"' - - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"' - - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"' - - exec: su postgres -c 'psql $db_name -c "create extension if not exists vector;"' - - exec: - stdin: | - update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII'); - cmd: sudo -u postgres psql $db_name - raise_on_fail: false + - file: + path: /usr/local/bin/create_db + chmod: +x + contents: | + #!/bin/bash + su postgres -c 'createdb $db_name' || true + su postgres -c 'psql $db_name -c "create user $db_user;"' || true + su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true + su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"' + su postgres -c 'psql template1 -c "create extension if not exists hstore;"' + su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' + su postgres -c 'psql template1 -c "create extension if not exists vector;"' + su postgres -c 'psql template1 -c "alter extension vector update;"' || true + su postgres -c 'psql $db_name -c "create extension if not exists hstore;"' + su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"' + su postgres -c 'psql $db_name -c "create extension if not exists vector;"' + su postgres -c 'psql $db_name -c "alter extension vector update;"' || true + sudo -u postgres psql $db_name <<< "update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');" || true - file: path: /var/lib/postgresql/take-database-backup @@ -243,5 +194,10 @@ run: #0 */4 * * * /var/lib/postgresql/take-database-backup - exec: + tag: db hook: postgres - cmd: "echo postgres installed!" + cmd: + # give db a few secs to start up + - "sleep 5" + - /usr/local/bin/create_db + - "echo postgres installed!" diff --git a/templates/postgres.15.template.yml b/templates/postgres.15.template.yml index 548c575eb..83f1fc100 100644 --- a/templates/postgres.15.template.yml +++ b/templates/postgres.15.template.yml @@ -22,8 +22,6 @@ hooks: sv start postgres || exit 1 run: - - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-13 postgresql-client-13 postgresql-contrib-13 postgresql-13-pgvector - - exec: apt-get update && apt-get install -y postgresql-15 postgresql-client-15 postgresql-contrib-15 postgresql-15-pgvector - file: path: /etc/service/postgres/run chmod: "+x" @@ -67,10 +65,12 @@ run: mkdir -p /shared/postgres_run/15-main.pg_stat_tmp chown postgres:postgres /shared/postgres_run/15-main.pg_stat_tmp chown -R root /var/lib/postgresql/15/main - [ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/15/bin/initdb -D /shared/postgres_data || exit 0 - chown -R postgres:postgres /shared/postgres_data - chown -R postgres:postgres /var/run/postgresql - if [ -f /root/upgrade_postgres ]; then + if [ ! -e /shared/postgres_data ]; then + install -d -m 0755 -o postgres -g postgres /shared/postgres_data + sudo -E -u postgres /usr/lib/postgresql/15/bin/initdb -D /shared/postgres_data + chown -R postgres:postgres /shared/postgres_data + chown -R postgres:postgres /var/run/postgresql + elif [ -f /root/upgrade_postgres ]; then /root/upgrade_postgres rm /root/upgrade_postgres fi @@ -90,11 +90,13 @@ run: required=$(($(du -sb /shared/postgres_data | awk '{print $1}') * 2)) if [ "$free_disk" -lt "$required" ]; then - echo "WARNING: Upgrading PostgreSQL would require an additional $(numfmt --to=si $(($required - $free_disk))) of disk space" - echo "Please free up some space, or expand your disk, before continuing." - echo '' - echo 'To avoid upgrading change "templates/postgres.15.template.yml" TO "templates/postgres.template.yml" in containers/app.yml' - exit 1 + echo + echo "WARNING: Upgrading PostgreSQL would require an additional $(numfmt --to=si $(($required - $free_disk))) of disk space" + echo "Please free up some space, or expand your disk, before continuing." + echo + echo 'To avoid upgrading change "templates/postgres.template.yml" TO "templates/postgres.13.template.yml" in containers/app.yml' + echo 'You can run "./launcher start app" to restart your app in the meanwhile.' + exit 1 fi if [ -d /shared/postgres_data_old ]; then @@ -119,8 +121,11 @@ run: echo ------------------------------------------------------------------------------------- echo UPGRADE OF POSTGRES FAILED echo - echo You can run "./launcher start app" to restart your app in the meanwhile + # TODO: Change meta URL for PostgreSQL 15 topic + echo Please visit https://meta.discourse.org/t/postgresql-13-update/172563 for support. echo + echo You can run "./launcher start app" to restart your app in the meanwhile + echo ------------------------------------------------------------------------------------- exit 1 fi @@ -131,10 +136,6 @@ run: echo UPGRADE OF POSTGRES COMPLETE echo echo Old ${PG_MAJOR_OLD} database is stored at /shared/postgres_data_old - echo - echo To complete the upgrade, rebuild again using: - echo - echo ./launcher rebuild app echo ------------------------------------------------------------------------------------- # Magic exit status to denote no failure exit 77 diff --git a/templates/postgres.9.5.template.yml b/templates/postgres.9.5.template.yml index 9d627137a..282e1bfd5 100644 --- a/templates/postgres.9.5.template.yml +++ b/templates/postgres.9.5.template.yml @@ -17,7 +17,7 @@ hooks: to: sv start postgres || exit 1 run: - - exec: apt-get remove -y postgresql-10 postgresql-client-10 postgresql-contrib-10 + - exec: DEBIAN_FRONTEND=noninteractive apt-get purge -y postgresql-15 postgresql-client-15 postgresql-contrib-15 - exec: apt-get update && apt-get install -y postgresql-9.5 postgresql-client-9.5 postgresql-contrib-9.5 - exec: mkdir -p /shared/postgres_run - exec: chown postgres:postgres /shared/postgres_run @@ -141,6 +141,7 @@ run: - exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"' - exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"' + - exec: su postgres -c 'psql $db_name -c "create extension if not exists unaccent;"' - exec: stdin: | update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII'); diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 95001a0f1..83f1fc100 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -28,7 +28,7 @@ run: contents: | #!/bin/sh exec 2>&1 - HOME=/var/lib/postgresql USER=postgres exec thpoff chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main + HOME=/var/lib/postgresql USER=postgres exec thpoff chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main - file: path: /etc/service/postgres/log/run @@ -62,13 +62,15 @@ run: fi rm -fr /shared/postgres_run/.s* rm -fr /shared/postgres_run/*.pid - mkdir -p /shared/postgres_run/13-main.pg_stat_tmp - chown postgres:postgres /shared/postgres_run/13-main.pg_stat_tmp - chown -R root /var/lib/postgresql/13/main - [ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data || exit 0 - chown -R postgres:postgres /shared/postgres_data - chown -R postgres:postgres /var/run/postgresql - if [ -f /root/upgrade_postgres ]; then + mkdir -p /shared/postgres_run/15-main.pg_stat_tmp + chown postgres:postgres /shared/postgres_run/15-main.pg_stat_tmp + chown -R root /var/lib/postgresql/15/main + if [ ! -e /shared/postgres_data ]; then + install -d -m 0755 -o postgres -g postgres /shared/postgres_data + sudo -E -u postgres /usr/lib/postgresql/15/bin/initdb -D /shared/postgres_data + chown -R postgres:postgres /shared/postgres_data + chown -R postgres:postgres /var/run/postgresql + elif [ -f /root/upgrade_postgres ]; then /root/upgrade_postgres rm /root/upgrade_postgres fi @@ -82,17 +84,19 @@ run: #!/bin/bash PG_MAJOR_OLD=`cat /shared/postgres_data/PG_VERSION` - if [ ! "13" = "$PG_MAJOR_OLD" ]; then - echo Upgrading PostgreSQL from version ${PG_MAJOR_OLD} to 13 + if [ ! "15" = "$PG_MAJOR_OLD" ]; then + echo Upgrading PostgreSQL from version ${PG_MAJOR_OLD} to 15 free_disk=$(df -P -B1 /shared | tail -n 1 | awk '{print $4}') required=$(($(du -sb /shared/postgres_data | awk '{print $1}') * 2)) if [ "$free_disk" -lt "$required" ]; then - echo "WARNING: Upgrading PostgreSQL would require an additional $(numfmt --to=si $(($required - $free_disk))) of disk space" - echo "Please free up some space, or expand your disk, before continuing." - echo '' - echo 'To avoid upgrading change "templates/postgres.template.yml" TO "templates/postgres.12.template.yml" in containers/app.yml' - exit 1 + echo + echo "WARNING: Upgrading PostgreSQL would require an additional $(numfmt --to=si $(($required - $free_disk))) of disk space" + echo "Please free up some space, or expand your disk, before continuing." + echo + echo 'To avoid upgrading change "templates/postgres.template.yml" TO "templates/postgres.13.template.yml" in containers/app.yml' + echo 'You can run "./launcher start app" to restart your app in the meanwhile.' + exit 1 fi if [ -d /shared/postgres_data_old ]; then @@ -100,10 +104,10 @@ run: fi rm -fr /shared/postgres_data_new - install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data_new || exit 0 + install -d -m 0755 -o postgres -g postgres /shared/postgres_data_new && sudo -u postgres /usr/lib/postgresql/15/bin/initdb -D /shared/postgres_data_new || exit 0 apt-get update apt-get install -y postgresql-${PG_MAJOR_OLD} - chown -R postgres:postgres /var/lib/postgresql/13 + chown -R postgres:postgres /var/lib/postgresql/15 /etc/init.d/postgresql stop rm -fr /shared/postgres_data/postmaster.pid cd ~postgres @@ -111,16 +115,17 @@ run: echo >> /shared/postgres_data/postgresql.conf echo "data_directory = '/shared/postgres_data'" >> /shared/postgres_data/postgresql.conf SUCCESS=true - sudo -u postgres /usr/lib/postgresql/13/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/13/bin || SUCCESS=false + sudo -u postgres /usr/lib/postgresql/15/bin/pg_upgrade -d /shared/postgres_data -D /shared/postgres_data_new -b /usr/lib/postgresql/${PG_MAJOR_OLD}/bin -B /usr/lib/postgresql/15/bin || SUCCESS=false if [[ "$SUCCESS" == 'false' ]]; then echo ------------------------------------------------------------------------------------- echo UPGRADE OF POSTGRES FAILED echo + # TODO: Change meta URL for PostgreSQL 15 topic echo Please visit https://meta.discourse.org/t/postgresql-13-update/172563 for support. echo echo You can run "./launcher start app" to restart your app in the meanwhile - echo + echo ------------------------------------------------------------------------------------- exit 1 fi @@ -131,82 +136,90 @@ run: echo UPGRADE OF POSTGRES COMPLETE echo echo Old ${PG_MAJOR_OLD} database is stored at /shared/postgres_data_old - echo - echo To complete the upgrade, rebuild again using: - echo - echo ./launcher rebuild app echo ------------------------------------------------------------------------------------- # Magic exit status to denote no failure exit 77 fi - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" - from: "data_directory = '/var/lib/postgresql/13/main'" + filename: "/etc/postgresql/15/main/postgresql.conf" + from: "data_directory = '/var/lib/postgresql/15/main'" to: "data_directory = '/shared/postgres_data'" # listen on all interfaces - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?listen_addresses *=.*/ to: "listen_addresses = '*'" # sync commit off is faster and less spiky, also marginally less safe - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?synchronous_commit *=.*/ to: "synchronous_commit = $db_synchronous_commit" # default is 128MB which is way too small - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?shared_buffers *=.*/ to: "shared_buffers = $db_shared_buffers" # default is 1MB which is too small - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?work_mem *=.*/ to: "work_mem = $db_work_mem" # allow for other - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?default_text_search_config *=.*/ to: "default_text_search_config = '$db_default_text_search_config'" - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?checkpoint_segments *=.*/ to: "checkpoint_segments = $db_checkpoint_segments" - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?logging_collector *=.*/ to: "logging_collector = $db_logging_collector" - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?log_min_duration_statement *=.*/ to: "log_min_duration_statement = $db_log_min_duration_statement" - replace: - filename: "/etc/postgresql/13/main/pg_hba.conf" + filename: "/etc/postgresql/15/main/pg_hba.conf" from: /^#local +replication +postgres +peer$/ to: "local replication postgres peer" - # allow all to connect in with md5 auth + # allow all to connect in with md5/scram auth - replace: - filename: "/etc/postgresql/13/main/pg_hba.conf" + filename: "/etc/postgresql/15/main/pg_hba.conf" from: /^host.*all.*all.*127.*$/ to: "host all all 0.0.0.0/0 md5" - # allow all to connect in with md5 auth (IPv6) + # allow all to connect in with md5/scram auth (IPv6) - replace: - filename: "/etc/postgresql/13/main/pg_hba.conf" + filename: "/etc/postgresql/15/main/pg_hba.conf" from: /^host.*all.*all.*::1\/128.*$/ to: "host all all ::/0 md5" + # allow replication to connect in with md5/scram auth + - replace: + filename: "/etc/postgresql/15/main/pg_hba.conf" + from: /^host.*replication.*all.*127.*$/ + to: "host replication all 0.0.0.0/0 md5" + + # allow replication to connect in with md5/scram auth (IPv6) + - replace: + filename: "/etc/postgresql/15/main/pg_hba.conf" + from: /^host.*replication.*all.*::1\/128.*$/ + to: "host replication all ::/0 md5" + - exec: tag: db cmd: | @@ -221,7 +234,7 @@ run: background: true # use fast shutdown for pg stop_signal: INT - cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main + cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main - file: path: /usr/local/bin/create_db From 8ddd747a7f9e02f9fa45aa8fb4d69b26d374e117 Mon Sep 17 00:00:00 2001 From: Mwaniki Wairungu Date: Tue, 14 Jan 2025 10:27:07 +0300 Subject: [PATCH 2/3] FIX: bump dev image to postgresql 15 --- .gitignore | 1 + image/README.md | 2 +- image/discourse_dev/postgres_dev.template.yml | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4bf7db49b..95019dc32 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ image/squash.tar image/nsenter/nsenter image/docker-squash image/docker-squash.tar.gz +image/discourse_dev/install-rust image/discourse_dev/postgres.template.yml image/discourse_dev/redis.template.yml .gc-state/* diff --git a/image/README.md b/image/README.md index d29158837..c3b665254 100644 --- a/image/README.md +++ b/image/README.md @@ -4,7 +4,7 @@ To build a new image, just run `ruby auto_build.rb image-name`. The build process will build a local image with a predefined tag. -Images and tag names are defined [here](https://github.com/discourse/discourse_docker/blob/master/image/auto_build.rb#L6-L11). +Images and tag names are defined [here](https://github.com/discourse/discourse_docker/blob/main/image/auto_build.rb#L6-L88). > **A note about --squash**: By default we squash the images we serve on Docker Hub. You will need to [enable experimental features](https://github.com/docker/docker-ce/blob/master/components/cli/experimental/README.md) on your Docker daemon for that. diff --git a/image/discourse_dev/postgres_dev.template.yml b/image/discourse_dev/postgres_dev.template.yml index 6c84045fa..5208bc1de 100644 --- a/image/discourse_dev/postgres_dev.template.yml +++ b/image/discourse_dev/postgres_dev.template.yml @@ -1,12 +1,12 @@ run: - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" - from: /#?fullpage_writes *=.*/ - to: "fullpage_writes = off" + filename: "/etc/postgresql/15/main/postgresql.conf" + from: /#?full_page_writes *=.*/ + to: "full_page_writes = off" - replace: - filename: "/etc/postgresql/13/main/postgresql.conf" + filename: "/etc/postgresql/15/main/postgresql.conf" from: /#?fsync *=.*/ to: "fsync = off" @@ -14,7 +14,7 @@ run: background: true # use fast shutdown for pg stop_signal: INT - cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main + cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/15/bin/postmaster -D /etc/postgresql/15/main - exec: background: true From 7d34842e561c3cdafc6ed697b3feee84855e4e2f Mon Sep 17 00:00:00 2001 From: Mwaniki Wairungu Date: Tue, 14 Jan 2025 10:50:33 +0300 Subject: [PATCH 3/3] FIX: remove unsupported replication configs --- templates/postgres.15.template.yml | 12 ------------ templates/postgres.template.yml | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/templates/postgres.15.template.yml b/templates/postgres.15.template.yml index 83f1fc100..04b86aa10 100644 --- a/templates/postgres.15.template.yml +++ b/templates/postgres.15.template.yml @@ -208,18 +208,6 @@ run: from: /^host.*all.*all.*::1\/128.*$/ to: "host all all ::/0 md5" - # allow replication to connect in with md5/scram auth - - replace: - filename: "/etc/postgresql/15/main/pg_hba.conf" - from: /^host.*replication.*all.*127.*$/ - to: "host replication all 0.0.0.0/0 md5" - - # allow replication to connect in with md5/scram auth (IPv6) - - replace: - filename: "/etc/postgresql/15/main/pg_hba.conf" - from: /^host.*replication.*all.*::1\/128.*$/ - to: "host replication all ::/0 md5" - - exec: tag: db cmd: | diff --git a/templates/postgres.template.yml b/templates/postgres.template.yml index 83f1fc100..04b86aa10 100644 --- a/templates/postgres.template.yml +++ b/templates/postgres.template.yml @@ -208,18 +208,6 @@ run: from: /^host.*all.*all.*::1\/128.*$/ to: "host all all ::/0 md5" - # allow replication to connect in with md5/scram auth - - replace: - filename: "/etc/postgresql/15/main/pg_hba.conf" - from: /^host.*replication.*all.*127.*$/ - to: "host replication all 0.0.0.0/0 md5" - - # allow replication to connect in with md5/scram auth (IPv6) - - replace: - filename: "/etc/postgresql/15/main/pg_hba.conf" - from: /^host.*replication.*all.*::1\/128.*$/ - to: "host replication all ::/0 md5" - - exec: tag: db cmd: |