From 66a94156a75cf4bf23d08d5ee7b6c5e40fce0459 Mon Sep 17 00:00:00 2001 From: serprex <159546+serprex@users.noreply.github.com> Date: Tue, 14 Jul 2026 14:31:25 +0000 Subject: [PATCH 1/2] mallopt(M_ARENA_MAX, 4) --- src/worker/bgworker.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/worker/bgworker.c b/src/worker/bgworker.c index 97a61a0..aa1a323 100644 --- a/src/worker/bgworker.c +++ b/src/worker/bgworker.c @@ -38,6 +38,9 @@ #include "queue/shmem.h" #include +#ifdef __GLIBC__ +#include +#endif #include "config/guc.h" #include "export/stats_exporter.h" @@ -182,6 +185,11 @@ static void RunExportCycle(uint32 wait_event) { } void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { +#ifdef __GLIBC__ + // Set before gRPC/Arrow spawn threads, greatly reduces virtual memory usage. + // 4 is minimum grpc pool size. + mallopt(M_ARENA_MAX, 4); +#endif SetupSignalHandlers(); BackgroundWorkerUnblockSignals(); BackgroundWorkerInitializeConnection("postgres", NULL, 0); From 62e45bddf72dbcb1cc478540265d8d15bfaf33f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= <159546+serprex@users.noreply.github.com> Date: Tue, 14 Jul 2026 15:03:19 +0000 Subject: [PATCH 2/2] DEBUG1 Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/worker/bgworker.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/worker/bgworker.c b/src/worker/bgworker.c index aa1a323..f5b2f82 100644 --- a/src/worker/bgworker.c +++ b/src/worker/bgworker.c @@ -186,9 +186,10 @@ static void RunExportCycle(uint32 wait_event) { void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { #ifdef __GLIBC__ - // Set before gRPC/Arrow spawn threads, greatly reduces virtual memory usage. - // 4 is minimum grpc pool size. - mallopt(M_ARENA_MAX, 4); + // Set before any gRPC/Arrow threads are created; cap glibc malloc arenas to reduce virtual memory usage. + if (mallopt(M_ARENA_MAX, 4) == 0) { + elog(DEBUG1, "pg_stat_ch: mallopt(M_ARENA_MAX, 4) failed"); + } #endif SetupSignalHandlers(); BackgroundWorkerUnblockSignals();