Alpine 3.25 Makes PostgreSQL 19 the Default: The Upgrade That Loses Data
Bottom line: Alpine 3.25 makes PostgreSQL 19 the default package, and apk upgrade will not migrate your data directory for you. Dump, then restore, or run pg_upgrade with the right bindirs, and check the collation before either.
Phoronix reported on December 4 that Alpine Linux 3.25 has shipped with the Linux 7.3 kernel and PostgreSQL 19 as the default database package. For a distribution that lives in containers and small VMs, that combination is the whole point of the release. For anyone who has a persistent Alpine box running the previous default, it is also a data-loss trap, because Alpine’s packaging makes it very easy to end up with two PostgreSQL versions installed and one of them pointed at your data.
The failure is not exotic, and it does not announce itself as a version problem at first. You run apk upgrade, the postgresql package resolves to 19, the old binaries are replaced, and the service refuses to start because the data directory was initialized by 18. On a good day you get a clear error about an incompatible catalog version. On a bad day you get a partially started server, a monitoring alert, and a backup job that has been silently failing since the upgrade.
What actually changes in the package
Alpine splits the server and client, and the version is in the package name. That means an upgrade does not replace your server in place; it can leave both versions installed side by side, which is convenient for pg_upgrade and dangerous if you are not paying attention to which binary is on your PATH.
1 | apk info -v | grep -i postgres |
Before touching anything, find out where the new package puts its binaries and where it expects data. Alpine’s layout has moved between major versions, and guessing is how people lose an afternoon.
1 | apk info -L postgresql19 | grep -E '/bin/|/data' |
Use the paths the package prints. The commands below assume /usr/bin for binaries and /var/lib/postgresql/data for data, which is the common case, but verify rather than copy.
Choosing the migration path
Two paths, and the choice is about downtime and extensions rather than about preference.
| Method | Downtime | Handles extensions | Risk |
|---|---|---|---|
pg_dumpall + restore into a fresh cluster |
full dump and load | must reinstall each extension | low, but slow on large databases |
pg_upgrade --link |
minutes | extension binaries must match | medium, in-place, needs rollback plan |
| Logical replication to a new cluster | seconds at cutover | per-table, manual for sequences | low downtime, most setup |
| Do nothing and pin the old package | none | n/a | drifts, and pinning ends eventually |
For anything under a few hundred gigabytes, dump and restore is the right answer. It is boring, it produces a tested backup as a side effect, and it does not care about collation differences between the old and new clusters, because the new cluster is initialized fresh with whatever locale you specify.
pg_upgrade --link is for databases where the dump window is too long. It hard-links the data files instead of copying them, so it is fast, and it also means the old cluster is no longer independently usable: a failed upgrade can leave you with neither.
The dump and restore, done properly
1 | # 1. stop writes, then dump the whole cluster |
Step 3 is the one people skip and then regret. Moving rather than deleting costs disk space for a day and buys you a rollback that takes one command.
Step 4 deserves a decision rather than a default. --locale=C.UTF-8 sorts by byte value, which is fast and stable and wrong if your application expects linguistic ordering. If the old cluster used a different collation, sorting order in indexes changes, and a query with ORDER BY name can return rows in a different order than before. That is not a bug, it is a different collation, and it will show up as a failing test rather than as a corrupt database.
1 | -- record this before the migration and compare after |
The pg_upgrade path, with the checks that matter
If you are going the in-place route, run the check mode first. It refuses to proceed on most of the things that would break, and its output is the migration plan.
1 | NEW_BIN=$(apk info -L postgresql19 | grep -m1 '/bin/postgres$' | xargs dirname) |
Three things the check will flag that are worth pre-empting. Extensions must exist as packages built for 19; a PostGIS or pg_stat_statements package from the old tree will block the upgrade until you install the matching one. Prepared transactions must be resolved, because pg_upgrade cannot carry them across. And the new data directory must already be initialized, with the same encoding as the old one.
1 | SELECT count(*) FROM pg_prepared_xacts; |
If the extension versions differ between the old and new package trees, do not upgrade the extension before the migration. Upgrade the cluster first, then run ALTER EXTENSION ... UPDATE in the new cluster, which is the order the extension authors support.
The container case is different
If PostgreSQL runs in a container on Alpine, the upgrade is a volume problem, not a package problem. The image tag determines the server version, the volume holds the data, and docker pull plus docker compose up will happily start a 19 server against an 18 volume and exit with a catalog version error.
1 | services: |
Pin the tag to the major version, never latest, and treat a major bump as a migration with a dump and a restore step in the runbook. A minor bump within 19 is safe to pull; a major bump is not, and the tag is the only thing that distinguishes them at deploy time.
What to do before the next apk upgrade
Pin postgresql18 in /etc/apk/world until you have a window and a tested restore, take a dump you have verified by restoring it somewhere harmless, and write down the collation of every database you own. Then run the upgrade with the old data directory moved aside rather than deleted, and keep it for a week. The package manager will not warn you, the service will not start, and the error it prints will be about a catalog version rather than about the backup you did not take.
FAQ
Why won’t PostgreSQL start after an Alpine 3.25 apk upgrade?
The postgresql package resolves to version 19 and replaces the old binaries, but the data directory was initialized by version 18. The server refuses to start because of an incompatible catalog version. On a worse outcome you get a partially started server and a backup job that has been silently failing since the upgrade.
How do I check which PostgreSQL versions are installed on Alpine?
Alpine splits the server and client, and the version is in the package name, so an upgrade can leave both versions installed side by side. Run apk info -v | grep -i postgres to list them. Then use apk info -L postgresql19 to find where the new package puts its binaries and data.
Should I use pg_dumpall or pg_upgrade to migrate to PostgreSQL 19?
For anything under a few hundred gigabytes, dump and restore is the right answer: it is slow but low-risk, produces a tested backup, and does not care about collation differences because the new cluster is initialized fresh. Use pg_upgrade --link only when the dump window is too long, since a failed upgrade can leave you with neither cluster.
How do I avoid data loss when migrating PostgreSQL on Alpine?
Dump the whole cluster with pg_dumpall, verify the dump has content and ends cleanly, then move the old data directory aside rather than deleting it. Initialize the new cluster with the locale you want and restore into it. Keeping the old directory for a week buys you a rollback that takes one command.
Does changing the locale during a PostgreSQL migration affect query results?
Yes. If the old cluster used a different collation, sorting order in indexes changes, and a query with ORDER BY name can return rows in a different order. That is a different collation rather than a bug, and it shows up as a failing test rather than a corrupt database.











