]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix data checksum processing for temp relations and dropped databases
authorFujii Masao <fujii@postgresql.org>
Fri, 10 Jul 2026 13:34:24 +0000 (22:34 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 10 Jul 2026 13:34:24 +0000 (22:34 +0900)
When building the list of temporary relations to wait for, the code
previously included temporary relations without storage, such as
temporary views, even though they are irrelevant to checksum
processing. As a result, enabling data checksums could wait for a
long-lived session that owned only a temporary view.

This commit fixes the issue by filtering temporary relations with storage
only, matching the existing behavior for non-temporary relations.

Also, when enabling data checksums online, the launcher assigns the
first worker to process shared catalogs and prevents later workers from
doing so. Previously, if that worker's database was dropped after it
had been selected for processing but before checksum processing began,
the worker failed without processing the shared catalogs, yet they were
still marked as processed. As a result, later workers skipped them, and
checksum enabling could complete successfully even though the shared
catalogs had never been processed.

This commit fixes the issue by marking shared catalogs as processed
only after a worker completes successfully.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CAHGQGwGDHAQw=bmpRzk+EmKzVtxZiD5YDurMUffBMwr6WXugQA@mail.gmail.com
Backpatch-through: 19

src/backend/postmaster/datachecksum_state.c

index bec110105dfc7da98e232b6aaeb11885df207f44..7f29551202ff96d342e2a86cb65303df635968d3 100644 (file)
@@ -1352,6 +1352,14 @@ ProcessAllDatabases(void)
                        /* Abort flag set, so exit the whole process */
                        return false;
                }
+               else if (result == DATACHECKSUMSWORKER_DROPDB)
+               {
+                       /*
+                        * Ignore databases that were dropped before their worker could
+                        * process them, and continue with the remaining databases.
+                        */
+                       continue;
+               }
 
                /*
                 * When one database has completed, it will have done shared catalogs
@@ -1497,11 +1505,11 @@ FreeDatabaseList(List *dblist)
  *             Compile a list of relations in the database
  *
  * Returns a list of OIDs for the requested relation types. If temp_relations
- * is True then only temporary relations are returned. If temp_relations is
- * False then non-temporary relations which have data checksums are returned.
- * If include_shared is True then shared relations are included as well in a
- * non-temporary list. include_shared has no relevance when building a list of
- * temporary relations.
+ * is True then only temporary relations with storage are returned.  If
+ * temp_relations is False then non-temporary relations with storage are
+ * returned.  If include_shared is True then shared relations are included as
+ * well in a non-temporary list. include_shared has no relevance when building
+ * a list of temporary relations.
  */
 static List *
 BuildRelationList(bool temp_relations, bool include_shared)
@@ -1522,6 +1530,9 @@ BuildRelationList(bool temp_relations, bool include_shared)
        {
                Form_pg_class pgc = (Form_pg_class) GETSTRUCT(tup);
 
+               if (!RELKIND_HAS_STORAGE(pgc->relkind))
+                       continue;
+
                /* Only include temporary relations when explicitly asked to */
                if (pgc->relpersistence == RELPERSISTENCE_TEMP)
                {
@@ -1537,9 +1548,6 @@ BuildRelationList(bool temp_relations, bool include_shared)
                        if (temp_relations)
                                continue;
 
-                       if (!RELKIND_HAS_STORAGE(pgc->relkind))
-                               continue;
-
                        if (pgc->relisshared && !include_shared)
                                continue;
                }