From f73d28d3910a30b388f39552059c5406dbf47ffb Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Sun, 29 Sep 2024 21:51:23 +0200 Subject: [PATCH] feat: Upgrade to postgres 16.4 --- Dockerfile | 2 +- Dockerfile.upgrade | 2 +- README.md | 32 ++++++++++++++++---------------- scripts/postgres-install | 6 ++++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 592f364..13a82d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ ENV PATH="$PATH:/usr/lib/postgresql/16/bin:/scripts" ENV WALG_CONFIG_FILE=/var/lib/postgresql/.walg.json ENV LANG en_US.utf8 -COPY --from=postgres:16 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY --from=postgres:16.4 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh ADD ./scripts /scripts STOPSIGNAL SIGINT diff --git a/Dockerfile.upgrade b/Dockerfile.upgrade index 1d49900..744e8a4 100644 --- a/Dockerfile.upgrade +++ b/Dockerfile.upgrade @@ -1,4 +1,4 @@ -FROM livingdocs/postgres:16.2 +FROM livingdocs/postgres:16.4 USER root RUN set -e \ export DEBIAN_FRONTEND=noninteractive && \ diff --git a/README.md b/README.md index e645ac8..0601a60 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [Postgres 16.2](https://github.com/livingdocsIO/dockerfile-postgres) [![](https://img.shields.io/badge/docker-livingdocs%2Fpostgres-blue)](https://hub.docker.com/r/livingdocs/postgres) +# [Postgres 16.4](https://github.com/livingdocsIO/dockerfile-postgres) [![](https://img.shields.io/badge/docker-livingdocs%2Fpostgres-blue)](https://hub.docker.com/r/livingdocs/postgres) - Based on Debian - Includes `postgres-contrib`, enables the extensions `pg_stat_statements` by default @@ -13,7 +13,7 @@ ```bash # Secured with a password, by default the image is secure -docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql -e POSTGRES_PASSWORD=somepassword livingdocs/postgres:16.2 +docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql -e POSTGRES_PASSWORD=somepassword livingdocs/postgres:16.4 ``` ## Upgrade an existing postgres container @@ -24,33 +24,33 @@ docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql livin # First stop it, then run the upgrade image docker stop postgres -docker run --rm -v postgres:/var/lib/postgresql livingdocs/postgres:16.2-upgrade +docker run --rm -v postgres:/var/lib/postgresql livingdocs/postgres:16.4-upgrade # After it succeeds, you can run the new image and mount the existing volume -docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql livingdocs/postgres:16.2 +docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql livingdocs/postgres:16.4 ``` ## To build this image manually ```bash -docker build -t livingdocs/postgres:16.2 . +docker build -t livingdocs/postgres:16.4 . ``` With buildx on docker ```bash # To build and push the multi-arch manifest to docker hub -docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:16.2 --push . +docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:16.4 --push . -docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:16.2-upgrade --push -f Dockerfile.upgrade . +docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:16.4-upgrade --push -f Dockerfile.upgrade . ``` With nerdctl on lima/containerd ```bash -nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:16.2 . -nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:16.2-upgrade -f Dockerfile.upgrade . +nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:16.4 . +nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:16.4-upgrade -f Dockerfile.upgrade . -lima nerdctl push --all-platforms livingdocs/postgres:16.2 -lima nerdctl push --all-platforms livingdocs/postgres:16.2-upgrade +lima nerdctl push --all-platforms livingdocs/postgres:16.4 +lima nerdctl push --all-platforms livingdocs/postgres:16.4-upgrade ``` ## Set up streaming replication @@ -58,8 +58,8 @@ lima nerdctl push --all-platforms livingdocs/postgres:16.2-upgrade ### Simple setup ```bash # Create the containers -docker run -d -p 5433:5432 --name postgres-1 livingdocs/postgres:16.2 -docker run -d -p 5434:5432 --name postgres-2 livingdocs/postgres:16.2 standby -d "host=host.docker.internal port=5433 user=postgres target_session_attrs=read-write" +docker run -d -p 5433:5432 --name postgres-1 livingdocs/postgres:16.4 +docker run -d -p 5434:5432 --name postgres-2 livingdocs/postgres:16.4 standby -d "host=host.docker.internal port=5433 user=postgres target_session_attrs=read-write" # Test the replication docker exec postgres-1 psql -c "CREATE TABLE hello (value text); INSERT INTO hello(value) VALUES('world');" @@ -77,7 +77,7 @@ docker exec postgres-2 psql -c "SELECT * FROM hello;" docker network create local # First create the database primary -docker run -d -p 5433:5432 --name postgres-1 --network=local --network-alias=postgres -e POSTGRES_HOST_AUTH_METHOD=md5 livingdocs/postgres:16.2 +docker run -d -p 5433:5432 --name postgres-1 --network=local --network-alias=postgres -e POSTGRES_HOST_AUTH_METHOD=md5 livingdocs/postgres:16.4 # Create the users on database intialization # You could also mount an sql or script into /var/lib/postgresql/initdb.d during cluster startup to execute the script automatically. @@ -86,8 +86,8 @@ docker exec postgres-1 psql -c "CREATE USER replication REPLICATION LOGIN ENCRYP # The launch the replicas export DB_URL="host=postgres port=5432 user=replication password=some-replication-password target_session_attrs=read-write" -docker run -d -p 5434:5432 --name postgres-2 --network=local --network-alias=postgres livingdocs/postgres:16.2 standby -d $DB_URL -docker run -d -p 5435:5432 --name postgres-3 --network=local --network-alias=postgres livingdocs/postgres:16.2 standby -d $DB_URL +docker run -d -p 5434:5432 --name postgres-2 --network=local --network-alias=postgres livingdocs/postgres:16.4 standby -d $DB_URL +docker run -d -p 5435:5432 --name postgres-3 --network=local --network-alias=postgres livingdocs/postgres:16.4 standby -d $DB_URL # Test the replication docker exec postgres-1 psql -c "CREATE TABLE hello (value text); INSERT INTO hello(value) VALUES('hello');" diff --git a/scripts/postgres-install b/scripts/postgres-install index cfecd47..e2ca480 100755 --- a/scripts/postgres-install +++ b/scripts/postgres-install @@ -19,13 +19,15 @@ curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /e apt-get update apt-get install -y --no-install-recommends postgresql-common sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf -apt-get install -y --no-install-recommends "postgresql-16=16.2-1.pgdg120+2" +apt-get install -y --no-install-recommends "postgresql-16=16.4-1.pgdg120+2" >&2 echo 'Install pg_auto_failover' apt-get install -y --no-install-recommends pg-auto-failover-cli postgresql-16-auto-failover >&2 echo 'Install wal-g' -curl -s -L https://github.com/wal-g/wal-g/releases/download/v2.0.1/wal-g-pg-ubuntu-18.04-amd64 > /usr/local/bin/wal-g +archfile=wal-g-fdb-ubuntu-20.04-amd64 +if [ "$(uname -m)" == "aarch64" ]; then archfile=wal-g-fdb-ubuntu20.04-aarch64; fi +curl -s -L "https://github.com/wal-g/wal-g/releases/download/v3.0.3/$archfile" > /usr/local/bin/wal-g chmod +x /usr/local/bin/wal-g # We need to have locales enabled for postgres grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker || sed -ri '/\/usr\/share\/locale/d' /etc/dpkg/dpkg.cfg.d/docker