pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Assertion failure with temporary relations in single-user mode
6+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2026-11-18 45047c51aa 079619ae93 4d6ff8a051 e9b2d85c14 c475754aa1  Fix temporary relation I/O statistics in single-user mode
* Assertion failure with temporary relations in single-user mode
@ 2026-11-17 00:32 Manu <manuelreyesbravo@gmail.com>
  2026-11-17 04:41 ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Manu @ 2026-11-17 00:32 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; +Cc: pgsql-hackers@lists.postgresql.org

Hi,

With assertions enabled, single-user mode fails an assertion as soon
as a temporary relation is read or written through local buffers,
from v16 to master:

$ echo "CREATE TEMP TABLE t AS SELECT 1;" | postgres --single postgres
TRAP: failed Assert("pgstat_tracks_io_op(MyBackendType, ...)")

28e626bde00 put B_STANDALONE_BACKEND in no_temp_rel, in
pgstat_tracks_io_object(), but a single-user backend uses local
buffers like a client backend.  Without assertions, that IO is not
counted: pg_stat_io has no "temp relation" row for it.

Patch with a test attached; the test also fails without assertions.
The back branches need small adjustments; tested on 16 to 19.

Regards,
Manu

Attachments:

v1-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 6.5K) download From ba7dee43c85f62517d59128ee6be788f1fd86fa8 Mon Sep 17 00:00:00 2001 From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com> Date: Mon, 16 Nov 2026 21:16:54 -0300 Subject: [PATCH v1] 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. A TAP test runs these commands in single-user mode, with a temporary table larger than temp_buffers so as local buffers are evicted, written and read back, then checks pg_stat_io once the server is started. Discussion: --- src/backend/utils/activity/pgstat_io.c | 14 ++-- src/test/modules/test_misc/meson.build | 1 + .../test_misc/t/016_single_user_temp_io.pl | 79 +++++++++++++++++++ src/test/regress/expected/stats.out | 3 +- 4 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 src/test/modules/test_misc/t/016_single_user_temp_io.pl diff --git a/src/backend/utils/activity/pgstat_io.c b/src/backend/utils/activity/pgstat_io.c index 3c8fcb20..cec57596 100644 --- a/src/backend/utils/activity/pgstat_io.c +++ b/src/backend/utils/activity/pgstat_io.c @@ -413,16 +413,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/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build index 5d81f5b1..f1750847 100644 --- a/src/test/modules/test_misc/meson.build +++ b/src/test/modules/test_misc/meson.build @@ -24,6 +24,7 @@ tests += { 't/013_temp_obj_multisession.pl', 't/014_log_statement_max_length.pl', 't/015_temp_schema_exit_deferrable.pl', + 't/016_single_user_temp_io.pl', ], # The injection points are cluster-wide, so disable installcheck 'runningcheck': false, diff --git a/src/test/modules/test_misc/t/016_single_user_temp_io.pl b/src/test/modules/test_misc/t/016_single_user_temp_io.pl new file mode 100644 index 00000000..cc9a7386 --- /dev/null +++ b/src/test/modules/test_misc/t/016_single_user_temp_io.pl @@ -0,0 +1,79 @@ +# Copyright (c) 2026, PostgreSQL Global Development Group + +# Check that a backend in single-user mode can do IO on temporary relations, +# and that this IO is reported in pg_stat_io. + +use strict; +use warnings FATAL => 'all'; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +# Skip the tests on Windows, as single-user mode would fail on permission +# failure with privileged accounts. +if ($windows_os) +{ + plan skip_all => 'this test is not supported by this platform'; +} + +# Run set of queries in single-user mode. +sub test_single_mode +{ + my ($node, $queries, $testname) = @_; + + my $result = run_log( + [ + 'postgres', '--single', '-F', + '-c' => 'exit_on_error=true', + '-D' => $node->data_dir, + 'postgres' + ], + '<' => \$queries); + + ok($result, $testname); +} + +my $node = PostgreSQL::Test::Cluster->new('node'); +$node->init; + +test_single_mode( + $node, qq( +CREATE TEMP TABLE temp_insert (a int); +INSERT INTO temp_insert VALUES (1); +), + "INSERT into temporary table"); +test_single_mode( + $node, + "CREATE TEMP TABLE temp_ctas AS SELECT 1 AS a;", + "CREATE TEMP TABLE AS"); +test_single_mode( + $node, qq( +CREATE TEMP SEQUENCE temp_seq; +SELECT nextval('temp_seq'); +), + "nextval() on temporary sequence"); + +# A temporary table larger than temp_buffers, so as local buffers are +# evicted, written and read back. +test_single_mode( + $node, qq( +SET temp_buffers = 100; +CREATE TEMP TABLE temp_big AS SELECT g AS a, repeat('x', 100) AS b FROM generate_series(1, 20000) g; +SELECT count(*) FROM temp_big; +), + "temporary table larger than temp_buffers"); + +# The IO done on temporary relations by the standalone backend is visible +# once the server is started. +$node->start; +my $result = $node->safe_psql( + 'postgres', qq( +SELECT extends > 0, reads > 0, writes > 0, evictions > 0, hits > 0 + FROM pg_stat_io + WHERE backend_type = 'standalone backend' AND + object = 'temp relation' AND context = 'normal')); +is($result, 't|t|t|t|t', + "IO on temporary relations of standalone backend in pg_stat_io"); +$node->stop; + +done_testing(); diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out index 8b154712..b1935882 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -81,6 +81,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 @@ -104,7 +105,7 @@ walsummarizer|wal|init walsummarizer|wal|normal walwriter|wal|init walwriter|wal|normal -(88 rows) +(89 rows) \a -- List of registered statistics kinds. SELECT id, name, fixed_amount, -- 2.56.1
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Assertion failure with temporary relations in single-user mode
  2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
@ 2026-11-17 04:41 ` Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 05:10   ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Fujii Masao @ 2026-11-17 04:41 UTC (permalink / raw)
  To: Manu <manuelreyesbravo@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; pgsql-hackers@lists.postgresql.org

On Tue, Nov 17, 2026 at 9:32 AM Manu <manuelreyesbravo@gmail.com> wrote:
> Patch with a test attached; the test also fails without assertions.

Thanks for the report and patch!
The fix in pgstat_io.c seems good to me.

I wonder if adding a new TAP test file might be overkill for this fix.
Several similar fixes for assertion failures in single-user mode have
not included tests.

Using temporary tables in single-user mode seems uncommon,
so I'm not sure a dedicated test provides enough value to justify
the additional test runtime.

Regards,


-- 
Fujii Masao






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

* Re: Assertion failure with temporary relations in single-user mode
  2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 04:41 ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
@ 2026-11-17 05:10   ` Manu <manuelreyesbravo@gmail.com>
  2026-11-17 07:15     ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Manu @ 2026-11-17 05:10 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; pgsql-hackers@lists.postgresql.org

Hi Fujii,

On Tue, Nov 17, 2026 at 1:41 PM Fujii Masao
<masao.fujii@gmail.com> wrote:
> I wonder if adding a new TAP test file might be overkill for this fix.

Agreed.  v2, attached, drops it and keeps only the fix in pgstat_io.c,
plus the new row in the stats regression test's list of pg_stat_io
rows.

The code change is the same down to 16.  The stats.out hunk differs
on 18 and 19, and 16 and 17 have no such list; I can post those
versions if they help.

Regards,
Manu

Attachments:

v2-0001-Fix-IO-tracking-of-temporary-relations-in-single-.patch (text/x-patch, 3.4K) download From 513420daf42d8df4542a94d82be963902c2e9fd6 Mon Sep 17 00:00:00 2001 From: Manuel Reyes Bravo <manuelreyesbravo@gmail.com> Date: Mon, 16 Nov 2026 21:16:54 -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.c index 3c8fcb20..cec57596 100644 --- a/src/backend/utils/activity/pgstat_io.c +++ b/src/backend/utils/activity/pgstat_io.c @@ -413,16 +413,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.out index 8b154712..b1935882 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -81,6 +81,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 @@ -104,7 +105,7 @@ walsummarizer|wal|init walsummarizer|wal|normal walwriter|wal|init walwriter|wal|normal -(88 rows) +(89 rows) \a -- List of registered statistics kinds. SELECT id, name, fixed_amount, -- 2.56.1
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Assertion failure with temporary relations in single-user mode
  2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 04:41 ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 05:10   ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
@ 2026-11-17 07:15     ` Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 21:40       ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Fujii Masao @ 2026-11-17 07:15 UTC (permalink / raw)
  To: Manu <manuelreyesbravo@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; pgsql-hackers@lists.postgresql.org

On Tue, Nov 17, 2026 at 2:10 PM Manu <manuelreyesbravo@gmail.com> wrote:
> The code change is the same down to 16.  The stats.out hunk differs
> on 18 and 19, and 16 and 17 have no such list; I can post those
> versions if they help.

Yes, it's helpful if you provide the patches for those versions. Thanks!

Regards,

-- 
Fujii Masao






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

* Re: Assertion failure with temporary relations in single-user mode
  2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 04:41 ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 05:10   ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 07:15     ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
@ 2026-11-17 21:40       ` Manu <manuelreyesbravo@gmail.com>
  2026-11-18 07:13         ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Manu @ 2026-11-17 21:40 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; pgsql-hackers@lists.postgresql.org

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.c index 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.c index 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.c index 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.out index 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.c index 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.out index 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
^ permalink raw reply [nested|flat] 6+ messages in thread

* Re: Assertion failure with temporary relations in single-user mode
  2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 04:41 ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 05:10   ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
  2026-11-17 07:15     ` Re: Assertion failure with temporary relations in single-user mode Fujii Masao <masao.fujii@gmail.com>
  2026-11-17 21:40       ` Re: Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
@ 2026-11-18 07:13         ` Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Fujii Masao @ 2026-11-18 07:13 UTC (permalink / raw)
  To: Manu <manuelreyesbravo@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Melanie Plageman <melanieplageman@gmail.com>; pgsql-hackers@lists.postgresql.org

On Wed, Nov 18, 2026 at 6:41 AM Manu <manuelreyesbravo@gmail.com> wrote:
> Attached for 16, 17, 18 and 19.

Thanks for the patches! I've pushed them.

Regards,

-- 
Fujii Masao






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


end of thread, other threads:[~2026-11-18 07:13 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 00:32 Assertion failure with temporary relations in single-user mode Manu <manuelreyesbravo@gmail.com>
2026-11-17 04:41 ` Fujii Masao <masao.fujii@gmail.com>
2026-11-17 05:10   ` Manu <manuelreyesbravo@gmail.com>
2026-11-17 07:15     ` Fujii Masao <masao.fujii@gmail.com>
2026-11-17 21:40       ` Manu <manuelreyesbravo@gmail.com>
2026-11-18 07:13         ` Fujii Masao <masao.fujii@gmail.com>

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