How to Upgrade Postgres to 19 in Docker (and the 4 Errors I Hit on the Way)
Short answer: you can't upgrade Postgres in Docker by changing the image tag. postgres:19 refuses to start on a data directory from 17 or 18. You either dump the old cluster and restore it into a fresh 19 one (simple, needs downtime about as long as the restore), or you run pg_upgrade with both versions' binaries in one container (fast, a few more traps). For a database of a few GB, dump and…
You cannot upgrade PostgreSQL in Docker simply by changing the image tag. Instead, there are two methods to upgrade the database version: dump and restore, or using pg_upgrade with both versions' binaries in one container. For a smaller database, dump and restore is the recommended approach.
Stop the app before starting the upgrade process to ensure no writes are happening during the dump. Then, dump the old server with the new client and restore it into a fresh 19 cluster.
When using pg_upgrade in Docker, you need to provide both versions' binaries in one container. Building a small image with both versions allows you to upgrade the database faster, as pg_upgrade only hard-links the table files into the new cluster.
After the upgrade, check the version and settings of the database to ensure everything is working correctly. Additionally, reindex any full-text or GiST indexes after the upgrade, and be aware of any PostgreSQL 19 breaking changes that may affect your application.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to