diff --git a/src/worker/bgworker.c b/src/worker/bgworker.c index 97a61a0..f5b2f82 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,12 @@ static void RunExportCycle(uint32 wait_event) { } void PschBgworkerMain(Datum main_arg pg_attribute_unused()) { +#ifdef __GLIBC__ + // 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(); BackgroundWorkerInitializeConnection("postgres", NULL, 0);