Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5
Masahiko Sawada <sawada.mshk@gmail.com>
From: Masahiko Sawada <sawada.mshk@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: Duncan Sands <duncan.sands@deepbluecap.com>,
pgsql-bugs@lists.postgresql.org
Date: 2025-05-21T18:24:14Z
Lists: pgsql-bugs
On Wed, May 21, 2025 at 4:12 AM Amit Kapila <amit.kapila16@gmail.com> wrote: > > On Wed, May 21, 2025 at 11:18 AM Amit Kapila <amit.kapila16@gmail.com> wrote: > > > > On Mon, May 19, 2025 at 8:08 PM Duncan Sands > > <duncan.sands@deepbluecap.com> wrote: > > > > > > 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 think the problem here is that when we are distributing > invalidations to a concurrent transaction, in addition to queuing the > invalidations as a change, we also copy the distributed invalidations > along with the original transaction's invalidations via repalloc in > ReorderBufferAddInvalidations. So, when there are many in-progress > transactions, each would try to copy all its accumulated invalidations > to the remaining in-progress transactions. This could lead to such an > increase in allocation request size. I agree with this analysis. > However, after queuing the > change, we don't need to copy it along with the original transaction's > invalidations. This is because the copy is only required when we don't > process any changes in cases like ReorderBufferForget(). It seems that we use the accumulated invalidation message also after replaying or concurrently aborting a transaction via ReorderBufferExecuteInvalidations(). Do we need to consider such cases too? Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix cache-dependent test failures in logical decoding.
- 87819f766f37 13.22 landed
-
Fix re-distributing previously distributed invalidation messages during logical decoding.
- d87d07b7ad3b 18.0 landed
- 45c357e0e85d 17.6 landed
- b2ae077205e1 16.10 landed
- fc0fb77c550f 15.14 landed
- 983b3636259b 14.19 landed
- 1230be12f086 13.22 landed
-
Fix data loss in logical replication.
- 247ee94150b6 13.21 cited
- 4909b38af034 18.0 cited