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 restore is the one I'd pick.
PostgreSQL 19 was released on 19 November 2026. I upgraded the same Postgres 17 Docker volume both ways on my laptop with the official images, and hit four errors along the way. All of them are below, with the fix.
What I tested
-
postgres:17(17.12) as the old version – most Docker setups I see are on 16 or 17 -
postgres:19(19.0) as the new one -
postgres:18(18.7), only to check what a plain tag bump does from 18
The test database: one table with 100,000 rows, a full-text GIN index, a pg_trgm index, a GiST index on an inet column through btree_gist, and one role with an old MD5 password. The data is small on purpose. The point was to hit the upgrade checks, not to time a big restore. Everything here is as of 25 November 2026.
Can you just change the image tag?
No. This is what postgres:19 prints when you point it at a volume from 17:
Error: in 18+, these Docker images are configured to store database data in a format which is compatible with "pg_ctlcluster" (specifically, using major-version-specific directory names). This better reflects how PostgreSQL itself works, and how upgrades are to be performed. Counter to that, there appears to be PostgreSQL data in: /var/lib/postgresql/data This is usually the result of upgrading the Docker image without upgrading the underlying database using "pg_upgrade" (which requires both versions). From 18 to 19 you get the same error, only the path says /var/lib/postgresql/18/docker. That's good news: the image stops instead of starting an empty database on top of your data.
The error also tells you about the second change you have to deal with:
| postgres:17 and older | postgres:18 and newer | |
|---|---|---|
| Volume mount point | /var/lib/postgresql/data | /var/lib/postgresql |
PGDATA | /var/lib/postgresql/data | /var/lib/postgresql/<major>/docker |
| Data checksums on a new cluster | Off | On |
So if you come from 17 or older, your docker-compose.yml volume line changes too:
services: db: image: postgres:19 volumes: - pgdata19:/var/lib/postgresql # not /var/lib/postgresql/data PostgreSQL 19 breaking changes to check first
The full list is in the Migration to Version 19 section of the release notes. These are the ones that can change how a normal app behaves:
| Change in 19 | What it means for you |
|---|---|
| JIT is off by default | Long analytic queries that relied on JIT may get slower. Set jit = on if you measured a gain from it. |
standard_conforming_strings is always on | Old dumps made with it off won't load. Code that relies on backslash escapes in plain '...' strings breaks. |
| MD5 password login logs a warning | WARNING: authenticated with an MD5-encrypted password. Still works, but move roles to SCRAM now. |
| RADIUS auth is removed | If pg_hba.conf uses radius, the server won't accept those logins. |
max_locks_per_transaction default is 128 (was 64) | Uses a bit more shared memory. Only matters if you had set it by hand. |
io_workers is removed | Remove it from your postgresql.conf if you set it in 18. Four new settings replace it. |
btree_gist inet/cidr index operator classes | pg_upgrade refuses clusters that use them. Dump and restore doesn't care. |
json_array() over zero rows returns [], not NULL | Check code that tests the result for NULL. |
Full-text search and pg_trgm follow the database locale provider | Reindex those indexes after the upgrade. |
Two more for people who use them: logical replication now copies sequence values, and the new REPACK (CONCURRENTLY) rewrites a bloated table without blocking reads and writes, which is what most people install pg_repack for.
Option 1: upgrade with pg_dumpall and restore
This is the boring way and it worked the first time. Stop your app first so nothing writes during the dump.
1. Dump the old server with the new client. The PostgreSQL docs recommend running the newer pg_dumpall against the old server. With Compose, put the old database on a network the dump container can reach (here the network is myapp_default and the service is db):
docker compose stop app docker run --rm --network myapp_default -e PGPASSWORD="$POSTGRES_PASSWORD" \ postgres:19 pg_dumpall -h db -U app > dump.sql 2. Start an empty 19 server on a new volume. Keep the old volume. It is your rollback.
services: db: image: postgres:19 environment: POSTGRES_USER: app POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: app volumes: - pgdata19:/var/lib/postgresql volumes: pgdata19: 3. Restore.
docker compose up -d db docker compose exec -T db psql -U app -d postgres < dump.sql You'll see ERROR: role "app" already exists. That's expected, because the image already created the user from POSTGRES_USER. Every other line should be clean.
On my test data the dump took 0.4 seconds and the restore 3.5 seconds for a 10 MB file. Restore time grows with data size and the number of indexes, so time it on a copy of your real database before you plan the downtime.
4. Check.
SELECT version(); SHOW jit; -- off on 19 SHOW max_locks_per_transaction; -- 128 on 19 One nice side effect: the dump writes USING gist (client) without the operator class, so the inet index came back on the new built-in inet_ops class. The btree_gist problem from Option 2 never shows up.
Option 2: pg_upgrade --link in Docker
pg_upgrade --link doesn't copy table files, it hard-links them into the new cluster. On a big database that is minutes instead of hours. The catch: pg_upgrade needs the binaries of both versions, and the official image has only one. I built a small image with both:
FROM postgres:19 RUN sed -i 's/$/ 17/' /etc/apt/sources.list.d/pgdg.list \ && apt-get update \ && apt-get install -y --no-install-recommends postgresql-17 \ && rm -rf /var/lib/apt/lists/* docker build -t pg-upgrade:17-to-19 . --link needs the old and new data directories on the same filesystem. So mount the volume one level up, at /var/lib/postgresql. Then the old data sits in data/ and the new cluster goes into 19/docker/, the path the 19 image expects. Here is the script I ended up with, errors included:
```bash title="upgrade.sh"
!/bin/sh
set -e
OLD=/var/lib/postgresql/data
NEW=/var/lib/postgresql/19/docker
mkdir -p "$NEW" && chown -R postgres:postgres /var/lib/postgresql
cd /var/lib/postgresql # pg_upgrade writes its scripts to the current directory
create the new cluster once, so a real run after --check reuses it
[ -f "$NEW/PG_VERSION" ] || \
gosu postgres /usr/lib/postgresql/19/bin/initdb -D "$NEW" -U app --no-data-checksums
gosu postgres /usr/lib/postgresql/19/bin/pg_upgrade \
-b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/19/bin \
-d "$OLD" -D "$NEW" -U app --link "$@"
Stop the database, **back up the volume**, then do a dry run first: ```bash docker compose stop docker run --rm -v myapp_pgdata:/var/lib/postgresql -v ./upgrade.sh:/upgrade.sh:ro \ pg-upgrade:17-to-19 /upgrade.sh --check -U app has to be the user that created the old cluster, which is your POSTGRES_USER. That's where it went wrong for me twice.
Error 1: "old cluster does not use data checksums but the new one does"
Checking cluster versions ok old cluster does not use data checksums but the new one does Failure, exiting Since PostgreSQL 18, initdb turns data checksums on by default. The 17 image didn't. Both clusters must match, so the new one needs --no-data-checksums (it's already in the script above). If you want checksums, turn them on later with pg_checksums --enable while the server is stopped.
Error 2: "Checking for uses of gist_inet_ops/gist_cidr_ops fatal"
Checking for uses of gist_inet_ops/gist_cidr_ops fatal Your installation contains indexes that use the btree_gist extension's gist_inet_ops or gist_cidr_ops operator classes, which cannot be binary-upgraded. Replace them with indexes that use the built-in GiST inet_ops operator class. If you ever created a GiST index on an inet or cidr column with btree_gist installed, it used the extension's operator class, because that was the default. Find them on the old server and rebuild them on the built-in class:
SELECT c.relname AS index, t.relname AS table FROM pg_index i JOIN pg_class c ON c.oid = i.indexrelid JOIN pg_class t ON t.oid = i.indrelid JOIN pg_opclass o ON o.oid = ANY (i.indclass) WHERE o.opcname IN ('gist_inet_ops', 'gist_cidr_ops'); CREATE INDEX CONCURRENTLY posts_client_new ON posts USING gist (client inet_ops); DROP INDEX CONCURRENTLY posts_client; ALTER INDEX posts_client_new RENAME TO posts_client; After that the real run went through:
Upgrade Complete ---------------- Some statistics are not transferred by pg_upgrade. Once you start the new server, consider running these two commands: /usr/lib/postgresql/19/bin/vacuumdb -U app --all --analyze-in-stages --missing-stats-only /usr/lib/postgresql/19/bin/vacuumdb -U app --all --analyze-only Running this script will delete the old cluster's data files: ./delete_old_cluster.sh With --link, the old cluster is gone for good once the new one starts. Your rollback is the backup you took, not the old directory.
Error 3: the 19 image still won't start
Change the Compose file to postgres:19 with the volume on /var/lib/postgresql, and you get the "in 18+, these Docker images…" error from the top of this post again. The image sees the old data/ directory and stops. Only after pg_upgrade printed Upgrade Complete, save the old pg_hba.conf (you need it for error 4), then delete the old directory:
docker run --rm -v myapp_pgdata:/var/lib/postgresql alpine sh -c \ 'cp /var/lib/postgresql/data/pg_hba.conf /var/lib/postgresql/pg_hba.conf.17 \ && rm -rf /var/lib/postgresql/data' Error 4: "no pg_hba.conf entry for host"
The server started, and my app couldn't connect:
FATAL: no pg_hba.conf entry for host "172.30.0.4", user "app", database "app", no encryption The official image adds the host all all all scram-sha-256 line to pg_hba.conf when it creates a new database. Our initdb ran by hand, so the new pg_hba.conf only allows localhost. Copy the old file back and reload:
docker compose exec db sh -c \ 'cp /var/lib/postgresql/pg_hba.conf.17 /var/lib/postgresql/19/docker/pg_hba.conf' docker compose exec db psql -U app -c "SELECT pg_reload_conf()" If you changed postgresql.conf on the old server, compare it with the new one too. pg_upgrade doesn't carry over any config.
After the upgrade
Run the statistics step that pg_upgrade asked for, update extensions, and reindex text search:
docker compose exec db vacuumdb -U app --all --analyze-in-stages --missing-stats-only # in my case one line: ALTER EXTENSION "btree_gist" UPDATE; (1.7 -> 1.9) docker compose exec db psql -U app -d postgres -f /var/lib/postgresql/update_extensions.sql REINDEX INDEX CONCURRENTLY posts_fts; REINDEX INDEX CONCURRENTLY posts_trgm; pg_upgrade writes update_extensions.sql (and delete_old_cluster.sh) to the current directory of the upgrade container. That's why the script does cd /var/lib/postgresql first. Without it, the files are gone when the container exits.
Dump/restore or pg_upgrade: which one to pick
| pg_dumpall + restore | pg_upgrade --link | |
|---|---|---|
| Downtime | Dump + restore time, grows with data size | Seconds to minutes, almost independent of size |
| Needs both versions' binaries | No | Yes, custom image |
| Data checksums mismatch | Not a problem | Must match (--no-data-checksums) |
btree_gist inet/cidr indexes | Not a problem | Must be rebuilt first |
pg_hba.conf / postgresql.conf | Image defaults, re-apply your changes | Copy them over by hand |
| Rollback | Old volume untouched | Only from a backup |
| Errors I hit | 0 | 4 |
My rule of thumb: if the restore fits in the downtime you can accept, dump and restore. It has fewer moving parts, the old volume stays as a rollback, and the indexes come back clean. Use pg_upgrade --link when the database is big enough that a restore would take hours.
FAQ
When was PostgreSQL 19 released?
PostgreSQL 19.0 was released on 19 November 2026. The official Docker image postgres:19 shipped 19.0 at the same time.
Can I upgrade Postgres in Docker by changing the image tag?
No. Major versions use different data formats. Since postgres:18, the official image refuses to start when it finds data from an older version and prints 'in 18+, these Docker images are configured to store database data in a format which is compatible with pg_ctlcluster'. You need pg_dumpall and a restore, or pg_upgrade with both versions' binaries.
Why does postgres:19 say there is data in /var/lib/postgresql/data?
Since postgres:18 the image keeps data in /var/lib/postgresql//docker and expects the volume on /var/lib/postgresql. An old volume mounted at /var/lib/postgresql/data, or an old data directory left inside the new mount, makes the image stop instead of creating a new empty database.
How do I run pg_upgrade in Docker?
Build an image from postgres:19 that also installs postgresql-17 (or your old version) from the PGDG apt repository. Mount the volume at /var/lib/postgresql so both data directories are on one filesystem, initdb the new cluster in /var/lib/postgresql/19/docker with the same user and checksum setting as the old one, then run pg_upgrade --link with -b and -B pointing at both bin directories. Run it with --check first.
What breaks when upgrading to PostgreSQL 19?
For most apps: JIT is off by default, standard_conforming_strings can no longer be turned off, MD5 password logins log a warning, RADIUS auth is removed, and json_array() over zero rows returns an empty array instead of NULL. pg_upgrade also refuses btree_gist inet/cidr indexes and clusters whose data checksum setting differs from the new one.
Do MD5 passwords still work in PostgreSQL 19?
Yes, but every login with an MD5 password logs 'WARNING: authenticated with an MD5-encrypted password' and the docs say MD5 support will be removed in a future release. Set password_encryption to scram-sha-256 and reset the passwords to move the roles to SCRAM.
Should I use pg_dumpall or pg_upgrade?
Use pg_dumpall and restore if the restore fits into your downtime window: fewer steps, the old volume stays as a rollback, and indexes are rebuilt cleanly. Use pg_upgrade --link for large databases where a restore would take hours, and take a backup first, because the old cluster can't be started after the new one has run.
More on running Postgres yourself: self-hosted Postgres vs Supabase and our Postgres benchmark of RDS, Hostim and a self-hosted server.
If you'd rather not plan major upgrades yourself, Hostim runs managed PostgreSQL next to your apps in the EU, on a flat monthly price.
👉 Deploy an app with Postgres on Hostim, free 5-day trial, no card
Last updated: 25 November 2026.
![[QGIS Web Client] Contributions and improvements, funded by the Eurométropole de Strasbourg](https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqnom8ob72l2wbuxp9hn0.png)