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 1wRS57-002M7P-2S for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2026 09:58:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wRS54-00119q-0e for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2026 09:58:43 +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 1wRS53-00119g-2h for pgsql-hackers@lists.postgresql.org; Mon, 25 May 2026 09:58:42 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wRS52-00000001KMd-33Ny for pgsql-hackers@lists.postgresql.org; Mon, 25 May 2026 09:58:42 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-36ab8816a35so634622a91.1 for ; Mon, 25 May 2026 02:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1779703118; cv=none; d=google.com; s=arc-20240605; b=C84hl52f2gXWfeE+cy3Kq2U1lDNkqmOiP7UM/cXPS2xSiILBOj0HiR37LzdpEq4QzB zPhIEiBNmCphG9sKUC4y+nFQKqI8tlZnUG4ELqwKW96g4ovMz69gRJWYO870vcLsBGGP V9tU9Ep5kwEHEGP6nMVf5AfEF4pCGrYF/NRDUUiLpVPefw3wf163osan0Z2aYeS6orew NHXkKvUCgoKSXD7S7PI0JlNuC2ImxXGzYgfcMF+9ZislesqmOyEAoMi6vfXGQJJecfZ9 o+zXhI2i5eBgisHVeanqCaaDMRdQp58Wg7bcRTYvVwBhQUkg3G2IwP+ubX1Mrrk/7ato t92w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LZgq6QGrUREp7fFtGbxZ/pd+wD1ipDfRLxdaDh3D3LU=; fh=Ax6sxJs3yAoTFMa9a00MB4mMnj26FW429HMdJlp5FeI=; b=Y7KC4TlztaDS71wVYldT0kppW5QDMikRR4rX+H/27f1pOiOA40nlvYq9S+ZWXmxLbu wI1n/7wf9f15qiXD2uYbGsZTAF5SfIu1UFyDv9/+tC6cTkHSJOZ/YPdJNRJqT0dqoQvR mwdWzGIIChTrFm//yfMFiwPmonrFXjJWi7dlIRZeGAbfTgqWgoHd1NzhjacbG6UaAuqJ AZY95qlrDJBtKsYPcGKr7TWcI/rFRhk0ltqDYeW3DYgXcdQorXGFI0lyhNdRpAKQXj+j 6rubCx427QNoodviMN29z5tfVcRucTkF292uXguLozyBVV8LxUe3iKBTfIeNZQR+fasM bf9w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779703118; x=1780307918; 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=LZgq6QGrUREp7fFtGbxZ/pd+wD1ipDfRLxdaDh3D3LU=; b=Ot6dQZK1j3XMVYtcGIThOIbhmUabIjCtPYBIs5Ya5y+JeTRCu8mkzbv8+nZZzi67NI Dxp2c6fFes5oTgCq8NWm/0qtiwTMCFBY2qhK+a0jRbZSajlPRLabz+UcpKuHde3es1YR 1UFS8QP6xIo0V+PrKjH28VZpq39YePEKAQGSk0nbS6EE2prbzlevCKBwCh5wRPO2V9Wn rkRmj9tgSQdf8P+gDgiO9Ep/6UHgSg1FVUheETJoMIqB7DntTLemZntru64NONt+6ysH jI8k7sed0Xm12buZfSDj70A99GsplvLyz6qf9M4FsUF48KETdxcdAx6JqzH0NjyduECP benw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779703118; x=1780307918; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LZgq6QGrUREp7fFtGbxZ/pd+wD1ipDfRLxdaDh3D3LU=; b=ix0ffUgsrtkT8dmYY6X+LYRYCYwuoPZFbS4qaTdEQeF/ZlLoha69aSyCOykNH2S35Y rqn3YzStRi7S2dhSFZdUUhzuEmIIarOaaure7fkSuY34l6P4dIBkjvNrWaaiXu3ENg6n H4rfBTtMMS8FAAtvA0TpAf+/IJD8UYasjDSCiI94at1vFxqCsqjt1inFXDQsmGnPdo8X e96Ic2c5auRRLRrl0hopVRKixqi8N/g4VBEkV8q0/N+/iSiTVIWlFvmX53ih/j4Q5mXP j0CvT8G6Be/0lPYE7e2+pBh6illAW+k5cqnRfh28mBAbBw3t3xss/DYr0asJX6VXtjnK XTpw== X-Forwarded-Encrypted: i=1; AFNElJ+mA1LBQUrQoXzXe89+jWNPvgwYTaqWIV4pU+0B3yE5wje+4HTjZcnewsF9qSCkYllBoO/FOoGkKxkXfJ0L@lists.postgresql.org X-Gm-Message-State: AOJu0YzfzsHdaIrfQmlMxtoHTAgeeqNn93RDzCjAkql51vGTNugNWVAL 9pZVWJiThCKYirmNakOOC/FkYKYeC7NirBaTpvgw3mdVh+MeYa6stmj/Q8TLwcE/mMXa5yFrGD7 nzLJB12WvMxrLxfj30pUCey27hnqtUtk= X-Gm-Gg: Acq92OG9cUtqeoXInIc1WcvygqHk+8466ny4UwVMMaF/ttjVGM/Hr2juLwwk0YSwrUx cSj9EKIN33otP/+YEmhfQlYWcwhqdcbvd7qeA/iMT8QOunzL2GaWZWlX8lHF60gRh78w8JxNSBw NEwNqmd8hI+7mW3Tth9e+aWuANDrh8+B9HtqE+Ca/SftP5l2mwSSKR2+w2S5g7V4erORApFZhCK eGl2e4jFtqDJiAFybUl5JVNE6TxD2Sq3nViHbMbeGKmIFXe/EGiBpwosAsqE4csb1EqwgLGuSal +Nlt7NnN6qLLFxU5jax8n5skgh69Jye/1ciqwbWgWg77nTlKSymvgw== X-Received: by 2002:a17:90b:37c6:b0:368:6ff3:6678 with SMTP id 98e67ed59e1d1-36a676364e7mr12890985a91.20.1779703118015; Mon, 25 May 2026 02:58:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Mon, 25 May 2026 15:28:26 +0530 X-Gm-Features: AVHnY4IpuIA8wit6JdmXWa-BJjzehRMF7cdTeNLne8gQ041AQEDOUat4IOlQsrQ Message-ID: Subject: Re: [PATCH] Release replication slot on error in SQL-callable slot functions To: SATYANARAYANA NARLAPURAM Cc: vignesh C , Fujii Masao , PostgreSQL Hackers , shveta malik 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 Mon, May 25, 2026 at 12:42=E2=80=AFPM SATYANARAYANA NARLAPURAM wrote: > > Hi > > On Fri, May 22, 2026 at 2:16=E2=80=AFAM shveta malik wrote: >> >> Thanks for reporting the issue. I could reproduce the same issue with >> all these as well: >> >> pg_logical_slot_peek_changes >> pg_logical_slot_get_binary_changes >> pg_logical_slot_peek_binary_changes > > > Please find the attached v2 patch that addressed these three cases as wel= l. > Thank You for addressuing these cases. A few comments: 1) +-- Test 2: session remains usable after the error (MyReplicationSlot clear= ed) It shoudl be part of 'Test 1' itself and thus should not be named as 'Test = 2' 2) -------- +-- Test 4: copy_replication_slot with max_replication_slots exceeded. +-- We reduce max_replication_slots artificially by filling all remaining s= lots. +-- Instead, trigger an error by copying to an already-existing name. +DO $$ +BEGIN + PERFORM pg_copy_logical_replication_slot('regression_slot_t3', 'regression_slot_t3'); +EXCEPTION WHEN OTHERS THEN + RAISE NOTICE 'caught: %', SQLERRM; +END; +$$; +-- The original slot must still exist and be usable +SELECT count(*) =3D 1 AS orig_slot_ok FROM pg_replication_slots + WHERE slot_name =3D 'regression_slot_t3'; ----------- I don't think we can hit the Assert with above test (at-least I could not). Since creation of slot itself will fail as the slot with same-name already exists, MyReplicationSlot will never be set and thus Assert will not be hit. A better testcase will be below which fails during LoadOutputPlugin() after slot-creation and MyReplicationSlot is set already. SELECT pg_create_logical_replication_slot('src_slot', 'test_decoding'); DO $$ BEGIN PERFORM pg_copy_logical_replication_slot('src_slot', 'dst_slot', false, 'nonexistent_plugin'); EXCEPTION WHEN others THEN RAISE NOTICE 'caught: %', SQLERRM; END $$; SELECT count(*) FROM pg_logical_slot_get_changes('src_slot', NULL, NULL); 3) So overall these are the problematic APIs: pg_create_logical_replication_slot pg_replication_slot_advance pg_copy_logical_replication_slot pg_logical_slot_peek_binary_changes pg_logical_slot_peek_changes pg_logical_slot_get_changes pg_logical_slot_get_binary_changes First 3 are are mutually exclusive fixes fow which we have added testcases. Last 4 are addressed by fixing common function pg_logical_slot_get_changes_guts(). I think we should add a test case for at-least any one of these APIs to cover pg_logical_slot_get_changes_guts(). Thanks. Shveta