mirror of
https://git.koehn.com/docker/postgres-wal-g.git
synced 2026-11-24 09:36:38 -06:00
Compare commits
14
Commits
16.1-v2.0.1-1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
653ab7a387 | ||
|
|
d6f4953452 | ||
|
|
05c907dcee | ||
|
|
a8212acfb5 | ||
|
|
14d15c287e | ||
|
|
fb913a8062 | ||
|
|
52888bd104 | ||
|
|
a437ca53f4 | ||
|
|
8669c7e663 | ||
|
|
fc63329212 | ||
|
|
9ca1e4b2c0 | ||
|
|
e33df13659 | ||
|
|
42be7c5361 | ||
|
|
caa0e988b1 |
No files matched your search
@@ -42,4 +42,4 @@ jobs:
|
||||
WAL_G=${{ steps.versions.outputs.walg }}
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: git.koehn.com/docker/postgres-wal-g:${{ gitea.ref.name }}
|
||||
tags: git.koehn.com/docker/postgres-wal-g:${{ gitea.ref_name }}
|
||||
+3
-2
@@ -1,13 +1,14 @@
|
||||
ARG BASE=latest
|
||||
|
||||
FROM golang:1 as build
|
||||
FROM golang:1-bookworm AS build
|
||||
|
||||
ARG WALG_RELEASE=master
|
||||
|
||||
RUN apt-get update && apt-get install -qqy --no-install-recommends --no-install-suggests cmake liblzo2-dev libsodium23 libsodium-dev && \
|
||||
RUN apt-get update && apt-get install -qqy --no-install-recommends --no-install-suggests cmake gnutls-bin liblzo2-dev libsodium23 libsodium-dev && \
|
||||
cd /go/src/ && \
|
||||
git clone -b $WALG_RELEASE --recurse-submodules https://github.com/wal-g/wal-g.git && \
|
||||
cd wal-g && \
|
||||
GOBIN=/go/bin go mod tidy && \
|
||||
GOBIN=/go/bin USE_LIBSODIUM=1 USE_LZO=1 make install_and_build_pg
|
||||
|
||||
|
||||
|
||||
@@ -1,48 +1,55 @@
|
||||
# Postgres WAL-G
|
||||
|
||||
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
|
||||
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
|
||||
helpful scripts. It allows you to simply and easily create continuous, encrypted
|
||||
archives of Postgres databases in S3-compatible storage.
|
||||
|
||||
## Environment
|
||||
To use the image, you'll need to configure a bucket on your favorite S3-
|
||||
compatible provider, and set a few environment variables:
|
||||
|
||||
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
|
||||
to your bucket
|
||||
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
|
||||
[WAL-G documentation](https://github.com/wal-g/wal-g/blob/master/docs/PostgreSQL.md) for details)
|
||||
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
|
||||
* `WALG_LIBSODIUM_KEY` to encrypt the files stored in S3
|
||||
|
||||
## Configuration
|
||||
In your `/var/lib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
|
||||
settings](https://www.postgresql.org/docs/current/continuous-archiving.html).
|
||||
Importantly, you should set `archive_mode = on` and
|
||||
`archive_command = 'wal-g wal-push %p'`. This will
|
||||
tell Postgres to have WAL-G send WAL files to S3.
|
||||
|
||||
## Full Backups
|
||||
To run a full backup, simply run `/wal-g/backup.sh`.
|
||||
|
||||
## Continuous Backups
|
||||
These will happen automatically once you've started Postgres with your edited
|
||||
`postgresql.conf` file (see
|
||||
[Configuration](#configuration), above).
|
||||
|
||||
## Recovery
|
||||
Testing recovery is simple: run a new Docker container with the correct
|
||||
environment variables set and run `/wal-g/recover.sh`. It will:
|
||||
1. Recover from the most recent full backup
|
||||
2. Configure Postgres to not accept incoming connections or perform streaming
|
||||
backups until the recovery is complete (important for testing!)
|
||||
3. Configure Postgres to apply all the WAL files
|
||||
4. Shut down Postgres, re-enable incoming connections and streaming backups
|
||||
|
||||
At this point you should have high confidence that the recovery was successful.
|
||||
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
|
||||
pushing additional WAL files to S3!
|
||||
|
||||
## Postgres Versions
|
||||
Currently I build for Postgres 15, but you can build for whatever version that wal-g supports.
|
||||
# Postgres WAL-G
|
||||
|
||||
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
|
||||
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
|
||||
helpful scripts. It allows you to simply and easily create continuous, encrypted
|
||||
archives of Postgres databases in S3-compatible storage.
|
||||
|
||||
## Environment
|
||||
To use the image, you'll need to configure a bucket on your favorite S3-
|
||||
compatible provider, and set a few environment variables:
|
||||
|
||||
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
|
||||
to your bucket
|
||||
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
|
||||
[WAL-G documentation](https://github.com/wal-g/wal-g/blob/master/docs/PostgreSQL.md) for details)
|
||||
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
|
||||
* `WALG_LIBSODIUM_KEY` to encrypt the files stored in S3
|
||||
|
||||
## Configuration
|
||||
In your `/var/lib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
|
||||
settings](https://www.postgresql.org/docs/current/continuous-archiving.html).
|
||||
Importantly, you should set `archive_mode = on` and
|
||||
`archive_command = 'wal-g wal-push %p'`. This will
|
||||
tell Postgres to have WAL-G send WAL files to S3.
|
||||
|
||||
## Full Backups
|
||||
To run a full backup, simply run `/wal-g/backup.sh`.
|
||||
|
||||
## Continuous Backups
|
||||
These will happen automatically once you've started Postgres with your edited
|
||||
`postgresql.conf` file (see
|
||||
[Configuration](#configuration), above).
|
||||
|
||||
## Recovery
|
||||
Testing recovery is simple: run a new Docker container with the correct
|
||||
environment variables set and run `/wal-g/recover.sh`. It will:
|
||||
1. Recover from the most recent full backup
|
||||
2. Configure Postgres to not accept incoming connections or perform streaming
|
||||
backups until the recovery is complete (important for testing!)
|
||||
3. Configure Postgres to apply all the WAL files
|
||||
4. Shut down Postgres, re-enable incoming connections and streaming backups
|
||||
|
||||
At this point you should have high confidence that the recovery was successful.
|
||||
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
|
||||
pushing additional WAL files to S3!
|
||||
|
||||
## Postgres Versions
|
||||
Currently I build for Postgres 16, but you can build for whatever version that wal-g supports.
|
||||
|
||||
## Kubernetes Deployments and Justfile
|
||||
For an example of how to use this in Kubernetes (I happen to use k3s), you can check
|
||||
out my deployment of this image [here](https://git.koehn.com/k3s-home/postgres).
|
||||
|
||||
That link also contains a `justfile` that has some useful recipes for creating
|
||||
database, creating backups, testing backups, verifying backups, etc.
|
||||
@@ -12,7 +12,7 @@ IMAGE_NAME=koehn/postgres-wal-g
|
||||
build_image() {
|
||||
BASE=$1
|
||||
IMAGE=$IMAGE_NAME:$BASE-$WALG_VERSION
|
||||
docker buildx build -t $IMAGE --push . --build-arg BASE=$PG_VERSION --build-arg WALG_RELEASE=$WALG_VERSION --ulimit memlock=16384:16384 --platform linux/amd64,linux/arm64 --builder multiarch
|
||||
docker buildx build -t $IMAGE --push . --build-arg BASE=$PG_VERSION --build-arg WALG_RELEASE=$WALG_VERSION --ulimit memlock=16384:16384 --platform linux/amd64,linux/arm64 --sbom=true --provenance=true
|
||||
}
|
||||
|
||||
build_image "$PG_VERSION" "$WALG_VERSION"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
||||
+22
-4
@@ -9,17 +9,29 @@
|
||||
# * 4. Disabling archive mode so as not to corrupt S3 backups
|
||||
# * Starts postgres
|
||||
#
|
||||
# When recovery is done, hit ^C and start database using `/docker-entrypoint.sh postgres` and you should be able to connect to the database and verify backups are OK.
|
||||
# If you get an error message, DON'T PANIC! Just read the message and do what it tells you to do.
|
||||
|
||||
if [ $(id -u) == "0" ] ; then
|
||||
echo "this command must be run as the postgres user."
|
||||
[ -z ${AWS_ACCESS_KEY_ID+x} ] && VARS="$VARS AWS_ACCESS_KEY_ID"
|
||||
[ -z ${AWS_SECRET_ACCESS_KEY+x} ] && VARS="$VARS AWS_SECRET_ACCESS_KEY"
|
||||
[ -z ${AWS_ENDPOINT+x} ] && VARS="$VARS AWS_ENDPOINT"
|
||||
[ -z ${AWS_REGION+x} ] && VARS="$VARS AWS_REGION"
|
||||
[ -z ${WALG_S3_PREFIX+x} ] && VARS="$VARS WALG_S3_PREFIX"
|
||||
[ -z ${WALG_LIBSODIUM_KEY+x} ] && VARS="$VARS WALG_LIBSODIUM_KEY"
|
||||
|
||||
if [ ! -z "$VARS" ] ; then
|
||||
echo "The following enviornment variables must be set:$VARS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -e
|
||||
if [ $(id -u) == "0" ] ; then
|
||||
echo "this command must be run as the postgres user (\`su postgres\`)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ -z ${PGDATA+x} ]; then
|
||||
echo "Setting PGDATA to /var/lib/postgresql/data/pgsql"
|
||||
export PGDATA=/var/lib/postgresql/data/pgsql
|
||||
fi
|
||||
|
||||
@@ -37,3 +49,9 @@ sed -i -e 's/^archive_mode = on/archive_mode = off/' $PGDATA/postgresql.conf
|
||||
PG_VERSION=$(ls /usr/lib/postgresql/)
|
||||
|
||||
/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl start -D $PGDATA
|
||||
|
||||
echo "Recovery complete. Press <return> to continue."
|
||||
echo "If this is a production recovery, simply restart the container."
|
||||
echo ""
|
||||
echo "To test the database, disable \`archive_mode\` in $PGDATA/postgresql.conf or you risk "
|
||||
echo "corrupting backups of the production instance. Then run \`postgres start\` to start the instance in test mode."
|
||||
Reference in new issue
Block a user