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 1uM8PU-003OCP-Kb for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Jun 2025 16:53:16 +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 1uM8PT-00BPIm-4C for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Jun 2025 16:53:15 +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 1uM8PS-00BPIe-Q7 for pgsql-bugs@lists.postgresql.org; Mon, 02 Jun 2025 16:53:14 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uM8Nx-0003uv-15 for pgsql-bugs@lists.postgresql.org; Mon, 02 Jun 2025 16:53:13 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5533302b49bso5933359e87.2 for ; Mon, 02 Jun 2025 09:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748883100; x=1749487900; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3VFW1EVmwuMO24MzJAi10Zs0FMKkxrt//hSTabtGBa0=; b=QC8VL8ykKvU/JypcxwORxKTs4R6+gS1w9OYtDZuaaHJaJ3Z9F06dOMaTzWRrbKCIhv 2pwSO79JEJvfgiyEpdj7f5D3bjxGh8fPeJPnJWBgpPrxDtuPEjQLgg16iz0osOYwK+bn gzQI4IRMHRnUvTVfusmNYPtTp6Cj+vVRNdBLmpelCHt6DRwkJ0Piuw4//2yWcWqSfPGZ GAjqBY3g+fAesJ83teDAHVQaaPrerJRiosyxuBLiod8JVkRfuQX7ENMyuf5nq5q6XEWr o4BsLIxM7LOUhvX8g4Jq/xoTW0WY/NsFy/uaX+kumxnHjQ++InkxCpvwaDoHN6hHuUN0 jeoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748883100; x=1749487900; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3VFW1EVmwuMO24MzJAi10Zs0FMKkxrt//hSTabtGBa0=; b=DZl47i1jStR+mdhbR17ThCKlcAOIHesw2A8pXfcgcUIhyD/lOGPMTjH2nXySI5Jme0 m2dq618p3/6zPIgY8+L4TJNZ8OEZ1feBhGTmr8jDqmbKX01nWtlT0DAw3WVwDpQmQM2B IqDSnCDf6kXxIkbVwlT/YWWVOsBqIvoUEYBbg7pJ4LFUSnGVpBq8vnD56eDID7B6X9ct iDc/CLMWoRYacNeh9YjcNDdtyT0iAxSlWpFA1V8KC48LdCb7e5UMY2FVhTRawKNhpRps Bu5fNjooPpY2lPhX1ttauB00sTWiZPElBPtWhFRDVqabd1qerj90otvmpmi2rojKe5ZK l5sw== X-Forwarded-Encrypted: i=1; AJvYcCW0pPBJIYtPz0ccimoJIxP9SA2s5y4TbfKvhtPOuX6hCL7vu1t/Sb68pkMGXY4D7jytEL4Ga7kaIOCX@lists.postgresql.org X-Gm-Message-State: AOJu0YxIVOpqcjAyPbNmJFUE/GxMaEG0oIBL3ptGyd/RK8rFEQvsRKc7 p3bQvOoEtGpnzNhGu2glpSx+4/X6HwSUzlXh7IHs5oTew+ZERUBI8ejlmJcCOsbSui7B69VNowh HF60YvEIx0ug7vgeguthSAH4eUWlO5/E= X-Gm-Gg: ASbGncsDp/XxETQuh/RYRGxtde8ugvpE4mKx6l+KFPDXpJMzIDPc4+JfZEvSmR14Z9q Pr9MeXpZ0p/f+LcZhFRoeLtX6mfo8+9bdHpa6QJH729QCg5zaCit3nADXMo/jCarBV6Vu8DFDf2 3HbnT8yJ4/i4WF7iFkaCI8VipW7VDV1Zvy88Y9z+asjWU= X-Google-Smtp-Source: AGHT+IFs9v76xkLZLkp6S1aBldtrZNjhdYZRXYqUxXxKfUd8+UgT4BGo1s5sP8pBBf/XLHeL865Fa0cuXo8M5drx8TE= X-Received: by 2002:a05:6512:3d22:b0:553:2cfd:5958 with SMTP id 2adb3069b0e04-5533b8e10c4mr4203284e87.8.1748883099843; Mon, 02 Jun 2025 09:51:39 -0700 (PDT) MIME-Version: 1.0 References: <680bdaf6-f7d1-4536-b580-05c2760c67c6@deepbluecap.com> In-Reply-To: From: Masahiko Sawada Date: Mon, 2 Jun 2025 09:51:03 -0700 X-Gm-Features: AX0GCFuJY5RQv3tmGr6DaX3BMnTOCKBcjVwQ5IiNPlXSOCsForsVGkRxwT-UwNg Message-ID: Subject: Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5 To: vignesh C Cc: Amit Kapila , "Hayato Kuroda (Fujitsu)" , Duncan Sands , "pgsql-bugs@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Jun 1, 2025 at 8:13=E2=80=AFPM vignesh C wrot= e: > > On Sat, 31 May 2025 at 10:20, Amit Kapila wrote= : > > > > On Fri, May 30, 2025 at 11:00=E2=80=AFPM Masahiko Sawada wrote: > > > > > > Thank you for updating the patch. Here are some review comments: > > > > > > --- > > > + /* > > > + * Make sure there's no cache pollution. Unlike the PG_TR= Y part, > > > + * this must be done unconditionally because the processi= ng might > > > + * fail before we reach invalidation messages. > > > + */ > > > + if (rbtxn_inval_all_cache(txn)) > > > + InvalidateSystemCaches(); > > > + else > > > + ReorderBufferExecuteInvalidations(txn->ninvalidations= _distr, > > > + > > > txn->distributed_invalidations); > > > + > > > > > > If we don't need to execute the distributed inval message in an error > > > path other than detecting concurrent abort, we should describe the > > > reason. > > > > > > > The concurrent abort handling is done for streaming and prepared > > transactions, where we send the transaction changes to the client > > before we read COMMIT/COMMIT PREPARED/ROLLBACK/ROLLBACK PREPARED. Now, > > among these COMMIT/ROLLBACK PREPARED cases are handled as part of a > > prepared transaction case. For ROLLBACK, we will never perform any > > changes from the current transaction, so we don't need distributed > > invalidations to be executed. For COMMIT, if we encounter any errors > > while processing changes (this is when we reach the ERROR path, which > > is not a concurrent abort), then we will reprocess all changes and, at > > the end, execute both the current transaction and distributed > > invalidations. Now, one possibility is that if, after ERROR, the > > caller does slot_advance to skip the ERROR, then we will probably miss > > executing the distributed invalidations, leading to data loss > > afterwards. If the above theory is correct, then it is better to > > execute distributed invalidation even in non-concurrent-abort cases in > > the ERROR path. This theory seems to be correct to me. If users re-try the logical decoding with smaller logical_decoding_work_mem the process could end up streaming the transaction with the wrong relcache before sending the committed transaction? > One possible reason this scenario may not occur is that > pg_logical_slot_get_changes_guts uses a PG_CATCH block to handle > exceptions, during which it calls InvalidateSystemCaches to clear the > system cache. Because of this, I believe the scenario might not > actually happen. > @Sawada-san / others =E2=80=94 Are there any other cases where this could= still occur? I think that we cannot confine use cases to walsender and pg_logical_slot_get_changes_guts() given that we expose logical decoding API at C level. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com