]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make ShmemIndex visible in the pg_shmem_allocations view
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 1 Apr 2026 20:56:51 +0000 (23:56 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 1 Apr 2026 20:56:51 +0000 (23:56 +0300)
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Discussion: https://www.postgresql.org/message-id/01ab1d41-3eda-4705-8bbd-af898f5007f1@iki.fi

src/backend/storage/ipc/shmem.c

index 0e49debaaaca2eee360ce1e8965738b4513efedd..a5b7360e2dc8335156d4df4aa31de5193d87bd80 100644 (file)
@@ -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;
+       }
 }
 
 /*