Skip to content

Commit 688278e

Browse files
committed
feat: Upgrade to postgres 18, remove autofailover as that's not yet supported
1 parent 70b6853 commit 688278e

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ ADD ./scripts /scripts
1313
RUN /scripts/postgres-install && rm /scripts/postgres-install
1414

1515
USER postgres
16-
ENV PG_MAJOR=17
16+
ENV PG_MAJOR=18
1717
ENV PGUSER=postgres
1818
ENV PGHOST /var/run/postgresql
1919
ENV PGPORT 5432
2020
ENV PGDATA /var/lib/postgresql/data
2121
ENV PAGER 'pspg -s 0'
22-
ENV PATH="$PATH:/usr/lib/postgresql/17/bin:/scripts"
22+
ENV PATH="$PATH:/usr/lib/postgresql/18/bin:/scripts"
2323
ENV WALG_CONFIG_FILE=/var/lib/postgresql/.walg.json
2424
ENV LANG en_US.utf8
2525

26-
COPY --from=postgres:17.2 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
26+
COPY --from=postgres:18.0 /usr/local/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
2727
ADD ./scripts /scripts
2828

2929
STOPSIGNAL SIGINT

Dockerfile.upgrade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM livingdocs/postgres:17.2
1+
FROM livingdocs/postgres:18.0
22
USER root
33
RUN set -e \
44
export DEBIAN_FRONTEND=noninteractive && \
5-
apt-get update && apt-get install -y git build-essential postgresql-13 postgresql-14 postgresql-15 postgresql-16 && \
5+
apt-get update && apt-get install -y git build-essential postgresql-13 postgresql-14 postgresql-15 postgresql-16 postgresql-17 && \
66
# Cleanup
7-
apt-get purge -y --auto-remove apt-transport-https git postgresql-server-dev-13 postgresql-server-dev-14 postgresql-server-dev-15 postgresql-server-dev-16 build-essential && \
7+
apt-get purge -y --auto-remove apt-transport-https git postgresql-server-dev-13 postgresql-server-dev-14 postgresql-server-dev-15 postgresql-server-dev-16 postgresql-server-dev-17 build-essential && \
88
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/log/*
99

1010
STOPSIGNAL SIGINT

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# [Postgres 17.2](https://github.com/livingdocsIO/dockerfile-postgres) [![](https://img.shields.io/badge/docker-livingdocs%2Fpostgres-blue)](https://hub.docker.com/r/livingdocs/postgres)
1+
# [Postgres 18.0](https://github.com/livingdocsIO/dockerfile-postgres) [![](https://img.shields.io/badge/docker-livingdocs%2Fpostgres-blue)](https://hub.docker.com/r/livingdocs/postgres)
22

33
- Based on Debian
44
- Includes `postgres-contrib`, enables the extensions `pg_stat_statements` by default
55
- Includes [wal-g](https://github.com/wal-g/wal-g) for WAL archiving and shipping
6-
- Includes [pg_auto_failover](https://github.com/citusdata/pg_auto_failover) for automatic failover
76
- Runs as postgres user with uid (1000), gid (1000)
87
- Does not try to fix permissions during boot to support a fast startup
98
- Does not have Dockerfile VOLUME declarations and therefore no issues with pg_upgrade --link
@@ -13,7 +12,7 @@
1312

1413
```bash
1514
# Secured with a password, by default the image is secure
16-
docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql -e POSTGRES_PASSWORD=somepassword livingdocs/postgres:17.2
15+
docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql -e POSTGRES_PASSWORD=somepassword livingdocs/postgres:18.0
1716
```
1817

1918
## Upgrade an existing postgres container
@@ -24,42 +23,42 @@ docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql livin
2423

2524
# First stop it, then run the upgrade image
2625
docker stop postgres
27-
docker run --rm -v postgres:/var/lib/postgresql livingdocs/postgres:17.2-upgrade
26+
docker run --rm -v postgres:/var/lib/postgresql -v postgres-socket:/var/run/postgresql livingdocs/postgres:18.0-upgrade
2827

2928
# After it succeeds, you can run the new image and mount the existing volume
30-
docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql livingdocs/postgres:17.2
29+
docker run -d --name postgres -p 5432:5432 -v postgres:/var/lib/postgresql -v postgres-socket:/var/run/postgresql livingdocs/postgres:18.0
3130
```
3231

3332
## To build this image manually
3433

3534
```bash
36-
docker build -t livingdocs/postgres:17.2 .
35+
docker build -t livingdocs/postgres:18.0 .
3736
```
3837

3938
With buildx on docker
4039
```bash
4140
# To build and push the multi-arch manifest to docker hub
42-
docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:17.2 --push .
41+
docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:18.0 --push .
4342

44-
docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:17.2-upgrade --push -f Dockerfile.upgrade .
43+
docker buildx build --platform linux/amd64,linux/arm64 -t livingdocs/postgres:18.0-upgrade --push -f Dockerfile.upgrade .
4544
```
4645

4746
With nerdctl on lima/containerd
4847
```bash
49-
nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:17.2 .
50-
nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:17.2-upgrade -f Dockerfile.upgrade .
48+
nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:18.0 .
49+
nerdctl build --platform=amd64,arm64 -t livingdocs/postgres:18.0-upgrade -f Dockerfile.upgrade .
5150

52-
lima nerdctl push --all-platforms livingdocs/postgres:17.2
53-
lima nerdctl push --all-platforms livingdocs/postgres:17.2-upgrade
51+
lima nerdctl push --all-platforms livingdocs/postgres:18.0
52+
lima nerdctl push --all-platforms livingdocs/postgres:18.0-upgrade
5453
```
5554

5655
## Set up streaming replication
5756

5857
### Simple setup
5958
```bash
6059
# Create the containers
61-
docker run -d -p 5433:5432 --name postgres-1 livingdocs/postgres:17.2
62-
docker run -d -p 5434:5432 --name postgres-2 livingdocs/postgres:17.2 standby -d "host=host.docker.internal port=5433 user=postgres target_session_attrs=read-write"
60+
docker run -d -p 5433:5432 --name postgres-1 livingdocs/postgres:18.0
61+
docker run -d -p 5434:5432 --name postgres-2 livingdocs/postgres:18.0 standby -d "host=host.docker.internal port=5433 user=postgres target_session_attrs=read-write"
6362

6463
# Test the replication
6564
docker exec postgres-1 psql -c "CREATE TABLE hello (value text); INSERT INTO hello(value) VALUES('world');"
@@ -77,7 +76,7 @@ docker exec postgres-2 psql -c "SELECT * FROM hello;"
7776
docker network create local
7877

7978
# First create the database primary
80-
docker run -d -p 5433:5432 --name postgres-1 --network=local --network-alias=postgres -e POSTGRES_HOST_AUTH_METHOD=md5 livingdocs/postgres:17.2
79+
docker run -d -p 5433:5432 --name postgres-1 --network=local --network-alias=postgres -e POSTGRES_HOST_AUTH_METHOD=md5 livingdocs/postgres:18.0
8180

8281
# Create the users on database intialization
8382
# You could also mount an sql or script into /var/lib/postgresql/initdb.d during cluster startup to execute the script automatically.
@@ -86,8 +85,8 @@ docker exec postgres-1 psql -c "CREATE USER replication REPLICATION LOGIN ENCRYP
8685

8786
# The launch the replicas
8887
export DB_URL="host=postgres port=5432 user=replication password=some-replication-password target_session_attrs=read-write"
89-
docker run -d -p 5434:5432 --name postgres-2 --network=local --network-alias=postgres livingdocs/postgres:17.2 standby -d $DB_URL
90-
docker run -d -p 5435:5432 --name postgres-3 --network=local --network-alias=postgres livingdocs/postgres:17.2 standby -d $DB_URL
88+
docker run -d -p 5434:5432 --name postgres-2 --network=local --network-alias=postgres livingdocs/postgres:18.0 standby -d $DB_URL
89+
docker run -d -p 5435:5432 --name postgres-3 --network=local --network-alias=postgres livingdocs/postgres:18.0 standby -d $DB_URL
9190

9291
# Test the replication
9392
docker exec postgres-1 psql -c "CREATE TABLE hello (value text); INSERT INTO hello(value) VALUES('hello');"

scripts/postgres-install

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@ chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql
1313
apt-get install -y --no-install-recommends curl nano pspg procps gosu dnsutils gnupg git ca-certificates
1414

1515
>&2 echo "Install Postgres"
16-
echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main 17" > /etc/apt/sources.list.d/pgdg.list
16+
echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main 18" > /etc/apt/sources.list.d/pgdg.list
1717
curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/pgdg.gpg
1818

1919
apt-get update
2020
apt-get install -y --no-install-recommends postgresql-common
2121
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf
22-
apt-get install -y --no-install-recommends "postgresql-17=17.2-1.pgdg120+1"
23-
24-
>&2 echo 'Install pg_auto_failover'
25-
apt-get install -y --no-install-recommends pg-auto-failover-cli postgresql-17-auto-failover
22+
apt-get install -y --no-install-recommends "postgresql-18"
2623

2724
>&2 echo 'Install wal-g'
2825
archfile=wal-g-fdb-ubuntu-20.04-amd64
2926
if [ "$(uname -m)" == "aarch64" ]; then archfile=wal-g-fdb-ubuntu20.04-aarch64; fi
30-
curl -s -L "https://github.com/wal-g/wal-g/releases/download/v3.0.3/$archfile" > /usr/local/bin/wal-g
27+
curl -s -L "https://github.com/wal-g/wal-g/releases/download/v3.0.7/$archfile" > /usr/local/bin/wal-g
3128
chmod +x /usr/local/bin/wal-g
3229
# We need to have locales enabled for postgres
3330
grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker || sed -ri '/\/usr\/share\/locale/d' /etc/dpkg/dpkg.cfg.d/docker

scripts/upgrade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ if [ -d "$PGDATANEW" ]; then
5959
fi
6060

6161
if [ "$(id -u)" != "1000" ] ; then
62+
gosu postgres:postgres $PGBINOLD/pg_checksums -e
6263
PGDATA="$PGDATANEW" gosu postgres:postgres $PGBINNEW/initdb
6364
PGDATA="$PGDATANEW" gosu postgres:postgres /scripts/tuneconfig
6465
gosu postgres:postgres pg_upgrade --link -j $(getconf _NPROCESSORS_ONLN)
6566
else
67+
$PGBINOLD/pg_checksums -e
6668
PGDATA="$PGDATANEW" $PGBINNEW/initdb
6769
PGDATA="$PGDATANEW" /scripts/tuneconfig
6870
pg_upgrade --link -j $(getconf _NPROCESSORS_ONLN)

0 commit comments

Comments
 (0)