public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Fix data checksum processing for temp relations and dropped databases
Date: Thu, 9 Jul 2026 11:24:31 +0900
Message-ID: <CAHGQGwGDHAQw=bmpRzk+EmKzVtxZiD5YDurMUffBMwr6WXugQA@mail.gmail.com> (raw)

Hi,

While reading the data checksum code, I found that BuildRelationList()
filters out non-temporary relations without storage, but does not
apply the same filtering to temporary relations. As a result, temporary
relations without storage, such as temporary views, are included in
the list of relations to wait for even though they are irrelevant to
checksum processing. For example, enabling data checksums can
unnecessarily wait for a long-lived session that owns only a temporary view.

I think BuildRelationList() should exclude temporary relations without
RELKIND_HAS_STORAGE(), matching the existing behavior for
non-temporary relations. Attached patch implements this.

Also there seems a small race condition. When enabling data checksums
online, the launcher assigns the first worker to process the shared catalogs
and prevents later workers from doing so. However, if that worker's
database is dropped after it has been selected for processing but
before checksum processing begins (a very small window), the worker
fails without processing the shared catalogs, yet they are still marked
as processed. As a result, later workers skip them, and checksum
enabling can complete successfully even though the shared catalogs
were never processed.

To fix this, we should mark the shared catalogs as processed only after
a worker completes successfully. Attached patch also implements this.

Thoughts?

Regards,

-- 
Fujii Masao


Attachments:

  [application/octet-stream] v1-0001-Fix-data-checksum-processing-for-temp-relations-a.patch (3.4K, ../CAHGQGwGDHAQw=bmpRzk+EmKzVtxZiD5YDurMUffBMwr6WXugQA@mail.gmail.com/2-v1-0001-Fix-data-checksum-processing-for-temp-relations-a.patch)
  download | inline diff:
From 6095cc49dce11e88840ed0c94071b124a1114461 Mon Sep 17 00:00:00 2001
From: Fujii Masao <[email protected]>
Date: Wed, 8 Jul 2026 23:52:39 +0900
Subject: [PATCH v1] Fix data checksum processing for temp relations and
 dropped databases

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.
---
 src/backend/postmaster/datachecksum_state.c | 22 +++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/backend/postmaster/datachecksum_state.c b/src/backend/postmaster/datachecksum_state.c
index 68557c16cb9..2b3e1df6cf1 100644
--- a/src/backend/postmaster/datachecksum_state.c
+++ b/src/backend/postmaster/datachecksum_state.c
@@ -1329,9 +1329,12 @@ ProcessAllDatabases(void)
 		 * When one database has completed, it will have done shared catalogs
 		 * so we don't have to process them again.
 		 */
-		LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE);
-		DataChecksumState->process_shared_catalogs = false;
-		LWLockRelease(DataChecksumsWorkerLock);
+		if (result == DATACHECKSUMSWORKER_SUCCESSFUL)
+		{
+			LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE);
+			DataChecksumState->process_shared_catalogs = false;
+			LWLockRelease(DataChecksumsWorkerLock);
+		}
 	}
 
 	FreeDatabaseList(DatabaseList);
@@ -1469,11 +1472,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)
@@ -1499,6 +1502,9 @@ BuildRelationList(bool temp_relations, bool include_shared)
 		{
 			if (!temp_relations)
 				continue;
+
+			if (!RELKIND_HAS_STORAGE(pgc->relkind))
+				continue;
 		}
 		else
 		{
-- 
2.55.0



view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Fix data checksum processing for temp relations and dropped databases
  In-Reply-To: <CAHGQGwGDHAQw=bmpRzk+EmKzVtxZiD5YDurMUffBMwr6WXugQA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox