Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pxcdI-0002JS-M9 for pgsql-admin@arkaria.postgresql.org; Fri, 12 May 2023 23:57:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pxcdH-0008AK-Du for pgsql-admin@arkaria.postgresql.org; Fri, 12 May 2023 23:57:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pxcdG-0008AA-Vl for pgsql-admin@lists.postgresql.org; Fri, 12 May 2023 23:57:07 +0000 Received: from mail-yw1-x1129.google.com ([2607:f8b0:4864:20::1129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pxcdD-002Iuc-Er for pgsql-admin@lists.postgresql.org; Fri, 12 May 2023 23:57:06 +0000 Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-55a44a2637bso156006607b3.2 for ; Fri, 12 May 2023 16:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=evaristesys-com.20221208.gappssmtp.com; s=20221208; t=1683935822; x=1686527822; h=to:references:message-id:content-transfer-encoding:date:in-reply-to :from:subject:mime-version:from:to:cc:subject:date:message-id :reply-to; bh=E2zAulyAiImf5Lt1id1VEeL+nsq9YMS58MYq7I7A/iM=; b=2JhpU9jRIiSo6UX+xtAk1r4wZWlmLJKOu8RECzdkLTjj2+MrniOX3u94b1tT27SpZD j9w5MNxmDPoPDuLcq4EGEgtmtvM7BiUyhIUfrWU+9m3lzZ5AwSXJxGnR4YYrSid/9GhH doQ6yirKBHiC+MqRE5TL0oITZDVmHiN1gmJm77DTh7NMFUkqDaHcHcM52dl1ZhaawnYb AO1lK6g3jByQMvCsdBu8QCPgD3J9e1tND1ulvzWz+y7DW4hPJwC2Vh6LHLJpw+vRUnTB VsuAP7sqG+dumBdX+RcgUtZY1lCfSJy0riaiTYdUsD7b9nDRt4kXBPJz2OnU6bCVLwux PbGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683935822; x=1686527822; h=to:references:message-id:content-transfer-encoding:date:in-reply-to :from:subject:mime-version:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=E2zAulyAiImf5Lt1id1VEeL+nsq9YMS58MYq7I7A/iM=; b=Fv8/AY+kJuId5pqmeb3JodNi/tg+l1NFSzu9/Oyd49cIj1TMMIi/3MOY1g0/SwO3WQ s+ZrbunFVQwBW6Nor5nH05kp7AIP8SYQI7S2wJXNHUrnZpFDfEP/dBljKmlaR/0rsLci yQ1SV4qP17+MiEsufVipwuMtR3NgE4R7XtGJi9Ep029F5JSoZEyHPLFMCrGVbTQXJ328 mGZdhllC2Ib5557oDb1TEdcrvdBek1GOeKmsYrV1rCced6tRR4M3G7f1P1B1D0iqAmeG 5/1N9KzT3zcwwOFdpq09doQ5N5NbFq0nzN8O/qTYoc6KVfkm3BBLxZ2osU3we29YPgo2 ysig== X-Gm-Message-State: AC+VfDz44RB6WQ8EJP6non+rLV1eA4vElc8b8lPqumW5keXmTwkKBVr8 SQooGZMReOUwgURb7WgeyCebsPv2E+Lfu9lGZuk= X-Google-Smtp-Source: ACHHUZ4CUH5KV1nYBLr4at1ocyreojut4q5lnfoGQcM9pRBz9mUK13wCv3kgDTJBB1aEZ384ORswhQ== X-Received: by 2002:a81:6c89:0:b0:55a:4c03:1b91 with SMTP id h131-20020a816c89000000b0055a4c031b91mr23940920ywc.21.1683935821746; Fri, 12 May 2023 16:57:01 -0700 (PDT) Received: from smtpclient.apple (99-97-91-220.lightspeed.tukrga.sbcglobal.net. [99.97.91.220]) by smtp.gmail.com with ESMTPSA id o206-20020a0dccd7000000b0055a881abfc3sm6043155ywd.135.2023.05.12.16.57.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2023 16:57:01 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Subject: Re: Unexplained rapid growth in memory usage of idle backends From: Alex Balashov X-Priority: 3 In-Reply-To: <729198445.317848.1683934680067@office.mailbox.org> Date: Fri, 12 May 2023 19:56:50 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <7402BB66-E774-405D-8F75-86142239194F@evaristesys.com> References: <2D17E15D-8D5B-4DF7-A238-12455C2731D8@evaristesys.com> <729198445.317848.1683934680067@office.mailbox.org> To: Erik Wienhold , pgsql-admin X-Mailer: Apple Mail (2.3731.500.231) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 12, 2023, at 7:38 PM, Erik Wienhold wrote: >=20 >> On 13/05/2023 00:12 CEST Alex Balashov = wrote: >>=20 >> We have an application that has a preforked worker pool architecture = and >> opens a relatively large (70+) number of persistent connections to = PostgreSQL >> 14, and have `max_connections` set to 200 accordingly. >=20 > Which pg14 minor version exactly? # dpkg -l postgresql-14 Desired=3DUnknown/Install/Remove/Purge/Hold | = Status=3DNot/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-= pend |/ Err?=3D(none)/Reinst-required (Status,Err: uppercase=3Dbad) ||/ Name Version Architecture Description = +++-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D ii postgresql-14 14.4-1.pgdg110+1 amd64 The World's Most = Advanced Open Source Relational Database # psql -V psql (PostgreSQL) 14.4 (Debian 14.4-1.pgdg110+1) >=20 >> Occasionally, about once every 2 months, we'll get a slow-motion = implosion >> over a period of about 24 hours, where the resident memory size of = some of >> the backends shoots up from a reasonable few hundred MB to several = gigs -- >> and will keep growing, e.g. >>=20 >> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ = COMMAND >> 3932733 postgres 20 0 637740 327124 323840 R 10.7 0.5 = 0:00.11 postgres >> 782930 postgres 20 0 3151360 2.8g 551704 S 9.7 4.5 221:43.17 = postgres >> 782839 postgres 20 0 2999896 2.7g 551832 S 8.7 4.3 220:54.55 = postgres >> 3932734 postgres 20 0 636128 338168 336096 R 8.7 0.5 = 0:00.09 postgres >> 3932735 postgres 20 0 636128 319824 317768 R 8.7 0.5 = 0:00.09 postgres >> 782851 postgres 20 0 3142152 2.8g 551872 S 7.8 4.5 221:22.62 = postgres >> 782855 postgres 20 0 3155144 2.8g 551828 S 7.8 4.5 221:38.59 = postgres >> 782897 postgres 20 0 3148808 2.8g 551724 S 7.8 4.5 220:05.94 = postgres >> 783106 postgres 20 0 3152416 2.8g 551912 S 7.8 4.5 221:24.40 = postgres >> 783168 postgres 20 0 2992592 2.7g 551968 S 7.8 4.2 220:36.06 = postgres >> 782843 postgres 20 0 3146772 2.8g 551944 R 4.9 4.5 221:38.46 = postgres >> 782778 postgres 20 0 3150956 2.8g 551852 R 3.9 4.5 220:49.88 = postgres >=20 > Function pg_log_backend_memory_contexts(pid int) may give you some = insights on > on the memory allocation for specific backends. >=20 > = https://www.postgresql.org/docs/14/functions-admin.html#FUNCTIONS-ADMIN-SI= GNAL-TABLE Ah, thanks! 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 3; = CachedPlanQuery: 2048 total in 2 blocks; 552 free (0 chunks); 1496 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 2; SPI = Plan: 1024 total in 1 blocks; 600 free (0 chunks); 424 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; 828 = more child contexts containing 2714624 total in 2097 blocks; 899280 free = (329 chunks); 1815344 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; WAL = record construction: 49768 total in 2 blocks; 6360 free (0 chunks); = 43408 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; = PrivateRefCount: 8192 total in 1 blocks; 2616 free (0 chunks); 5576 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; = MdSmgr: 8192 total in 1 blocks; 5640 free (1 chunks); 2552 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; = LOCALLOCK hash: 16384 total in 2 blocks; 4592 free (2 chunks); 11792 = used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; = Timezones: 104120 total in 2 blocks; 2616 free (0 chunks); 101504 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: level: 1; = ErrorContext: 8192 total in 1 blocks; 7928 free (5 chunks); 264 used 2023-05-12 23:53:23.293 UTC [3934125] eti_adm@eti LOG: Grand total: = 6417232 bytes in 2461 blocks; 2409920 free (468 chunks); 4007312 used But what can I learn from this that might be of applied value? -- Alex --=20 Alex Balashov Principal Consultant Evariste Systems LLC Web: https://evaristesys.com Tel: +1-706-510-6800