Skip to content

Commit

Permalink
feat: Upgrade to postgres 16.4
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Sep 29, 2024
1 parent 878c5ac commit f73d28d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.upgrade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM livingdocs/postgres:16.2
FROM livingdocs/postgres:16.4
USER root
RUN set -e \
export DEBIAN_FRONTEND=noninteractive && \
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -24,42 +24,42 @@ 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

### 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');"
Expand All @@ -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.
Expand All @@ -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');"
Expand Down
6 changes: 4 additions & 2 deletions scripts/postgres-install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f73d28d

Please sign in to comment.