From 1bdbb211bbf31b0024f000746c42326648ecde90 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 1 Apr 2026 23:56:51 +0300 Subject: [PATCH] Make ShmemIndex visible in the pg_shmem_allocations view Reviewed-by: Tomas Vondra Discussion: https://www.postgresql.org/message-id/01ab1d41-3eda-4705-8bbd-af898f5007f1@iki.fi --- src/backend/storage/ipc/shmem.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index 0e49debaaac..a5b7360e2dc 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -131,7 +131,7 @@ InitShmemAllocator(PGShmemHeader *seghdr) Size offset; HASHCTL info; int hash_flags; - size_t size; + size_t size = 0; #ifndef EXEC_BACKEND Assert(!IsUnderPostmaster); @@ -198,6 +198,22 @@ InitShmemAllocator(PGShmemHeader *seghdr) info.hctl = ShmemAllocator->index; ShmemIndex = hash_create("ShmemIndex", SHMEM_INDEX_SIZE, &info, hash_flags); Assert(ShmemIndex != NULL); + + /* + * Add an entry for ShmemIndex itself into ShmemIndex, so that it's + * visible in the pg_shmem_allocations view + */ + if (!IsUnderPostmaster) + { + bool found; + ShmemIndexEnt *result = (ShmemIndexEnt *) + hash_search(ShmemIndex, "ShmemIndex", HASH_ENTER, &found); + + Assert(!found); + result->size = size; + result->allocated_size = size; + result->location = ShmemAllocator->index; + } } /*