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 1pS769-0001Ob-1J for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Feb 2023 02:00:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pS765-00027g-Mt for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Feb 2023 02:00:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pS765-00027W-3c for pgsql-bugs@lists.postgresql.org; Wed, 15 Feb 2023 02:00:37 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pS762-0004gO-3M for pgsql-bugs@lists.postgresql.org; Wed, 15 Feb 2023 02:00:35 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 825E35F7BA; Tue, 14 Feb 2023 21:00:32 -0500 (EST) Date: Tue, 14 Feb 2023 21:00:32 -0500 From: Stephen Frost To: Joe Conway Cc: Tom Lane , Francisco Olarte , tom@quist.de, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17793: Query with large number of joins crashes PostgreSQL Message-ID: References: <17793-21fa598adbc21118@postgresql.org> <1682145.1676386040@sss.pgh.pa.us> <1975c07f-82a0-3503-e221-211b43878467@joeconway.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="J6u+Btf5EnSqFJFp" Content-Disposition: inline In-Reply-To: <1975c07f-82a0-3503-e221-211b43878467@joeconway.com> User-Agent: Mutt/2.1.4 (2021-12-11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --J6u+Btf5EnSqFJFp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Joe Conway (mail@joeconway.com) wrote: > On 2/14/23 09:47, Tom Lane wrote: > > Francisco Olarte writes: > > > On Tue, 14 Feb 2023 at 11:29, PG Bug reporting form > > > wrote: > > > > It looks like the OS is killing the process due to running OOM, whi= ch is not > > > > very surprising when looking at the query. Is this expected, or sho= uld PG > > > > have guards in place to prevent this from happening? > >=20 > > > When you run postgres in an environment where someone ( OOM killer ) > > > can K9 it, protection is hard. IIRC OOM can kill you because ANOTHER > > > process touches memory, among other things. > >=20 > > Yeah. We have no visibility into what the OOM killer will choose to > > allow or not allow at any instant. > >=20 > > > ( I do run DBs in machines w/ overcommit disabled, this prevents it > > > from happening, but it is not Pg who prevents it ). > >=20 > > If overcommit-disabled doesn't seem practical, another idea that's > > been recommended is to start the postmaster under a "ulimit -v" > > setting chosen to cause plain ENOMEM failures before the OOM > > killer kicks in. Unfortunately, that ends up being on a per-process basis and therefore isn't as useful as we'd like it to be (ideally, we'd allow all of the backends to allocate up until we hit some global "only use X amount of memory" instead). > Given: > > It looks like the OS is killing the process due to running OOM ... > > I could reproduce it using a fresh docker container of the image > > "postgres:13.10". >=20 > I gather the OP is running Postgres in a container. If so, and if they ha= ve > a memory.limit set (also assuming cgroup v1, otherwise memory.max for cgr= oup > v2), disabling overcommit at the host level will not prevent an OOM kill > when the cgroup exceeds memory.limit Indeed, we need a way to allow users to specify a limit which PG keeps track of and prevents PG from hitting the limit. There's work being done to both allow users to see how much memory each backend is using as well as tracking an overall allocation amount in shared memory across all processes, to allow us to decide to fail an allocation in a given backend instead of having the kernel decide to run the OOM killer. Further, once we're managing this, we can also make choices such as "keep X amount reserved for system processes like autovacuum" and "don't fail allocations for system processes like autovacuum" or such (just an example, not saying we necessarily want to do exactly that, but the point is that it's definitely nicer when we have control instead of getting hit with a memory allocation failure or worse the OOM killer deciding to kill -9 PG). Thanks, Stephen --J6u+Btf5EnSqFJFp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwf6gbxKhD863zrx/7WyKOINHZFUFAmPsPL0ACgkQ7WyKOINH ZFVQMA//RNqaIiGEKzfdFAadF98AVz8rjXguIos24uVd7lL7Qd2P1B5bc0jiPa0m dtxcODMuAD320oIGK1MWHffcxqkAwc9OdNyZNYcGHqMrLUmzACq6Fvgp9/iMScFZ LLjvB3RwGgJMA7e6+sITcVYIrjh2CLORZl8wtc6LKG5/QLFiP/ab2smumM3EGJAn iglCnJkNHIaSvZpciWlz52GkYrC6xJy5iBeKbvaLJ7qTwaEq5XnmwB6eKhclyFab SEjwBxxACOwL47Ob2xGNdGHZH5YxQMTB4uJjz42guxTgrTHHhRRr2Y/AN9Lk6hOg Q+ztJLJSXCc4CFBtNeWijB70cJTUhAqhWcx8uyKnZ0dVdkNwpoWq5Xf19Oe6xEdJ wDqhy/fx80Iazy44WaegWE10ZxTl2/8TdcDFaqesE43Ki5Vsl49Du7OF2KHUx0+Z 1kG0YgcBmJdeF+bnMCcZPr0SUw9EcyPPp0YpwGzaqnjaPK5uviiQYCy1EVA/WeCS 95dqYXojNicsOCiH9XxhTOULwrfk6m2Zjb6SXhsSs9rl/9bSVUsbXqTQiJ4rBD6y KmXrJjKsXoUaSJkewE70yWb5xW5gzRzzoZ6MCcVAcqK5BAsdw/XznDPVPcZOWvWI DuApz1oHb01W3ZE6gejsUewXsVKR+SusYS5B7l2KeR/okPUnKs4= =sZK2 -----END PGP SIGNATURE----- --J6u+Btf5EnSqFJFp--