On 21/09/2026 02:51, Ayush Tiwari wrote:
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.

Agreed.

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?

+1. Committed, thanks!

- Heikki



Reply via email to