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 1l92iR-0000hC-7T for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Feb 2021 09:20:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l92iQ-0007g3-57 for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Feb 2021 09:20:18 +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 1l91x6-00013u-00 for pgsql-hackers@lists.postgresql.org; Mon, 08 Feb 2021 08:31:24 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l91wx-0002A5-Vm for pgsql-hackers@postgresql.org; Mon, 08 Feb 2021 08:31:23 +0000 Received: by mail-wm1-x331.google.com with SMTP id i5so3746152wmq.2 for ; Mon, 08 Feb 2021 00:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=KIspy2kI6LnXdLy5Bv/uwXD22be7u/1XGlzn0TnWUA8=; b=kTkIlK3JkZCGL7/quQjHGTAsRKpkeLobfVzs+0qc+bUPkpi3GxzYXoxlF1eBir6G4t jQbG0RCO29QtdeU7txoEGiwbipQfdcVMlaujhSRSxqPw0bIV51Bf0H9YoUfBQTFMPuBg 2MY0otCJOYVz6rOzTujrBxU+AZMlHsFYXSIY8Wb8k9dhbEk/dXvT77TCyOINZUao037w 61LXmIpbwrwPaQHcla6Ki6W2y3RcW6++PS1Qo/5MryHW/0yeDgIwKYIciFoALcky3zKz piKT55VnfOVDJllNX0r4vVjADmlKHww+EGHj8wDD8KHyIZ2T33JGc+28Lva62mvcbfsx nV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=KIspy2kI6LnXdLy5Bv/uwXD22be7u/1XGlzn0TnWUA8=; b=S0gcEKWXet22kPt1DBejJltD7caBvOZTXbLGzPykzxZRfet6ugTLXcHxAsbTE4YUsi 18sMjam1TfQwlRz0jeJJBMe4y8CU0K5XldJg8zzoKerjcYTSUmO/YKW2/0Y0MS7lJppX wfx7OACk3p64Y954u9h6as6WpqXGX+EsU+bAri0YDjR5wIHD3S/iMVGonma8/YYz/djc uQiKDBVp68haeTpksuzYyC5Wv8DQtUGeQFv+EehxOoF0nG76n8xGa5th4czSo5RC4ZrR m4RL3s8IZe4+GfUh3S35kK0kny4FsFxBuxuJfChhPEEX1O7pdxd4T5CXVVO7VeLAqiEF FwLA== X-Gm-Message-State: AOAM533YsM7Tg8oKABKtrXKCeg4RhI3aL7iCIhLe2A/WEvBpZ4Su+VFg 99/OtKMkG5H94W/6LEvW3XkhDsUNRTMj6sVhs3Zuqgrf/PpDI+bNiWcUcD3/FVqZVMPJijfS7WM 5X4BkPZCSbRnsti/E5CFFG1Y9UkOd1sVFDRFp31ffPlGvLDXji/GRgnn3SuK4zkpR9atmBbSD// QO6yvFTFsaTfkGf5GK1jw1lRbTyVqCIp8RezJh X-Google-Smtp-Source: ABdhPJwKwrR/ueztt9s9LY4Rm9tGOX3jLlekeAMbjQMoTWWCFnxM0NBkxy33qCnf6pVq3+pPATO4pQ== X-Received: by 2002:a1c:9c01:: with SMTP id f1mr13256721wme.159.1612773074762; Mon, 08 Feb 2021 00:31:14 -0800 (PST) Received: from [10.80.18.219] (pool1-225.cgn.as8758.net. [212.25.6.225]) by smtp.gmail.com with ESMTPSA id t205sm20030217wmt.28.2021.02.08.00.31.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Feb 2021 00:31:14 -0800 (PST) To: pgsql-hackers@postgresql.org, amit.kapila16@gmail.com, itsajin@gmail.com From: Markus Wanner Subject: repeated decoding of prepared transactions Message-ID: Date: Mon, 8 Feb 2021 09:31:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: Precedence: bulk Amit, Ajin, hackers, testing logical decoding for two-phase transactions, I stumbled over what I first thought is a bug. But comments seems to indicate this is intended behavior. Could you please clarify or elaborate on the design decision? Or indicate this indeed is a bug? What puzzled me is that if a decoder is restarted in between the PREPARE and the COMMIT PREPARED, it repeats the entire transaction, despite it being already sent and potentially prepared on the receiving side. In terms of `pg_logical_slot_get_changes` (and roughly from the prepare.sql test), this looks as follows: data ---------------------------------------------------- BEGIN table public.test_prepared1: INSERT: id[integer]:1 PREPARE TRANSACTION 'test_prepared#1' (3 rows) This is the first delivery of the transaction. After a restart, it will get all of the changes again, though: data ---------------------------------------------------- BEGIN table public.test_prepared1: INSERT: id[integer]:1 PREPARE TRANSACTION 'test_prepared#1' COMMIT PREPARED 'test_prepared#1' (4 rows) I did not expect this, as any receiver that wants to have decoded 2PC is likely supporting some kind of two-phase commits itself. And would therefore prepare the transaction upon its first reception. Potentially receiving it a second time would require complicated filtering on every prepared transaction. Furthermore, this clearly and unnecessarily holds back the restart LSN. Meaning even just a single prepared transaction can block advancing the restart LSN. In most cases, these are short lived. But on the other hand, there may be an arbitrary amount of other transactions in between a PREPARE and the corresponding COMMIT PREPARED in the WAL. Not being able to advance over a prepared transaction seems like a bad thing in such a case. I fail to see where this repetition would ever be useful. Is there any reason for the current implementation that I'm missing or can this be corrected? Thanks for elaborating. Regards Markus