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 1oC67N-00064z-Ho for pgsql-general@arkaria.postgresql.org; Thu, 14 Jul 2022 21:11:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oC67M-0006WJ-BP for pgsql-general@arkaria.postgresql.org; Thu, 14 Jul 2022 21:11:28 +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 1oC67L-0006W8-Gs for pgsql-general@lists.postgresql.org; Thu, 14 Jul 2022 21:11:28 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oC67I-0007Kv-HI for pgsql-general@lists.postgresql.org; Thu, 14 Jul 2022 21:11:27 +0000 Received: by mail-ed1-x52d.google.com with SMTP id r18so3965418edb.9 for ; Thu, 14 Jul 2022 14:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=cePt+8buP4wIcNy/gF+f/MNeB17CqVq9mhaW/AjUsyk=; b=KFrlpfKY1GRfpVZBrSvnFCyOLmAOVbw1rAhCSCxk4rs/OZ9d87yqdH3gMEPo1Uozl/ +UQ8EDDQTwjwI1HVRhF3mtRQvglOk6dfLu5X4kKFmfi4WBNKkU7FAFmZUNO50BU7fx4g CnzZVqmKAprFmxv3mrx9OHNiyHnRwHg6eMwpjgdfMjTB+yvMg6Tl6BoivKZ9btdU9y0t LwxzkG8fF1/y3Ay9YSTC0DgfbNtygMP4tZ0MxWga2jx0CdUYbR+lZGLjMDvACQEd7L39 wY7NvyHLeb6g0dIVeuWdeGDkFJ9z4NuBVYnJXj0lUxP5w+By1LFuHz0Rq91JJ2VfQxgQ Kxfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=cePt+8buP4wIcNy/gF+f/MNeB17CqVq9mhaW/AjUsyk=; b=7SvOIJnv2TOdvu31TvJe4SckDRuhoSUml/MLfB96/W4d3xvwUnV34fDY47AHqYCZ5D mtwmCwPu8wpdXhSopspocsV7VB3m0r5sUHbbEtqyI5PR9dMipQkgie1zDzvZCYjcWjDE JJkrv3Bl44O9m5cF/Ve0b4W3BygKYZaCMVjP3XCQbemI3Jjkry1wc3bZh5zEneemAD9k 8HMT+Q9EXmCsOBiH9mNc5vwdaSdB0ViMno2xHvu0K6FQC4u025J9t0/mlVC1Zm72AtSq cPPBwsvG3SNIiBxl71E5VR9CZmtQoFjsP12WR//NImfUsvyTsZg3xsWufga8dASrjrvq flog== X-Gm-Message-State: AJIora+9oPv45mJZk8GEZzRUj2PRV2C1lYmyfLAAr0AIi5JMXlFkaPeA OfSV4GZOgVM2mtTGg8ojRPzqUcLTOfSw8lz0ZCOPtCnhLlR8989qHWhYTjblgFCZQtrlSpqGnjt 1VNeexMQDedMooNXWgnrq+WzN/21Su4SZmvJBWh0LHXMroirX1drfHa6pXZtq6rBLai8BB9uSWS xI4sUlytF/FF//XZZ5OjEk2aRBQfKl2gG6+LY6foIET4rMqEEbDRKc X-Google-Smtp-Source: AGRyM1vdmS8j1LcEQrl+MD0Wt3OXSg6PfLynNYzP3oeN4dAz4DkvQzNs6qhxKeFOt8SDb7V8aMwD5Q== X-Received: by 2002:a05:6402:110b:b0:43a:e0b7:1788 with SMTP id u11-20020a056402110b00b0043ae0b71788mr14832304edv.109.1657833083607; Thu, 14 Jul 2022 14:11:23 -0700 (PDT) Received: from [10.137.0.17] (ip-86-49-250-151.bb.vodafone.cz. [86.49.250.151]) by smtp.gmail.com with ESMTPSA id d2-20020a056402000200b0043a61f6c389sm1700962edu.4.2022.07.14.14.11.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jul 2022 14:11:23 -0700 (PDT) Message-ID: Date: Thu, 14 Jul 2022 23:11:23 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: PostgreSQL 14.4 ERROR: out of memory issues Content-Language: en-US To: =?UTF-8?B?QWxlxaEgWmVsZW7DvQ==?= , Michael Paquier Cc: "pgsql-generallists.postgresql.org" References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/14/22 21:25, Aleš Zelený wrote: > > st 13. 7. 2022 v 2:20 odesílatel Michael Paquier > napsal: > > On Mon, Jul 11, 2022 at 10:50:23AM +0200, Aleš Zelený wrote: > > So far, it has happened three times (during a single week) from > the 14.3 -> > > 14.4 upgrade, before 14.4 we haven't suffered from such an issue. > > > > Questions: > > 1)  Can we safely downgrade from 14.4 to 14.3 by shutting down the > instance > > and reinstalling 14.3 PG packages (to prove, that the issue > disappear)? > > 2) What is the best way to diagnose what is the root cause? > > Hmm.  14.4 has nothing in its release notes that would point to a > change in the vacuum or autovacuum's code paths: > https://www.postgresql.org/docs/14/release-14-4.html#id-1.11.6.5.4 > > > There is nothing specific after a look at the changes as of, and I am > not grabbing anything that would imply a change in memory context > handling either: > `git log --stat REL_14_3..REL_14_4` > `git diff REL_14_3..REL_14_4 -- *.c` > > Saying that, you should be able to downgrade safely as there are no > changes in WAL format or such that would break things.  Saying that, > the corruption issue caused by CONCURRENTLY is something you'd still > have to face. > > > Thanks, good to know that, we can use it for a test case, since we > already hit the CONCURRENTLY bug on 14.3. > > > 2022-07-02 14:48:07 CEST [3930]: [3-1] user=,db=,host=,app= > ERROR:  out of > > memory > > 2022-07-02 14:48:07 CEST [3930]: [4-1] user=,db=,host=,app= > DETAIL:  Failed > > on request of size 152094068 in memory context > "TopTransactionContext". > > 2022-07-02 14:48:07 CEST [3930]: [5-1] user=,db=,host=,app= CONTEXT: > >  automatic vacuum of table "prematch.replication.tab_queue_tmp" > > This is the interesting part.  Do you happen to use logical > replication in a custom C++ plugin? > > > We are using logical replication to other instances (pg_output) and > decoderbufs > https://github.com/debezium/postgres-decoderbufs > for other applications. >   This is probably just a red herring - std:bad_alloc is what the process that runs into the overcommit limit gets. But the real issue (e.g. memory leak) is likely somewhere else - different part of the code, different process ... > ... > > Checking the RssAnon from proc/pid/status I've found some points where > RssAnon memory usage grew very steep for a minute, but no "suspicious" > queries/arguments were found in the instance logfile. >   > Any hint, on how to get the root cause would be appreciated since so far > I've failed to isolate the issue reproducible testcase. > At least I hope that looking for the RssAnon process memory is an > appropriate metric, if not, let me know and I'll try to update the > monitoring to get the root cause. > > I can imagine a workaround with client application regular reconnect..., > but u to 14.3 it works, so I'd like to fix the issue either on our > application side or at PG side if it is a PG problem. > I think it's be interesting to get memory context stats from the processes consuming a lot of memory. If you know which processes are suspect (and it seems you know, bacause if a reconnect helps it's the backend handling the connection), you can attach a debugger and do $ gdb -p $PID call MemoryContextStats(TopMemoryContext) which will log info about memory contexts, just like autovacuum. Hopefully that tells us memory context is bloated, and that might point us to particular part of the code. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company