[PATCH] Assertion in pg_get_shmem_pagesize() in single-user mode

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Assertion in pg_get_shmem_pagesize() in single-user mode
Date: 2026-09-20 23:51:00
Message-ID: CAJTYsWV-=w5_oFgCnfAixWGc=gMa2pkDinLyGLsb4sKcDaf2FA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While trying pg_buffercache in single-user mode, I noticed what looks
like an overly restrictive assertion in pg_get_shmem_pagesize(). With
pg_buffercache installed and the server stopped, I can reproduce this
on an assertion-enabled build:

$ postgres --single -D "$PGDATA" postgres
backend> SELECT pg_buffercache_os_pages(false) LIMIT 1;
TRAP: failed Assert("IsUnderPostmaster")

AFAICS, PostgresSingleUserMain() calls
CreateSharedMemoryAndSemaphores() before processing queries, so
huge_pages_status should already be initialized at this point.
However, IsUnderPostmaster is false in a standalone backend.

Could we drop that assertion and retain the existing
Assert(huge_pages_status != HUGE_PAGES_UNKNOWN)? That seems to check
the relevant precondition without excluding single-user mode. This
also doesn't appear specific to NUMA, since the query above requests
only OS-page mappings.

The attached patch removes the process-role assertion and adjusts the
comment to refer to shared-memory creation. The query seems to work
with this change in my local testing.

Does this look reasonable, or am I overlooking another reason for
the IsUnderPostmaster check?

Regards,
Ayush

Attachment Content-Type Size
v1-0001-Fix-shared-memory-page-size-assertion-in-single-user.patch application/x-patch 1.7 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message Adam Brusselback 2026-09-20 23:10:13 Re: [Patch] Add WHERE clause support to REFRESH MATERIALIZED VIEW