Sub topic 12
Troubleshooting common failures
This chapter assumes you have already run initdb for the new cluster and used pg_upgrade --check, --link, and --jobs as shown in the earlier chapters. You should be comfortable reading server logs and running psql against both clusters. Here you will learn to read a pg_upgrade failure, match it to a cause, and decide whether the old cluster is still safe to start.
Read the failure before you retry
pgupgrade stops at the first problem it finds. The message on the terminal is usually only a summary. The details are in log files that pgupgrade writes while it runs.
In PostgreSQL 15 and later, the logs go into a timestamped directory under pg_upgrade_output.d inside the new data directory. pg_upgrade removes this directory after a successful run. It keeps it after a failure. Older versions write the same files into the directory you ran the command from.
latest=$(ls -td /data/pg17/pg_upgrade_output.d/*/ | head -1)
ls "$latest"
tail -n 40 "$latest/pg_upgrade_server.log"| File | What it records |
|---|---|
| `pg_upgrade_internal.log` | The main step-by-step progress of pg_upgrade. |
| `pg_upgrade_server.log` | The server log of the temporary postmasters that pg_upgrade starts. |
| `pg_upgrade_dump_<oid>.log` | Output of schema dump and restore, one file per database. |
| `pg_upgrade_utility.log` | Output of helper tools such as `pg_resetwal`. |
| Named `.txt` files | Lists of the exact objects that failed a check, for example `loadable_libraries.txt` or `tables_using_reg.txt`. |
The .txt files matter most. A check failure such as "Your installation contains tables using a data type that cannot be upgraded" names a file, and that file lists the schema, table, and column to fix.
Oops—the diagram must follow the required format. Here is the full chapter.
How a failure maps to your next step
The key question after any failure is whether the old cluster was changed. That decides whether you simply fix and retry or must undo something first.
Failures before any data moves
Most failures happen in the checks at the start. These cost nothing to retry, but you must fix the cause.
The old cluster was not shut down cleanly
Typical messages: "The source cluster was not shut down cleanly" or "There seems to be a postmaster servicing the old cluster."
pgupgrade needs a clean shutdown checkpoint in the old cluster. A crash, `pgctl stop -m immediate, or a leftover postmaster.pid` file leaves the cluster in the wrong state. Start the old cluster with the old binaries, let it recover, and stop it in the default smart or fast mode.
/opt/pg16/bin/pg_ctl -D /data/pg16 start
/opt/pg16/bin/pg_ctl -D /data/pg16 stop -m fastDo not delete postmaster.pid by hand unless you have confirmed that no server process is running.
The new cluster is not empty or does not match
Messages such as "New cluster database "x" is not empty" mean someone created objects in the new cluster after initdb. The new cluster must contain only the template databases and postgres. Delete the new data directory and run initdb again.
Other mismatches are caused by initdb options:
- Encoding or locale: the checks report "encodings for database ... do not match" or "lc_collate values for database ... do not match". Re-run
initdbwith the same--encodingand--localevalues as the old cluster, as shown in the initialization chapter. - Locale provider: if the old cluster uses the ICU provider, the new cluster must also use ICU, with a matching locale.
- Data checksums: pgupgrade refuses to upgrade across a checksum mismatch, with a message such as "old cluster does not use data checksums but the new one does". PostgreSQL 18 enables checksums by default in
initdb, so a cluster created with defaults can fail against an older cluster without them. Compare the two with `SHOW datachecksums;. Then re-runinitdbwith--no-data-checksumsor--data-checksumsto match the old cluster. You can change checksums afterwards withpg_checksums` on a stopped cluster.
Incompatible data types and objects
pg_upgrade cannot carry some objects across versions. The check names them and writes a file listing each one.
- Removed data types:
abstime,reltime, andtintervalwere removed in PostgreSQL 12, andsql_identifierin user tables is rejected for older sources. Alter the columns to a supported type in the old cluster. reg*types: columns of types such asregprocorregclassstore OIDs that do not survive the upgrade. The check lists the columns, and you must convert them (for example totext) before upgrading.- Prepared transactions: the old cluster must have none. Commit or roll them back.
- Roles named
pg_*: these names are reserved for built-in roles. Rename them in the old cluster.
Query the old cluster to find the last two:
SELECT gid, prepared, owner, database FROM pg_prepared_xacts;
SELECT rolname FROM pg_roles WHERE rolname ~ '^pg_' AND oid >= 16384;The oid >= 16384 filter skips the built-in roles, which have lower OIDs.
Missing extension libraries
The message is could not load library "$libdir/...", and the check writes loadable_libraries.txt. It means an extension installed in the old cluster has no matching shared library in the new installation. Install the new version's package, such as postgresql-17-postgis-3, before you run the upgrade. Third-party extensions are a common cause.
Use this query on the old cluster to list what you need to install:
SELECT name, installed_version
FROM pg_available_extensions
WHERE installed_version IS NOT NULL
ORDER BY name;Also check shared_preload_libraries in the old configuration. If it lists a library that the new installation lacks, the new server cannot start.
Connection and configuration problems
pg_upgrade starts both clusters temporarily. These are the usual obstacles:
- Authentication: pgupgrade connects as the bootstrap superuser many times. A password prompt, or an error such as "fesendauth: no password supplied", means
pg_hba.confrequires a password. Usepeerortrustfor local connections during the window, or provide a.pgpassfile. - Configuration outside the data directory: Debian and Ubuntu keep
postgresql.confin/etc/postgresql. The temporary server then fails to find its settings. Pass the path with--old-options "-c config_file=/etc/postgresql/16/main/postgresql.conf"and the matching--new-options. - Port clashes: pg_upgrade uses port 50432 by default, to avoid colliding with a running server. If that port is in use, set
--old-portand--new-port. - Ownership: run as the operating system user that owns both data directories, normally
postgres. The directories must have mode 0700 or 0750.
Failures during the run
Restore errors in the schema step
If the check passes but the run fails while restoring the schema, look at pg_upgrade_dump_<oid>.log. Search for the first ERROR, because later errors often follow from it. Common causes are a collation or operator class that exists in the old cluster but not the new one, and a schema object that depends on a missing extension. Fix the cause in the old cluster, then start again.
Hard-link failures
With --link, an error such as "could not create hard link ... Invalid cross-device link" means the old and new data directories are on different file systems. Hard links cannot cross file systems. Either put the new cluster on the same file system, or use --clone (on file systems that support reflinks, like XFS or Btrfs) or the default copy mode.
The same applies to tablespaces: with --link, every tablespace path must be on a file system that allows links from the new location.
Running out of disk space
In copy mode, you need room for a full second copy of the database. If the disk fills, pg_upgrade fails and the old cluster is untouched. Free space or switch to --link or --clone. Check free space before you start, using du -sh /data/pg16 and df -h /data.
Logical replication slots
If the source is PostgreSQL 17 or later, pgupgrade can carry logical slots over, but the new cluster needs `wallevel = logical and enough maxreplicationslots`. It also requires that all changes in the old slots have been consumed. Failures here are reported in the check output with a file name. Earlier source versions do not preserve slots, so you must recreate subscriptions after the upgrade. See the replicas chapter for details.
Is the old cluster still safe?
After a failed real run, check the state before you start any server.
| Situation | Old cluster state | Action |
|---|---|---|
| Failure in `--check` | Unchanged | Fix the cause, rerun `--check`. |
| Failure before linking began, any mode | Unchanged | Fix the cause, delete the new data directory, run `initdb` again, rerun. |
| Copy or clone mode, failure at any point | Unchanged | Same as above. The old files were only read. |
| Link mode, `global/pg_control.old` exists, new cluster never started | Old data files shared with new cluster, not yet modified | Remove the `.old` suffix from `pg_control`, then start the old cluster. |
| Link mode, new cluster has been started | Old files may be modified | Restore from backup or promote a replica. Do not start the old cluster. |
To reuse the old cluster after a link-mode failure where the new cluster never started:
mv /data/pg16/global/pg_control.old /data/pg16/global/pg_control
/opt/pg16/bin/pg_ctl -D /data/pg16 startProblems after a successful upgrade
Some failures appear only once the new cluster is running.
- Slow queries right after the upgrade: the planner statistics were not carried over. Run
vacuumdb --all --analyze-in-stages, as in the post-upgrade chapter, and wait for the first stage to finish before you judge performance. - Extension warnings: pgupgrade can leave extensions at their old version. If it generates `updateextensions.sql
, run it withpsql -f update_extensions.sql` as a superuser. - Missing logical subscriptions or slots: if the source was older than 17, recreate them. Check
pg_replication_slotsandpg_subscription. - Unexpected configuration: pgupgrade does not copy
postgresql.confor `pghba.conf`. Compare the old and new files and port your settings by hand.
A short checklist for repeated failures
- Read the named
.txtfile and the firstERRORin the dump log. - Fix the cause in the old cluster (data types, roles, prepared transactions) or in the new installation (extension packages,
initdboptions). - Confirm the state of the old cluster using the table above.
- Recreate the new data directory with
initdbso it is empty. - Rerun
pg_upgrade --checkbefore the real run.
Exercise
You ran pg_upgrade --link. It failed with "could not create hard link between old and new data directories: Invalid cross-device link". global/pg_control.old does not exist in the old data directory and the new cluster never started. What caused the failure, and what are two ways to continue?
Show answer
The old data directory (/data/pg16) and the new one are on different file systems, and hard links cannot cross file systems. Because linking had not finished, the old cluster is unchanged and can still be started. To continue, either create the new cluster on the same file system as the old one and run --link again, or run pg_upgrade in copy mode (or --clone if the file system supports it). In both cases, delete the failed new data directory and run initdb again first so the new cluster is empty.
Exercise
pg_upgrade --check fails with could not load library "$libdir/postgis-3". Which file lists the details, and how do you fix it?
Show answer
The check writes loadable_libraries.txt in the pg_upgrade_output.d directory (or the working directory in versions before 15). The old cluster uses the PostGIS extension, but the new PostgreSQL installation has no matching shared library. Install the PostGIS package built for the new major version, then run pg_upgrade --check again.