Teach pg_upgrade to deal with invalid databases

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Robert Treat <rob(at)xzilla(dot)net>
Subject: Teach pg_upgrade to deal with invalid databases
Date: 2026-09-04 17:27:00
Message-ID: CALj2ACV3jSPaMCSRQ8XZTN_meZezNyySpMJVhVBZy_qDJK2mmQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Reviving this thread [1] on the subject for PG20.

Currently, pg_upgrade fails when it encounters an invalid database
(commit c66a7d75e65, a database whose DROP DATABASE got interrupted)
in the source cluster, blocking the whole upgrade workflow. In the
previous thread, various options were discussed such as skip or drop,
and commit f638aafd1ea tightened checking and error reporting for
invalid databases.

I think we can do better here. If a user decided to DROP a database,
the data in it is no longer wanted. Even if it were, the data in the
files is unlikely to be consistent or useful, since DROP was
interrupted mid-operation (while evicting buffer pool pages, unlinking
files, etc.).

I would like to propose an option to skip the invalid databases, with
the default being on. This helps unblock upgrade workflows while still
preserving them for users who think it is necessary. Please find the
attached patch doing this.

Dropping the invalid databases during the upgrade is another approach,
but it could be costly, especially with large buffer pools and a large
number of files to unlink. Skipping them instead is simpler, and the
old directory contents would be cleaned up by the removal script that
pg_upgrade already generates.

Thoughts?

Thanks to Nathan Bossart and Robert Treat for earlier discussions and
design review.

[1] https://postgr.es/m/f9315bf0-e03e-4490-9f0d-5b6f7a6d9908%40postsubmeta.net

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-Teach-pg_upgrade-to-deal-with-invalid-databases.patch application/x-patch 12.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-04 17:54:07 Re: Teach pg_upgrade to deal with invalid databases
Previous Message Etsuro Fujita 2026-09-04 16:23:39 Re: Further cleanup related to statistics import support in postgres_fdw