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.96) (envelope-from ) id 1wXCCW-0037L6-2q for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2026 06:14:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wXCCV-009SCw-2Y for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jun 2026 06:14:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wXCCV-009SCf-1b for pgsql-hackers@lists.postgresql.org; Wed, 10 Jun 2026 06:14:07 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wXCCT-00000002HXF-2Lni for pgsql-hackers@lists.postgresql.org; Wed, 10 Jun 2026 06:14:07 +0000 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-36b9ec98144so5340453a91.1 for ; Tue, 09 Jun 2026 23:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781072043; x=1781676843; darn=lists.postgresql.org; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=W2jjiMh8aIwFPQxhxf6Z2ZzBcsfl/qhCbNPsC+cehiM=; b=iODnike9EMECd0RkneTg9AfYfmIJPQ8nxLK71hpyPX40LfdPS4SfCSb89Z98CZWuXb wCcyxmPrJRZXHf3u9pZQHFaIo1p26E0opyx0sKkwoQbTl9v33VOsJ08ckt7eWItVg1iR 86WdqOJOFJh/uqpZ68555dUcUy1tYGRJQRObpVrQx5H9MoubHg2C9sdjDFaXqU98WWiN aldpEfn/bAguq6zZYc6INQ6ske/ueN1Dq8HMGXOD7lpiVYatLgVFIEHQDEUp290EOKkZ YcX235gOQngGer7ricoLeJZ6nTYEgdrYmlIQHJmo0ZzOcAuyVIuxNjBBp8F3eIdc1VPe YN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781072043; x=1781676843; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W2jjiMh8aIwFPQxhxf6Z2ZzBcsfl/qhCbNPsC+cehiM=; b=oQIZjgXEjw9h6unv+RcwZ1MHHKRyx9pxnV5yV6eIC7JKcspPIyZXG0a9tsxrb2ugC1 WH6tBHMstBltl+dU78S2ypLXGBRylkhhcIH/uaPB2h6U2cPf1iSDuZY5RtYbUcf84112 ahWsmYd66JUNK51p5Uz6k+9UK0RvEXR423MvdEE5/xJ+RAnoTNw42TukHN+rTalBDCXA Axzcyg1syJXyOLEi9sjZf5NUar84vz1/6M20/nVUtMxqXgjtrZ8JS5SvQ5Z0L8iZyj2X VBd4JDBh0CdVUK/p1sYttDGRROARzXjKPbtsZj/GcCMeHgKhYpofdHisGugBCYrCXvVd AldA== X-Forwarded-Encrypted: i=1; AFNElJ8xt55qUy7cR7MZwHb/TbSEsm5J6kvwSjb6vaINLG+OTyUMKri3f5nkgH9oDhq/7N+f0WEGCzGQdPr86smq@lists.postgresql.org X-Gm-Message-State: AOJu0YwMyq/lAhhgcjK+dsQdRRnfGd1MttJ2ug73UubyU+qrNqB5zYJM dpV6FV4sS9tuPxNTHf0Ub90ixMAsckROzpHDbcZWmYc2EcSdiqw6vlEo X-Gm-Gg: Acq92OFeoV/VPWPX2QrNhSyZbWec+SzA/KrwfxeN5tog8qURTvoOPEBkKkNXHt74P7s DEbHQ3Xt93k0C024YAl+a+yPbE5p7Or86XuKSDlTX8eIPQKM33EXcebIgKl/zScCPGKcTgym2+g QY7Zk010/hTh+KNKaTcFpm84skr6ujNpFzGU3khr6JxS3wT+keMVaw7p0hpV5R96BnGKHYSbkjC HLgx0Wft+4QxF3ZZfwrt4yXARfi0jPY8Aw6EqSb0Tae3+8N/Z24SWhtHWl3D4Ql0li4rf2s9JXJ u0zjLBG25HSQ2l0f+Ig4/CxWLhBh3rvWpJNf1OS5eQncZMBYBI3yNmyP56jhentpMgyv9E7Fbcy XjZm7piXyHHI3LPYADJUlb5ifIHFJEFBuNlvQuQHDJNmB75jZ1CNbcQ7HazYag07KB2dInJCpdL cZOl+k+sgE0hqmR7tB61EnmBpdDgOyiHr42YPaMysuDqPRIm8y9HNuqQNIbzV6rPFBukaiaHMkL NcEwsbXAg== X-Received: by 2002:a17:90b:390f:b0:368:b01c:85a0 with SMTP id 98e67ed59e1d1-37520dc5920mr6744453a91.14.1781072043448; Tue, 09 Jun 2026 23:14:03 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-376245bb9f0sm1757633a91.9.2026.06.09.23.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 23:14:02 -0700 (PDT) Date: Wed, 10 Jun 2026 15:14:00 +0900 (JST) Message-Id: <20260610.151400.1358982088596344930.horikyota.ntt@gmail.com> To: satyanarlapuram@gmail.com Cc: shveta.malik@gmail.com, masao.fujii@gmail.com, vignesh21@gmail.com, pgsql-hackers@lists.postgresql.org, shvetamalik@gmail.com Subject: Re: [PATCH] Release replication slot on error in SQL-callable slot functions From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.8 on Emacs 29.4 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sorry for the late response. I may be misunderstanding the patch, but it looks to me as if it is trying to handle several different classes of problems uniformly by wrapping them in exception handling. ReplicationSlotAcquire() can exit with an ERROR after setting MyReplicationSlot. I think it should restore that state itself. Or rather, perhaps it should not set MyReplicationSlot until it is certain that the slot can be successfully acquired. I think the same kind of argument applies to ReplicationSlotCreate(). There is also a different issue around pgstat_create_replslot(). If ReplicationSlotCreate() calls it and then an error is thrown later in the caller, the caller needs to clean up that pgstat entry. That seems like a separate kind of cleanup from restoring MyReplicationSlot. In pg_logical_slot_get_changes_guts(), the patch moves the call to ReplicationSlotAcquire() inside the PG_TRY block. In practice the code checks whether MyReplicationSlot is NULL before releasing it, so this may work. However, semantically, it looks as if the caller is also responsible for releasing the slot even when ReplicationSlotAcquire() itself fails. More generally, I am not sure that all of these cleanup actions belong at the same level. Restoring MyReplicationSlot, cleaning up pgstat entry, and releasing an acquired slot seem to be different kinds of responsibilities. Handling them all through the same PG_TRY/PG_CATCH blocks causes those cleanup responsibilities to cross component boundaries. That, in turn, makes it harder to tell whether all resources affected by an error are actually being cleaned up. Regards. -- Kyotaro Horiguchi NTT Open Source Software Center