Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trNOp-002q59-Ub for pgsql-admin@arkaria.postgresql.org; Sun, 09 Mar 2025 20:37:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1trNOo-00DVik-3u for pgsql-admin@arkaria.postgresql.org; Sun, 09 Mar 2025 20:37:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1trNOn-00DVib-Bd for pgsql-admin@lists.postgresql.org; Sun, 09 Mar 2025 20:37:25 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1trNOk-001u3l-1Z for pgsql-admin@lists.postgresql.org; Sun, 09 Mar 2025 20:37:23 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e636585c375so1556531276.1 for ; Sun, 09 Mar 2025 13:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; t=1741552641; x=1742157441; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=DECHi1rDPUAgTX4LqChBK1KEwPomYmVepwpLYSK91VM=; b=Fv4+fX2r7eQhWjk2SIL7hf3MCZxqQaS+P56kJ3EkkS60yNmeXMl/Qh8eiqc9ku8lzc kFIVO3vArlPV3xeXpz7DN4tG/4nmewYggqS7JLSxNMLGGBr+3F+EHxQZxz9VWbZmec4F k/zqf36FeN8kD9+eLXeyqKYHgkpSf3H+S2bu/QRDNIISjKfZbkb2WXzIUPUnBxWgS73y /8oEJj59660UX9N4vKe0AZBlWhy+k1+5Pdl+/lnKtVIClDA2OiX5uS4jdQ1c4CTHtuT7 iUU3nOl9Zk31bf7olvDoPC3LeHOMHCDN9ypI3lWNOTPA6UwUHj8JJI0+8PAsOPfkLF0P 8ZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741552641; x=1742157441; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=DECHi1rDPUAgTX4LqChBK1KEwPomYmVepwpLYSK91VM=; b=NEXLrF9i9VrtoRTuvPhBNBnL+tdoDMBpbH5TA5+S/8S1+u4oKrn3f2B8wJRCznu87M 2uQrQxhPqDv6AL2ZWT2npeZERebm6hlDVHrcEUjOqegOYQ15iBqS/pLNoLFm5p3b90wa 3Snrc750M9gqLat8rgtGW4vowgIeDswoAms4FDMhKIXWvweVZFPK2i5yoKXjSXUGq5vW iYGICOib8J4yefxZLFcEwzJGlx2uTRbG61rRLBAZXcT8j88XIOAOr8lQfWQhP3dPrvEW 4GgLEiq8igRxRBXyFUyTxj7Lb2zuj7CMbDk4wbAcMD4FdACAl3cQCNRoGXzvt/CuzLsT su9Q== X-Gm-Message-State: AOJu0Yy4DGW1sOQkdBFZXAb3Z5SGm/UMPDWNU2QfKq5GKkXx7fyyAiV2 Y2wY/IiJz3B0AK4XI1smYJx/ijo8CEHgo1BiDFhbTIBb9zvK0o383D6Myfk5SVA= X-Gm-Gg: ASbGncvsydS/fKlYnMlzQal+djOBjs89vVhq4DUUjYWjtL8W2pfRvOQbodCvi/1w5wq UqONLN+ha2f6X+ukR7Ak485nbRmrm9lV7yminZTcJR+zJdBKWtWNxYFt3mEoT23Kg4epjsN+MHB jcRbZoX3n/NH+7i9mW8w/I4xdDocMwRdicfnvrGzpr2gsY/TQXCo2VKymyS5Eej2APx5GjK5HjK dnfZth1G22+ulFRe5RXAJ4Wo059K70B3WbU2sD2xb+kMF8/ZR1nOH62MDqkXyndqCaVN68GbKcm rDgwPFqPC/qcfVnpAuz//lyYZSv75FFwDCJs216UyZo+MIxpWwZPAymPgcibd/kyGILFMVpNmyg e1PYfntZEsNdsjIy/cq1/gulo X-Google-Smtp-Source: AGHT+IF0CrNV0ECDcac13XLCJMWu5jvFlRFVdkI7EVLDCBEfHhQ6x3hfvj6bVILprjFRgDktPxge6A== X-Received: by 2002:a05:6902:2e05:b0:e60:b011:5406 with SMTP id 3f1490d57ef6-e635c1e4bd0mr14879186276.43.1741552641550; Sun, 09 Mar 2025 13:37:21 -0700 (PDT) Received: from [192.168.4.41] (162-239-31-113.lightspeed.dybhfl.sbcglobal.net. [162.239.31.113]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e634b8fe22asm1872680276.51.2025.03.09.13.37.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Mar 2025 13:37:21 -0700 (PDT) Message-ID: Date: Sun, 9 Mar 2025 16:37:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Getting out ahead of OOM To: Tom Lane , Joseph Hammerman Cc: pgsql-admin@lists.postgresql.org References: <1117736.1741375563@sss.pgh.pa.us> Content-Language: en-US From: Joe Conway Autocrypt: addr=mail@joeconway.com; keydata= xsFNBEpXMCsBEADDnXUQzjlyi/cX02Gtdy2CLcroE5CsC7DJKdOBDbfgn0kfiIYoV5JniG4l VyzZUodY8yUAagqLYolh0UkBzs9N+qkm7erde4ypw3jzVQ37BuzIvk3nMUbuDZDgxWqX+nVS sKc+BQ5BpzgCHg48leoRO2ohjvYnUhgH3j2rFZCzaj6qQ7mv+XoxOJmUlVQtG06Jwkk7Vu14 7U9nMMM6hyUKzVnmCphnlcMNo26UyVU70MwFfFJgcI0c5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ERDH1PsvJNuevmQMzS0DWFav9+xMz9rKP4N+HffoBIZ E0C1xIE43nD4eLsbycte9sVIrmlNuUti3qUxJAQw8HwfJ6ZbBInHxquApR16uD1u99o6Xlnd FrDlY22tRmHCM0bR81GfGNdcU3Uo+rG/R/k4qa7s9/dgKvMbyH3fHhp/ceKag80Xo8IFurRl 0ZJP3sHJ2QDHCVLat7jRZ+43hi1WlIhFbrgn6IyI0i7XR/W8JjrC5MsKq4TUwGH077sU/kcH YebVJZRbUUst2hAGHDFVBcG12qoKf+ltL9qXJc1y7BGeCoUW6QjOpljpq6ZL4FQUsM0RSRjs 5egE3szPcIf5SyPK6WDOApoAq6M7BBFMGDZwEylYMtr0YekA1u86UA9D2xwLHEbBBp/uiby1 c9JbPJ1Pn8zJP8WZNeRw4Q9TtqVK09+oLirMUSpIDd6KdZ1VgRxOK2re7tjDvkVuYsSrsiJ+ 1iJNEnp9iK0ok0DlJpSCe6KhkxpaTdeoWMXdKuJWec0NIqoAd54ZgBPnr+UPxTixgPq/p6Q= In-Reply-To: <1117736.1741375563@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/7/25 14:26, Tom Lane wrote: > Joseph Hammerman writes: >> We run Postgres in a Kubernetes environment, and we have not to date been >> able to convince our Compute team to create a class of Kubernetes hosts >> that have memory overcommit disabled. > > :-( > >> Has anyone had success tracking all the Postgres memory allocation >> configurables and using that to administratively prevent OOMing? > > I doubt anyone has tried that. I would look into whether running > the postmaster under a suitable ulimit helps. I seem to recall > discussions that in Linux, "ulimit -v" works better than the other > likely-looking options. But that might be stale information. Problem with ulimit is that it is per process, but within a Kubernetes pod the memory accounting is for all the pod's processes. >> Alternatively, has anyone has success implementing an extension or periodic >> process to monitor the memory consumption of the Postgres children and >> killing them before the OOM event occurs? > > That's not going to be noticeably nicer than the kernel-induced > OOM, I think. The one thing it might do for you is ensure that > the kill happens to a child process and not the postmaster; but > you can already use PG_OOM_ADJUST_VALUE and PG_OOM_ADJUST_FILE > to manage that if it's a problem. (Recent kernels are alleged > to usually do the right thing without that, though.) Actually the problem here is likely that the Kubernetes Postgres pod was started with a memory limit. Disabling memory overcommit at the lost level will not help you if there is a memory limit set for the pod because that in turn sets memory.limit for the cgroup related to the pod and the oom killer will strike when memory.usage_in_bytes exceeds that value irrespective of the free memory at the host level. In these cases the oom_score_adj values don't end up mattering much. This is a fairly complex topic -- I wrote a blog a few years ago which may or may not be out of date at this point: https://www.crunchydata.com/blog/deep-postgresql-thoughts-the-linux-assassin Additionally Jeremy Schneider wrote a more recent one that you might find helpful: https://ardentperf.com/2024/09/22/kubernetes-requests-and-limits-for-postgres/ My quick and dirty recommendations: 1. Use cgroup v2 on the host if at all possible 2. Do not under any circumstances disable swap on the host. This is an anti-pattern unfortunately followed widely the last time I looked. 3. If nothing else, avoid setting a memory.limit on the cgroup. That will at least get you back to not getting whacked unless there is host level memory pressure. The blogs discuss how to do that with Kube pod settings. HTH, -- Joe Conway PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com