postgres.git / summary / log / commit / refs

commit    4d6ff8a051a13b7c86255ff5d83ff2aa0dce302a
Author:   Fujii Masao <fujii@postgresql.org>
Date:     Wed Nov 18 07:07:52 2026 +0000

    Fix temporary relation I/O statistics in single-user mode
    
    Accessing temporary relations in single-user mode could trigger an
    assertion failure in assertion-enabled builds. For example, CREATE
    TEMP TABLE AS and CREATE TEMP SEQUENCE failed when recording relation
    extension statistics. Without assertions, the statistics were still
    collected internally but were not exposed in pg_stat_io.
    
    The problem was that pgstat_tracks_io_object() incorrectly excluded
    standalone backends from I/O tracking for temporary relations, even
    though they use local buffers just like regular client backends.
    
    Remove this exclusion to prevent the assertion failures and make the
    statistics visible in pg_stat_io.
    
    Backpatch to v16, where the incorrect exclusion was introduced in
    commit 28e626bde00.
    
    Author: Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
    Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
    Discussion: https://postgr.es/m/179487554022.104798.7544124224648387746@gmail.com
    Backpatch-through: 16


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 13ae57ed649..d3ffca6c24b 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 37df27351d8..fa35ea3d296 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; [parent: 94fc1c08f5f7]