From: Manu <manuelreyesbravo@gmail.com>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Melanie Plageman <melanieplageman@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Assertion failure with temporary relations in single-user mode
Date: Tue, 17 Nov 2026 18:40:47 -0300
Message-ID: <179495164701.1836133.8159158009811818811@gmail.com> (raw)
In-Reply-To: <CAHGQGwGteJra-o0F7rrEyzCxecfDJvzczbPtUJht9pFJN4B9Mg@mail.gmail.com>
References: <CAHGQGwGteJra-o0F7rrEyzCxecfDJvzczbPtUJht9pFJN4B9Mg@mail.gmail.com>
Hi Fujii,
On Tue, Nov 17, 2026 at 4:15 PM Fujii Masao
<masao.fujii@gmail.com> wrote:
> Yes, it's helpful if you provide the patches for those versions.
> Thanks!
Attached for 16, 17, 18 and 19. The change to pgstat_io.c is the
same in all four; 18 and 19 also add the row to stats.out, and 16
and 17 have no such list. Each applies with git am on its branch as
of today and passes check-world with assertions enabled. For master,
v2 upthread is unchanged.
Regards,
Manu
Attachments:download all (4 files, .tar.gz)v2-REL_16-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 2.6K) download
From 907c204620d8ef1ddbe6ea07cd31a208357c0921 Mon Sep 17 00:00:00 2001
From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Date: Tue, 17 Nov 2026 16:35:43 -0300
Subject: [PATCH v2] Fix IO tracking of temporary relations in single-user mode
pgstat_tracks_io_object() lists B_STANDALONE_BACKEND among the backend
types that never do IO on temporary relations, since 28e626bde00 (v16).
A backend in single-user mode executes queries like a client backend,
and can create and use temporary tables and sequences. With assertions
enabled, an INSERT into a temporary table, CREATE TEMP TABLE AS or
nextval() on a temporary sequence fails the assertion in
pgstat_count_io_op():
$ echo "CREATE TEMP TABLE t AS SELECT 1;" | postgres --single postgres
TRAP: failed Assert("pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op)")
Without assertions, this IO is not counted: pg_stat_io has no
"temp relation" row for "standalone backend".
Remove B_STANDALONE_BACKEND from this list, and fix the comment above
it.
Discussion:
---
src/backend/utils/activity/pgstat_io.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.cindex 8ec8670199..683b060543 100644--- a/src/backend/utils/activity/pgstat_io.c+++ b/src/backend/utils/activity/pgstat_io.c@@ -359,16 +359,16 @@ pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
return false;
/*
- * In core Postgres, only regular backends and WAL Sender processes- * executing queries will use local buffers and operate on temporary- * relations. Parallel workers will not use local buffers (see- * InitLocalBuffers()); however, extensions leveraging background workers- * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for- * BackendType B_BG_WORKER.+ * In core Postgres, only regular backends, WAL Sender processes executing+ * queries and standalone backends (single-user mode) will use local+ * buffers and operate on temporary relations. Parallel workers will not+ * use local buffers (see InitLocalBuffers()); however, extensions+ * leveraging background workers have no such limitation, so track IO on+ * IOOBJECT_TEMP_RELATION for BackendType B_BG_WORKER.
*/
no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
- bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP;+ bktype == B_STARTUP;
if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
io_object == IOOBJECT_TEMP_RELATION)
--
2.56.1
v2-REL_17-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 2.6K) download
From a78b5d691cb7abb7819c39ca1a58c34e85295fd7 Mon Sep 17 00:00:00 2001
From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Date: Tue, 17 Nov 2026 16:35:43 -0300
Subject: [PATCH v2] Fix IO tracking of temporary relations in single-user mode
pgstat_tracks_io_object() lists B_STANDALONE_BACKEND among the backend
types that never do IO on temporary relations, since 28e626bde00 (v16).
A backend in single-user mode executes queries like a client backend,
and can create and use temporary tables and sequences. With assertions
enabled, an INSERT into a temporary table, CREATE TEMP TABLE AS or
nextval() on a temporary sequence fails the assertion in
pgstat_count_io_op():
$ echo "CREATE TEMP TABLE t AS SELECT 1;" | postgres --single postgres
TRAP: failed Assert("pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op)")
Without assertions, this IO is not counted: pg_stat_io has no
"temp relation" row for "standalone backend".
Remove B_STANDALONE_BACKEND from this list, and fix the comment above
it.
Discussion:
---
src/backend/utils/activity/pgstat_io.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.cindex 9d6e067382..8293949874 100644--- a/src/backend/utils/activity/pgstat_io.c+++ b/src/backend/utils/activity/pgstat_io.c@@ -376,16 +376,16 @@ pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
return false;
/*
- * In core Postgres, only regular backends and WAL Sender processes- * executing queries will use local buffers and operate on temporary- * relations. Parallel workers will not use local buffers (see- * InitLocalBuffers()); however, extensions leveraging background workers- * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for- * BackendType B_BG_WORKER.+ * In core Postgres, only regular backends, WAL Sender processes executing+ * queries and standalone backends (single-user mode) will use local+ * buffers and operate on temporary relations. Parallel workers will not+ * use local buffers (see InitLocalBuffers()); however, extensions+ * leveraging background workers have no such limitation, so track IO on+ * IOOBJECT_TEMP_RELATION for BackendType B_BG_WORKER.
*/
no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
- bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP;+ bktype == B_STARTUP;
if (no_temp_rel && io_context == IOCONTEXT_NORMAL &&
io_object == IOOBJECT_TEMP_RELATION)
--
2.56.1
v2-REL_18-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 3.4K) download
From 8c3413d86099568b6542da774c2d7a904de7484e Mon Sep 17 00:00:00 2001
From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Date: Tue, 17 Nov 2026 16:35:43 -0300
Subject: [PATCH v2] Fix IO tracking of temporary relations in single-user mode
pgstat_tracks_io_object() lists B_STANDALONE_BACKEND among the backend
types that never do IO on temporary relations, since 28e626bde00 (v16).
A backend in single-user mode executes queries like a client backend,
and can create and use temporary tables and sequences. With assertions
enabled, an INSERT into a temporary table, CREATE TEMP TABLE AS or
nextval() on a temporary sequence fails the assertion in
pgstat_count_io_op():
$ echo "CREATE TEMP TABLE t AS SELECT 1;" | postgres --single postgres
TRAP: failed Assert("pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op)")
Without assertions, this IO is not counted: pg_stat_io has no
"temp relation" row for "standalone backend".
Remove B_STANDALONE_BACKEND from this list, and fix the comment above
it. The regression test that lists the rows of pg_stat_io gains that
row.
Discussion:
---
src/backend/utils/activity/pgstat_io.c | 14 +++++++-------
src/test/regress/expected/stats.out | 3 ++-
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.cindex 13ae57ed64..d3ffca6c24 100644--- a/src/backend/utils/activity/pgstat_io.c+++ b/src/backend/utils/activity/pgstat_io.c@@ -419,16 +419,16 @@ pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
return false;
/*
- * In core Postgres, only regular backends and WAL Sender processes- * executing queries will use local buffers and operate on temporary- * relations. Parallel workers will not use local buffers (see- * InitLocalBuffers()); however, extensions leveraging background workers- * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for- * BackendType B_BG_WORKER.+ * In core Postgres, only regular backends, WAL Sender processes executing+ * queries and standalone backends (single-user mode) will use local+ * buffers and operate on temporary relations. Parallel workers will not+ * use local buffers (see InitLocalBuffers()); however, extensions+ * leveraging background workers have no such limitation, so track IO on+ * IOOBJECT_TEMP_RELATION for BackendType B_BG_WORKER.
*/
no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
- bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP ||+ bktype == B_STARTUP ||
bktype == B_WAL_SUMMARIZER || bktype == B_WAL_WRITER ||
bktype == B_WAL_RECEIVER;
diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.outindex 37df27351d..fa35ea3d29 100644--- a/src/test/regress/expected/stats.out+++ b/src/test/regress/expected/stats.out@@ -72,6 +72,7 @@ standalone backend|relation|bulkwrite
standalone backend|relation|init
standalone backend|relation|normal
standalone backend|relation|vacuum
+standalone backend|temp relation|normal
standalone backend|wal|init
standalone backend|wal|normal
startup|relation|bulkread
@@ -95,7 +96,7 @@ walsummarizer|wal|init
walsummarizer|wal|normal
walwriter|wal|init
walwriter|wal|normal
-(79 rows)+(80 rows)
\a
-- ensure that both seqscan and indexscan plans are allowed
SET enable_seqscan TO on;
--
2.56.1
v2-REL_19-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 3.4K) download
From 2a6c3c7af65afcb90b78bfc7230283bb6ddd07b2 Mon Sep 17 00:00:00 2001
From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Date: Tue, 17 Nov 2026 16:35:43 -0300
Subject: [PATCH v2] Fix IO tracking of temporary relations in single-user mode
pgstat_tracks_io_object() lists B_STANDALONE_BACKEND among the backend
types that never do IO on temporary relations, since 28e626bde00 (v16).
A backend in single-user mode executes queries like a client backend,
and can create and use temporary tables and sequences. With assertions
enabled, an INSERT into a temporary table, CREATE TEMP TABLE AS or
nextval() on a temporary sequence fails the assertion in
pgstat_count_io_op():
$ echo "CREATE TEMP TABLE t AS SELECT 1;" | postgres --single postgres
TRAP: failed Assert("pgstat_tracks_io_op(MyBackendType, io_object, io_context, io_op)")
Without assertions, this IO is not counted: pg_stat_io has no
"temp relation" row for "standalone backend".
Remove B_STANDALONE_BACKEND from this list, and fix the comment above
it. The regression test that lists the rows of pg_stat_io gains that
row.
Discussion:
---
src/backend/utils/activity/pgstat_io.c | 14 +++++++-------
src/test/regress/expected/stats.out | 3 ++-
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.cindex ae52baafd1..49571235e4 100644--- a/src/backend/utils/activity/pgstat_io.c+++ b/src/backend/utils/activity/pgstat_io.c@@ -411,16 +411,16 @@ pgstat_tracks_io_object(BackendType bktype, IOObject io_object,
return false;
/*
- * In core Postgres, only regular backends and WAL Sender processes- * executing queries will use local buffers and operate on temporary- * relations. Parallel workers will not use local buffers (see- * InitLocalBuffers()); however, extensions leveraging background workers- * have no such limitation, so track IO on IOOBJECT_TEMP_RELATION for- * BackendType B_BG_WORKER.+ * In core Postgres, only regular backends, WAL Sender processes executing+ * queries and standalone backends (single-user mode) will use local+ * buffers and operate on temporary relations. Parallel workers will not+ * use local buffers (see InitLocalBuffers()); however, extensions+ * leveraging background workers have no such limitation, so track IO on+ * IOOBJECT_TEMP_RELATION for BackendType B_BG_WORKER.
*/
no_temp_rel = bktype == B_AUTOVAC_LAUNCHER || bktype == B_BG_WRITER ||
bktype == B_CHECKPOINTER || bktype == B_AUTOVAC_WORKER ||
- bktype == B_STANDALONE_BACKEND || bktype == B_STARTUP ||+ bktype == B_STARTUP ||
bktype == B_WAL_SUMMARIZER || bktype == B_WAL_WRITER ||
bktype == B_WAL_RECEIVER;
diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.outindex 7dcd678259..6803eba8f3 100644--- a/src/test/regress/expected/stats.out+++ b/src/test/regress/expected/stats.out@@ -72,6 +72,7 @@ standalone backend|relation|bulkwrite
standalone backend|relation|init
standalone backend|relation|normal
standalone backend|relation|vacuum
+standalone backend|temp relation|normal
standalone backend|wal|init
standalone backend|wal|normal
startup|relation|bulkread
@@ -95,7 +96,7 @@ walsummarizer|wal|init
walsummarizer|wal|normal
walwriter|wal|init
walwriter|wal|normal
-(79 rows)+(80 rows)
\a
-- ensure that both seqscan and indexscan plans are allowed
SET enable_seqscan TO on;
--
2.56.1
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: manuelreyesbravo@gmail.com, masao.fujii@gmail.com, michael@paquier.xyz, melanieplageman@gmail.com
Subject: Re: Assertion failure with temporary relations in single-user mode
In-Reply-To: <179495164701.1836133.8159158009811818811@gmail.com>
References: <CAHGQGwGteJra-o0F7rrEyzCxecfDJvzczbPtUJht9pFJN4B9Mg@mail.gmail.com> <179495164701.1836133.8159158009811818811@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox