pg_upgrade check for invalid databases

From: Thomas Krennwallner <tk(at)postsubmeta(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: pg_upgrade check for invalid databases
Date: 2024-09-30 00:45:50
Message-ID: f9315bf0-e03e-4490-9f0d-5b6f7a6d9908@postsubmeta.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

if a cluster contains invalid databases that we cannot connect to
anymore, pg_upgrade would currently fail when trying to connect to the
first encountered invalid database with

Performing Consistency Checks
-----------------------------
Checking cluster versions ok

connection failure: connection to server on socket "/tmp/.s.PGSQL.50432"
failed: FATAL: cannot connect to invalid database "foo"
HINT: Use DROP DATABASE to drop invalid databases.

Failure, exiting

If there is more than one invalid database, we need to run pg_upgrade
more than once (unless the user inspects pg_database).

I attached two small patches for PG 17 and PG 18 (can be easily
backported to all previous versions upon request). Instead of just
failing to connect with an error, we collect all invalid databases in a
report file invalid_databases.txt:

Performing Consistency Checks
-----------------------------
Checking cluster versions ok
Checking for invalid databases fatal

Your installation contains invalid databases as a consequence of
interrupted DROP DATABASE. They are now marked as corrupted databases
that cannot be connected to anymore. Consider removing them using
DROP DATABASE ...;
A list of invalid databases is in the file:

/usr/local/pgsql/data/18/pg_upgrade_output.d/20240929T200559.707/invalid_databases.txt
Failure, exiting

Any thoughts on the proposed patches?

Attachment Content-Type Size
pg18-v1-0001-pg_upgrade-Add-check-for-invalid-databases.patch text/x-patch 8.2 KB
pg17-v1-0001-pg_upgrade-Add-check-for-invalid-databases.patch text/x-patch 7.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2024-09-30 01:07:55 Re: query_id, pg_stat_activity, extended query protocol
Previous Message Tatsuo Ishii 2024-09-30 00:07:51 Re: Row pattern recognition