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 1uHjd1-008ViU-G1 for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2025 13:37:03 +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 1uHjd0-0072Ba-7I for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2025 13:37:02 +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 1uHhfB-005yYb-Dc for pgsql-bugs@lists.postgresql.org; Wed, 21 May 2025 11:31:09 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uHhf4-0008A7-0M for pgsql-bugs@lists.postgresql.org; Wed, 21 May 2025 11:31:07 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-601a5747638so6924352a12.3 for ; Wed, 21 May 2025 04:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deepbluecap-com.20230601.gappssmtp.com; s=20230601; t=1747827059; x=1748431859; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wbwGL42rbrWfLAhB9ZE24gMZHEhgUihxYnAaJZmXnrY=; b=t7tvnkD45nNkMf/AsFmlCdBvrzardW7WkuFPcfrppI5DZmmkv18ZUBBot5NSP71FVG UHBu/perPQ2rQ+hn1iqUVuKs+SGf5BkRKOpATr6s9a+gz3MhkbjsqP7rpBE0s/frgKD0 7N1s5sRZEkT3t5h87A4Q3KYPTtM1q+Xnyw/PFTYT+gAulDE9N9eEZm5tMFgeTllTdWBW C/TU9CT7kCjabeLGJgHOG3c3k+ixwwQtCbldiLoLtJREX56EWrdgLO9djEgNLWWM1oJe Vc1wbg9Nlex16zGvMY2IaJ/M+SyQT+z5xPuhB1tjCqfi26cLCFaHK97EKXdaDBg75YoK Xx4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747827059; x=1748431859; h=content-transfer-encoding:in-reply-to: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=wbwGL42rbrWfLAhB9ZE24gMZHEhgUihxYnAaJZmXnrY=; b=FlF2/qMHt1gMYm/Ffdolfwxbz1LQFfDIHM8sQRSA3E/U2bpJ+v5EPyvT4Gs/AIaHRF c95wNSGrwuEHMR91OsCO4erTvDnKswkGScVQZW1xiYm9kq7nBfNzST/yQTV5QU1b/fWB h7p8yr/K8B5KDbHYncuDhGWJGQSFsO7JhSsslcNGIvt5nPRidRl6gYCqjregEMvJzQk1 TbRlyaQliyNk2WTh9Ibx7n8Nr/waAOpUuyk0XmJsZzW4FInVIxh4NLUYKlUEeqDnljrk tr+nHcsSoeCcEa316B9gbkehyBIdqN+dMcKiG+/KYwIJN8Cr2rnhIee3X9txsD7B2yI6 jSbA== X-Gm-Message-State: AOJu0Yw6lAmu6zlMMknvCuN0jfXkayOeuCYDZMdfDiP0zGEOz8LtDm4E H9IuzXjuB1uFHAJbsBx7nNo8BkNsr/ofANrcgFtfqtY+k4yQmuKE2azspuQ0Ut03c6g= X-Gm-Gg: ASbGncvsAilcyCrVdXUpt1yS93N8ufyPnBrT+CxOKdJ07PEU7/RV8r9xOPabDoyleRs 2yrpggiUsfPtLPmsZm8203fZCcBhd8m7vs+TCh07xkFnSRgqv7AksoK4RKtjpo8NsR/mWCyXFk3 p8uQVroidqEainvE40T77mMC8G6zHBUxZx3dVUsKSuwpZ+JhgxPyIKMGtuxC4jg4reYupR5jsK5 iG5Kmwlaf7gZ1xylsBG7iIKiXsK1dF4gJv36xtL/pbDSdwgItqUsTxfeL2flm1ANMI4Pm7Qptdv txOkiHPysR8OfYSm23geRhraxb3MUOkZEr3fBkglG4dbKpRZRK2v+l8uHkE9S2Tc9RNq56ZsLiy wBpjcreWZHHds5qk4movj/r+oDsw5lyGEjiLhPA== X-Google-Smtp-Source: AGHT+IGjXMBSyO4FdqTj72t+tZOCS7aSnrLe8dWe9HhLBLh/rPva7euRJaA4w4VN6BaEVbtAWuT2Hw== X-Received: by 2002:a05:6402:1056:b0:5f3:26bb:8858 with SMTP id 4fb4d7f45d1cf-60090180a5dmr14254206a12.34.1747827059422; Wed, 21 May 2025 04:30:59 -0700 (PDT) Received: from [192.168.57.201] (92-111-21-226.static.v4.ziggozakelijk.nl. [92.111.21.226]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6005a6dfd41sm8656025a12.35.2025.05.21.04.30.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 May 2025 04:30:58 -0700 (PDT) Message-ID: Date: Wed, 21 May 2025 13:30:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5 To: Amit Kapila Cc: pgsql-bugs@lists.postgresql.org, Shlok Kyal References: <680bdaf6-f7d1-4536-b580-05c2760c67c6@deepbluecap.com> Content-Language: en-US From: Duncan Sands In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Amit and Shlok, thanks for thinking about this issue. We are working on reproducing it in our test environment. Since it seems likely to be related to our primary database being very busy with lots of concurrency and large transactions, we are starting by creating a streaming replication copy of our primary server (this copy to run 17.5, with the primary on 17.4), with the idea of then doing logical replication from the standby to see if we hit the same issue. If so, that gives something to poke at, and we can move on to something better from there. Best wishes, Duncan. On 21/05/2025 07:48, Amit Kapila wrote: > On Mon, May 19, 2025 at 8:08 PM Duncan Sands > wrote: >> >> PostgreSQL v17.5 (Ubuntu 17.5-1.pgdg24.04+1); Ubuntu 24.04.2 LTS (kernel >> 6.8.0); x86-64 >> >> Good morning from DeepBlueCapital. Soon after upgrading to 17.5 from 17.4, we >> started seeing logical replication failures with publisher errors like this: >> >> ERROR: invalid memory alloc request size 1196493216 >> >> (the exact size varies). Here is a typical log extract from the publisher: >> >> 2025-05-19 10:30:14 CEST \[1348336-465] remote\_production\_user\@blue DEBUG: >> 00000: write FB03/349DEF90 flush FB03/349DEF90 apply FB03/349DEF90 reply\_time >> 2025-05-19 10:30:07.467048+02 >> 2025-05-19 10:30:14 CEST \[1348336-466] remote\_production\_user\@blue LOCATION: >> ProcessStandbyReplyMessage, walsender.c:2431 >> 2025-05-19 10:30:14 CEST \[1348336-467] remote\_production\_user\@blue DEBUG: >> 00000: skipped replication of an empty transaction with XID: 207637565 >> 2025-05-19 10:30:14 CEST \[1348336-468] remote\_production\_user\@blue CONTEXT: >> slot "jnb\_production", output plugin "pgoutput", in the commit callback, >> associated LSN FB03/349FF938 >> 2025-05-19 10:30:14 CEST \[1348336-469] remote\_production\_user\@blue LOCATION: >> pgoutput\_commit\_txn, pgoutput.c:629 >> 2025-05-19 10:30:14 CEST \[1348336-470] remote\_production\_user\@blue DEBUG: >> 00000: UpdateDecodingStats: updating stats 0x5ae1616c17a8 0 0 0 0 1 0 1 191 >> 2025-05-19 10:30:14 CEST \[1348336-471] remote\_production\_user\@blue LOCATION: >> UpdateDecodingStats, logical.c:1943 >> 2025-05-19 10:30:14 CEST \[1348336-472] remote\_production\_user\@blue DEBUG: >> 00000: found top level transaction 207637519, with catalog changes >> 2025-05-19 10:30:14 CEST \[1348336-473] remote\_production\_user\@blue LOCATION: >> SnapBuildCommitTxn, snapbuild.c:1150 >> 2025-05-19 10:30:14 CEST \[1348336-474] remote\_production\_user\@blue DEBUG: >> 00000: adding a new snapshot and invalidations to 207616976 at FB03/34A1AAE0 >> 2025-05-19 10:30:14 CEST \[1348336-475] remote\_production\_user\@blue LOCATION: >> SnapBuildDistributeSnapshotAndInval, snapbuild.c:915 >> 2025-05-19 10:30:14 CEST \[1348336-476] remote\_production\_user\@blue ERROR: >> XX000: invalid memory alloc request size 1196493216 >> >> If I'm reading it right, things go wrong on the publisher while preparing the >> message, i.e. it's not a subscriber problem. >> > > Right, I also think so. > >> This particular instance was triggered by a large number of catalog >> invalidations: I dumped what I think is the relevant WAL with "pg_waldump -s >> FB03/34A1AAE0 -p 17/main/ --xid=207637519" and the output was a single long line: >> > ... > ... >> >> While it is long, it doesn't seem to merit allocating anything like 1GB of >> memory. So I'm guessing that postgres is miscalculating the required size somehow. >> > > We fixed a bug in commit 4909b38af0 to distribute invalidation at the > transaction end to avoid data loss in certain cases, which could cause > such a problem. I am wondering that even prior to that commit, we > would eventually end up allocating the required memory for a > transaction for all the invalidations because of repalloc in > ReorderBufferAddInvalidations, so why it matter with this commit? One > possibility is that we need allocations for multiple in-progress > transactions now. I'll think more about this. It would be helpful if > you could share more details about the workload, or if possible, a > testcase or script using which we can reproduce this problem. >