public inbox for [email protected]  
help / color / mirror / Atom feed
Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
5+ messages / 3 participants
[nested] [flat]

* Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
@ 2026-04-10 08:38 Lakshmi N <[email protected]>
  2026-04-10 11:57 ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Lakshmi N @ 2026-04-10 08:38 UTC (permalink / raw)
  To: [email protected]

Hi hackers,

I noticed CFI is missing while scanning pg_class for RELKIND_RELATION and
RELKIND_TOASTVALUE. On a database with several thousands of tables, these
scans can take a noticeable amount of time. Attached a patch to address
this.

Regards,
Lakshmi


Attachments:

  [application/octet-stream] 0001-autovacuum-cfi.patch (639B, 3-0001-autovacuum-cfi.patch)
  download | inline diff:
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 82061247..90575a52 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -2042,6 +2042,8 @@ do_autovacuum(void)
 		bool		wraparound;
 		AutoVacuumScores scores;
 
+		CHECK_FOR_INTERRUPTS();
+
 		if (classForm->relkind != RELKIND_RELATION &&
 			classForm->relkind != RELKIND_MATVIEW)
 			continue;
@@ -2146,6 +2148,8 @@ do_autovacuum(void)
 		bool		wraparound;
 		AutoVacuumScores scores;
 
+		CHECK_FOR_INTERRUPTS();
+
 		/*
 		 * We cannot safely process other backends' temp tables, so skip 'em.
 		 */


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
  2026-04-10 08:38 Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
@ 2026-04-10 11:57 ` Dapeng Wang <[email protected]>
  2026-04-11 05:02   ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Dapeng Wang @ 2026-04-10 11:57 UTC (permalink / raw)
  To: Lakshmi N <[email protected]>; +Cc: [email protected]

Lakshmi N <[email protected]> 于2026年4月10日周五 16:39写道:

> Hi hackers,
>
> I noticed CFI is missing while scanning pg_class for RELKIND_RELATION and
> RELKIND_TOASTVALUE. On a database with several thousands of tables, these
> scans can take a noticeable amount of time. Attached a patch to address
> this.
>
> Regards,
> Lakshmi
>
Hi Lakshmi,

The patch applies cleanly to HEAD and compiles without warnings.
make check passes (one unrelated ICU collation diff).

The two CHECK_FOR_INTERRUPTS() additions in do_autovacuum() look
correct and are well-placed at the top of each loop iteration,
before any resources are acquired.

I noticed there are other similar catalog scan loops in
autovacuum.c that also lack CHECK_FOR_INTERRUPTS():

- The pg_database scan loop around line 1854
- The pg_class scan loop around line 3664

Should those be covered as well?

Regards,
Dapeng Wang


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
  2026-04-10 08:38 Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
  2026-04-10 11:57 ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
@ 2026-04-11 05:02   ` Lakshmi N <[email protected]>
  2026-04-11 12:19     ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Lakshmi N @ 2026-04-11 05:02 UTC (permalink / raw)
  To: Dapeng Wang <[email protected]>; +Cc: [email protected]

Hi,

On Fri, Apr 10, 2026 at 4:57 AM Dapeng Wang <[email protected]>
wrote:

> Lakshmi N <[email protected]> 于2026年4月10日周五 16:39写道:
>
>> Hi hackers,
>>
>> I noticed CFI is missing while scanning pg_class for RELKIND_RELATION and
>> RELKIND_TOASTVALUE. On a database with several thousands of tables, these
>> scans can take a noticeable amount of time. Attached a patch to address
>> this.
>>
>> Regards,
>> Lakshmi
>>
> Hi Lakshmi,
>
> The patch applies cleanly to HEAD and compiles without warnings.
> make check passes (one unrelated ICU collation diff).
>
> The two CHECK_FOR_INTERRUPTS() additions in do_autovacuum() look
> correct and are well-placed at the top of each loop iteration,
> before any resources are acquired.
>
> I noticed there are other similar catalog scan loops in
> autovacuum.c that also lack CHECK_FOR_INTERRUPTS():
>
> - The pg_database scan loop around line 1854
> - The pg_class scan loop around line 3664
>
> Should those be covered as well?
>

Updated the patch covering those two as well.


Regards,
Lakshmi

>


Attachments:

  [application/octet-stream] v2-0001-Add-CHECK_FOR_INTERRUPTS-in-autovacuum-table-scannin.patch (1.4K, 3-v2-0001-Add-CHECK_FOR_INTERRUPTS-in-autovacuum-table-scannin.patch)
  download | inline diff:
From d2d31987d2e479a8d92494644c183c8bd2f749b2 Mon Sep 17 00:00:00 2001
From: Lakshmi N <[email protected]>
Date: Fri, 10 Apr 2026 01:39:04 -0700
Subject: [PATCH] Add CHECK_FOR_INTERRUPTS in autovacuum table-scanning loops

---
 src/backend/postmaster/autovacuum.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 82061247988..5e36137925a 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -1859,6 +1859,8 @@ get_database_list(void)
 		avw_dbase  *avdb;
 		MemoryContext oldcxt;
 
+		CHECK_FOR_INTERRUPTS();
+
 		/*
 		 * If database has partially been dropped, we can't, nor need to,
 		 * vacuum it.
@@ -2042,6 +2044,8 @@ do_autovacuum(void)
 		bool		wraparound;
 		AutoVacuumScores scores;
 
+		CHECK_FOR_INTERRUPTS();
+
 		if (classForm->relkind != RELKIND_RELATION &&
 			classForm->relkind != RELKIND_MATVIEW)
 			continue;
@@ -2146,6 +2150,8 @@ do_autovacuum(void)
 		bool		wraparound;
 		AutoVacuumScores scores;
 
+		CHECK_FOR_INTERRUPTS();
+
 		/*
 		 * We cannot safely process other backends' temp tables, so skip 'em.
 		 */
@@ -3669,6 +3675,8 @@ pg_stat_get_autovacuum_scores(PG_FUNCTION_ARGS)
 		Datum		vals[10];
 		bool		nulls[10] = {false};
 
+		CHECK_FOR_INTERRUPTS();
+
 		/* skip ineligible entries */
 		if (form->relkind != RELKIND_RELATION &&
 			form->relkind != RELKIND_MATVIEW &&
-- 
2.43.0



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
  2026-04-10 08:38 Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
  2026-04-10 11:57 ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
  2026-04-11 05:02   ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
@ 2026-04-11 12:19     ` Dapeng Wang <[email protected]>
  2026-04-11 20:10       ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Sami Imseih <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Dapeng Wang @ 2026-04-11 12:19 UTC (permalink / raw)
  To: Lakshmi N <[email protected]>; +Cc: [email protected]

Lakshmi N <[email protected]> 于2026年4月11日周六 13:02写道:

> Hi,
>
> On Fri, Apr 10, 2026 at 4:57 AM Dapeng Wang <[email protected]>
> wrote:
>
>> Lakshmi N <[email protected]> 于2026年4月10日周五 16:39写道:
>>
>>> Hi hackers,
>>>
>>> I noticed CFI is missing while scanning pg_class for RELKIND_RELATION
>>> and RELKIND_TOASTVALUE. On a database with several thousands of tables,
>>> these scans can take a noticeable amount of time. Attached a patch to
>>> address this.
>>>
>>> Regards,
>>> Lakshmi
>>>
>> Hi Lakshmi,
>>
>> The patch applies cleanly to HEAD and compiles without warnings.
>> make check passes (one unrelated ICU collation diff).
>>
>> The two CHECK_FOR_INTERRUPTS() additions in do_autovacuum() look
>> correct and are well-placed at the top of each loop iteration,
>> before any resources are acquired.
>>
>> I noticed there are other similar catalog scan loops in
>> autovacuum.c that also lack CHECK_FOR_INTERRUPTS():
>>
>> - The pg_database scan loop around line 1854
>> - The pg_class scan loop around line 3664
>>
>> Should those be covered as well?
>>
>
> Updated the patch covering those two as well.
>
>
> Regards,
> Lakshmi
>


Hi Lakshmi,

The updated patch now covers all four catalog scan loops.
Applies cleanly, compiles without warnings, and all 247
regression tests pass.

Regards,
Dapeng Wang


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops
  2026-04-10 08:38 Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
  2026-04-10 11:57 ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
  2026-04-11 05:02   ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
  2026-04-11 12:19     ` Re: Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Dapeng Wang <[email protected]>
@ 2026-04-11 20:10       ` Sami Imseih <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Sami Imseih @ 2026-04-11 20:10 UTC (permalink / raw)
  To: Dapeng Wang <[email protected]>; +Cc: Lakshmi N <[email protected]>; [email protected]

Hi,

It was discussed [1] here if C_F_I is needed in these
do_autovacuum/autovacuum_scores code paths, and it
was decided not to add them.

Also, at least on my tests with 100k evern with 1 million tables, I did
not see a reason to do so. These are catalog scans that should
happen quick enough, even in extreme cases, to not make
this worthwhile.

Others may have another opinion.

--
Sami


[1] [https://www.postgresql.org/message-id/acwTxpz3Toxt0ty8%40nathan]





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-04-11 20:10 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-10 08:38 Add missing CHECK_FOR_INTERRUPTS in autovacuum catalog scan loops Lakshmi N <[email protected]>
2026-04-10 11:57 ` Dapeng Wang <[email protected]>
2026-04-11 05:02   ` Lakshmi N <[email protected]>
2026-04-11 12:19     ` Dapeng Wang <[email protected]>
2026-04-11 20:10       ` Sami Imseih <[email protected]>

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