diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index c9ae3b45b76..070ad2f13e7 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -689,8 +689,17 @@ pg_get_shmem_allocations_numa(PG_FUNCTION_ARGS)
                        CHECK_FOR_INTERRUPTS();
                }

-               if (pg_numa_query_pages(0, shm_ent_page_count, page_ptrs, pages_status) == -1)
-                       elog(ERROR, "failed NUMA pages inquiry status: %m");
+               #define NUMA_QUERY_CHUNK_SIZE 16  /* has to be <= DO_PAGES_STAT_CHUNK_NR (do_pages_stat())*/
+
+               for (uint64 chunk_start = 0; chunk_start < shm_ent_page_count; chunk_start += NUMA_QUERY_CHUNK_SIZE) {
+                        uint64 chunk_size = Min(NUMA_QUERY_CHUNK_SIZE, shm_ent_page_count - chunk_start);
+
+                       if (pg_numa_query_pages(0, chunk_size, &page_ptrs[chunk_start],
+                                                                       &pages_status[chunk_start]) == -1)
+                               elog(ERROR, "failed NUMA pages inquiry status: %m");
+               }
+
+               #undef NUMA_QUERY_CHUNK_SIZE

