This repository provides Docker images that automatically upgrade PostgreSQL data directories to newer versions. The images support upgrading from PostgreSQL 14, 15, or 16 to versions 15, 16, or 17.
The images are published to GitHub Container Registry with the following tags:
ghcr.io/flanksource/postgres-upgrade:to-15
- Upgrades to PostgreSQL 15ghcr.io/flanksource/postgres-upgrade:to-16
- Upgrades to PostgreSQL 16ghcr.io/flanksource/postgres-upgrade:to-17
- Upgrades to PostgreSQL 17
- The container automatically detects the PostgreSQL version in the mounted data directory
- It performs sequential upgrades if needed (e.g., 14→15→16→17)
- The upgrade uses
pg_upgrade
with hard links for efficiency - Original data is preserved with
.old
suffix on control files
To upgrade a PostgreSQL data directory:
docker run --rm \
-v /path/to/your/pgdata:/var/lib/postgresql/data \
ghcr.io/flanksource/postgres-upgrade:to-17
version: '3.8'
services:
postgres-upgrade:
image: ghcr.io/flanksource/postgres-upgrade:to-17
volumes:
- postgres_data:/var/lib/postgresql/data
profiles:
- upgrade
volumes:
postgres_data:
Run the upgrade with:
docker-compose run --rm postgres-upgrade
apiVersion: batch/v1
kind: Job
metadata:
name: postgres-upgrade-to-17
spec:
template:
spec:
restartPolicy: Never
containers:
- name: upgrade
image: ghcr.io/flanksource/postgres-upgrade:to-17
volumeMounts:
- name: postgres-data
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-data
persistentVolumeClaim:
claimName: postgres-pvc
From Version | To Version 15 | To Version 16 | To Version 17 |
---|---|---|---|
PostgreSQL 14 | ✅ | ✅ | ✅ |
PostgreSQL 15 | - | ✅ | ✅ |
PostgreSQL 16 | - | - | ✅ |
To build images using the Makefile:
# Build all versions
make build-all
# Build specific version
make build-15 # Builds image that upgrades to PostgreSQL 15
make build-16 # Builds image that upgrades to PostgreSQL 16
make build-17 # Builds image that upgrades to PostgreSQL 17
# Build with custom registry and tag
REGISTRY=myregistry.io IMAGE_TAG=v1.0.0 make build-all
To build manually with Docker:
# Build image that upgrades to PostgreSQL 16
docker build --build-arg TARGET_VERSION=16 -t postgres-upgrade:to-16 .
# Build image that upgrades to PostgreSQL 15
docker build --build-arg TARGET_VERSION=15 -t postgres-upgrade:to-15 .
The repository includes comprehensive tests using Make and Taskfile:
# Install Task (required for tests)
curl -sL https://taskfile.dev/install.sh | sh
# Run all tests
make test
# Test specific upgrade paths
make test-14-to-15 # Test upgrade from 14 to 15
make test-14-to-16 # Test upgrade from 14 to 16
make test-15-to-16 # Test upgrade from 15 to 16
make test-14-to-17 # Test upgrade from 14 to 17
make test-15-to-17 # Test upgrade from 15 to 17
make test-16-to-17 # Test upgrade from 16 to 17
# Clean test volumes
make clean
The project includes GitHub Actions workflows:
- build-push.yml: Builds and pushes images to GitHub Container Registry
- test.yml: Runs comprehensive tests for all upgrade paths
- ci.yml: Lints Dockerfile and shell scripts
The Taskfiles are configured to use GitHub Actions' output grouping when running in CI. This creates collapsible sections in the workflow logs:
# In GitHub Actions, task output will be grouped like:
::group::test:seed-version
... task output ...
::endgroup::
To enable grouped output locally:
TASK_OUTPUT=group task test
To manually publish images:
# Push all versions
make push-all
# Push specific version
make push-15
make push-16
make push-17
- Always backup your data before running upgrades
- The upgrade process modifies the data directory in-place
- Once upgraded, you cannot downgrade to an older PostgreSQL version
- The container runs as the
postgres
user (UID 999) - Ensure your data directory has correct permissions
TARGET_VERSION
: The PostgreSQL version to upgrade to (default: 17)
If you encounter permission errors, ensure the data directory is owned by UID 999:
sudo chown -R 999:999 /path/to/your/pgdata
If an upgrade fails:
- Check the container logs for specific errors
- Ensure the data directory contains valid PostgreSQL data
- Verify the source version is supported (14, 15, or 16)
The upgrade process uses hard links and preserves original data with .old
suffix. If needed, you can recover the original data by:
- Removing the upgraded data
- Renaming
.old
files back to their original names - Using the original PostgreSQL version
Contributions are welcome! Please ensure:
- All tests pass (
task test
) - New features include appropriate tests
- Documentation is updated
This project is licensed under the MIT License.