postgresql/src/bin
Nathan Bossart 158408fef8 pg_upgrade: Fix handling of pg_largeobject_metadata.
For binary upgrades from v16 or newer, pg_upgrade transfers the
files for pg_largeobject_metadata from the old cluster, as opposed
to using COPY or ordinary SQL commands to reconstruct its contents.
While this approach adds complexity, it can greatly reduce
pg_upgrade's runtime when there are many large objects.

Large objects with comments or security labels are one source of
complexity for this approach.  During pg_upgrade, schema
restoration happens before files are transferred.  Comments and
security labels are transferred in the former step, but the COMMENT
and SECURITY LABEL commands will fail if their corresponding large
objects do not exist.  To deal with this, pg_upgrade first copies
only the rows of pg_largeobject_metadata that are needed to avoid
failures.  Later, pg_upgrade overwrites those rows by replacing
pg_largeobject_metadata's files with its files in the old cluster.

Unfortunately, there's a subtle problem here.  Simply put, there's
no guarantee that pg_upgrade will overwrite all of
pg_largeobject_metadata's files on the new cluster.  For example,
the new cluster's version might more aggressively extend relations
or create visibility maps, and pg_upgrade's file transfer code is
not sophisticated enough to remove files that lack counterparts in
the old cluster.  These extra files could cause problems
post-upgrade.

More fortunately, we can simultaneously fix the aforementioned
problem and further optimize binary upgrades for clusters with many
large objects.  If we teach the COMMENT and SECURITY LABEL commands
to allow nonexistent large objects during binary upgrades,
pg_upgrade no longer needs to transfer pg_largeobject_metadata's
contents beforehand.  This approach also allows us to remove the
associated dependency tracking from pg_dump, even for upgrades from
v12-v15 that use COPY to transfer pg_largeobject_metadata's
contents.

In addition to what is described in the previous paragraph, this
commit modifies the query in getLOs() to only retrieve LOs with
comments or security labels for upgrades from v12 or newer.  We
have long assumed that such usage is rare, so this should reduce
pg_upgrade's memory usage and runtime in many cases.  We might also
be able to remove the "upgrades from v12 or newer" restriction on
the recent batch of optimizations by adding special handling for
pg_largeobject_metadata's hidden OID column on older versions
(since this catalog previously used the now-removed WITH OIDS
feature), but that is left as a future exercise.

Reported-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/3yd2ss6n7xywo6pmhd7jjh3bqwgvx35bflzgv3ag4cnzfkik7m%40hiyadppqxx6w
2026-02-09 14:58:02 -06:00
..
initdb Update to latest Snowball sources. 2026-01-05 15:22:37 -05:00
pg_amcheck Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_archivecleanup Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_basebackup Standardize replication origin naming to use "ReplOrigin". 2026-01-28 11:03:29 -08:00
pg_checksums Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_combinebackup Fix some error message inconsistencies 2026-02-06 15:38:16 +09:00
pg_config Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_controldata Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_ctl Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_dump pg_upgrade: Fix handling of pg_largeobject_metadata. 2026-02-09 14:58:02 -06:00
pg_resetwal pg_resetwal: Fix incorrect error message related to pg_wal/summaries/ 2026-02-04 16:38:06 +09:00
pg_rewind Further error message fix 2026-02-07 22:37:02 +01:00
pg_test_fsync Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_test_timing Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_upgrade pg_upgrade: Optimize logical replication slot caught-up check. 2026-02-04 17:11:27 -08:00
pg_verifybackup Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
pg_waldump pg_waldump: Remove file-level global WalSegSz. 2026-01-27 08:33:20 -05:00
pg_walsummary Fix accidentally cast away qualifiers 2026-01-26 16:02:31 +01:00
pgbench Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgevent Update copyright for 2026 2026-01-01 13:24:10 -05:00
psql psql: Add %i prompt escape to indicate hot standby status. 2026-02-03 10:03:19 +09:00
scripts Update copyright for 2026 2026-01-01 13:24:10 -05:00
Makefile Update copyright for 2026 2026-01-01 13:24:10 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00