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 1pbob8-0006Pe-T0 for pgsql-general@arkaria.postgresql.org; Mon, 13 Mar 2023 20:16:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbob7-0003Ve-P6 for pgsql-general@arkaria.postgresql.org; Mon, 13 Mar 2023 20:16:45 +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 1pbob7-0003VU-EQ for pgsql-general@lists.postgresql.org; Mon, 13 Mar 2023 20:16:45 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pboaz-00034n-I0 for pgsql-general@lists.postgresql.org; Mon, 13 Mar 2023 20:16:45 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id E8AB61C235; Mon, 13 Mar 2023 21:16:29 +0100 (CET) Date: Mon, 13 Mar 2023 21:16:29 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Properly handle OOM death? Message-ID: <20230313201629.5d6nkptfxy3qs5fr@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <20230313174301.23n6crb5dpttozup@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4itbbsofw2yq2hus" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4itbbsofw2yq2hus Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-03-13 09:55:50 -0800, Israel Brewster wrote: > On Mar 13, 2023, at 9:43 AM, Peter J. Holzer wrote: > > On 2023-03-13 09:21:18 -0800, Israel Brewster wrote: > >> I=E2=80=99m running a postgresql 13 database on an Ubuntu 20.04 VM tha= t is a bit more > >> memory constrained than I would like, such that every week or so the v= arious > >> processes running on the machine will align badly and the OOM killer w= ill kick > >> in, killing off postgresql, as per the following journalctl output: > >>=20 > >> Mar 12 04:04:23 novarupta systemd[1]: postgresql@13-main.service: A pr= ocess of > >> this unit has been killed by the OOM killer. > >> Mar 12 04:04:32 novarupta systemd[1]: postgresql@13-main.service: Fail= ed with > >> result 'oom-kill'. > >> Mar 12 04:04:32 novarupta systemd[1]: postgresql@13-main.service: Cons= umed 5d > >> 17h 48min 24.509s CPU time. > >>=20 > >> And the service is no longer running. > >=20 > > I might be misreading this, but it looks to me that systemd detects that > > *some* process in the group was killed by the oom killer and stops the > > service. > >=20 > > Can you check which process was actually killed? If it's not the > > postmaster, setting OOMScoreAdjust is probably useless. > >=20 > > (I tried searching the web for the error messages and didn't find > > anything useful) >=20 > Your guess is as good as (if not better than) mine. I can find the PID > of the killed process in the system log, but without knowing what the > PID of postmaster and the child processes were prior to the kill, I=E2=80= =99m > not sure that helps much. The syslog should contain a list of all tasks prior to the kill. For example, I just provoked an OOM kill on my laptop and the syslog contains (among lots of others) these lines: Mar 13 21:00:36 trintignant kernel: [112024.084117] [ 2721] 126 2721 = 54563 2042 163840 555 -900 postgres Mar 13 21:00:36 trintignant kernel: [112024.084123] [ 2873] 126 2873 = 18211 85 114688 594 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084128] [ 2941] 126 2941 = 54592 1231 147456 565 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084134] [ 2942] 126 2942 = 54563 535 143360 550 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084139] [ 2943] 126 2943 = 54563 1243 139264 548 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084145] [ 2944] 126 2944 = 54798 561 147456 545 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084150] [ 2945] 126 2945 = 54563 215 131072 551 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084156] [ 2956] 126 2956 = 18718 506 122880 553 0 postgres Mar 13 21:00:36 trintignant kernel: [112024.084161] [ 2957] 126 2957 = 54672 269 139264 546 0 postgres That's less helpful than it could be since all the postgres processes are just listed as "postgres" without arguments. However, it is very likely that the first one is actually the postmaster, because it has the lowest pid (and the other pids follow closely) and it has an OOM score of -900 as set in the systemd service file. So I could compare the PID of the killed process with this list (in my case the killed process wasn't one of them but a test program which just allocates lots of memory). hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --4itbbsofw2yq2hus Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmQPhJkACgkQ8g5IURL+ KF2iNBAAjMhO27oSPBo+If0kTVOMzuZWKto0jdIX5RNOJb4QfxKT+SWztEUYzFt3 HolKU9VGattk3zDUyR4b6y93TbZpafU5oldl55+QezMfBQCaO1O/r9XcnE2NqP8U nKw0qRdDxJATL/Y7BqsbZttN2Jvhp/j4ab1n50UoIVA3fkSWJYOvp9xctFz+Qllx 6YGZzLTBpeLpJP5AYi9zUXibGiAzw4Tkk1kR2dHqpahpLzD8o1bmPA8484vXEI4c WiCKL47+3AUErTDw6eTRu3m9QyE7VS+ydYDOxeQRm5kFne8/6x41qRx2rgpdGwjq E7lPB2Cs9QKjXxDsExl2Pp7jbphARNzBJqGghA8EpPmDdZBnKjNWotnnQRUs4MpE P/pJ4DLv9wGjUtDts5uqdD5Cd0ReVhfDqKNqv+ly3c95YoAMgOM98SIsMXjVv/2l hT4T/HJlkq3lcIZmKWz1L5u40uLJE+pvghuao58+R0SllwnLUeVlFlmlWcVN2S2t Xy2jKrp5GE1DwoNxYDcs3fleM62Muh8LfCTg/kDAERK6zEc9+a2sQ4hoG2v8QU61 O5s53FNxcgVwzgkwN2puh9tkywu66FefNh1hTHOgpVWEJe2tN/+DSvkoiC/OhBjc fsUTmy6qM6pvR9vsZuXYHzAkIWiPh4dskdP2MphqVZTSITNIrPM= =NQuh -----END PGP SIGNATURE----- --4itbbsofw2yq2hus--