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 1wSq2S-0008dk-1P for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 05:45:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSq2Q-001fS9-20 for pgsql-hackers@arkaria.postgresql.org; Fri, 29 May 2026 05:45: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 1wSq2Q-001fRz-0p for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 05:45:42 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wSq2O-000000005TI-2Zzz for pgsql-hackers@lists.postgresql.org; Fri, 29 May 2026 05:45:42 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2bc763e2ba8so68681605ad.3 for ; Thu, 28 May 2026 22:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780033538; cv=none; d=google.com; s=arc-20240605; b=THUzKJuz252OTFoP/U+G/Cn/Zy8+iMZsV6IfdV5PeNguFHjhZXoCywFd34Gi84qtGT hwD27aMVUsncKmLRi45iyMdUpo6J/ztRVvp/NS1zZs0wUrxHxfh7PDvLYic/wj5ng0nS TjfvYbekW0AV9uCN+FsQwNY+5TuWr7x526rymUzVsPRBuR4fd1FHVROhYgRAAl5ikS/5 zCZ893CwSEcJju9xOKxl03HeScAB2lVZp70a7+CETRuJGYF7kqmgXvqsMxX7Y5YmrdK/ eXFbm+I/R7ZNf6Dp+we4XwCQNZ+9fSuRvRsQhT64ZUIlu+yqLE2MKXEVZHDT6r0GY/49 QswA== 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=lWsl/VRQY0bxsHhpHtW0KMhyfJeJpL2Ax1pl/YFTWRY=; fh=CJJfvrHPj3vz7+G43uMv+xJtwbK5guk1nCz+E8EFIvU=; b=LitcubRJFlKhZK99IFY5sK/utv9of9et7NmVAdhzLvq2syO8gFkUKUc3H7XywcSTI1 6rkC/rJFQ5ixEMdd3HKxgJ3qWQqNVKdoE8V2WtfrDFQIazKdAORbBDlVoGFi9cEh4ukd tD3JlvUkZi+kh0XUB5XSxpmCPjOxEsNREBod4xhTJczAvtARJVJtGw+6WqbD5cZ2iuIO jO05JEpQGEk42rtp4dU7/iMUs7PLqlTxYkMkv6aGPPxcWEoKP3vmkItUidG17DfZoiaR NVCv642/CHBtBmmvnrcVNhEtENNXm1AtYKLk3bqzQS7VtLGd6FvDf0Gm+xz1muTvHV2S mLYA==; 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=1780033538; x=1780638338; 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=lWsl/VRQY0bxsHhpHtW0KMhyfJeJpL2Ax1pl/YFTWRY=; b=D+fIulFm1Nh4nnCptEVVMX4hvSCWmhd3dqwsa8hp2Po1T7sI6kHZcEQ8J7kAFqj2Ha 3k7pBrdS7f/ELWMFb444XxHP3q1Ott2CaLsHbYY++2mwlfwaBy1SMh0qIXBC+WPRVR82 HzehfTgkR6hmyRKx98OBk14P96SgxMZaF8homw8a07KcTdFbfBNjsJ5CkoEMiZzTcB90 Zaw2BjjW8hvfnoLzfmoAUD/9EvivLOAj6jKuFNysZtOrX+sOAsx7xrkK15sao+7gjxa/ usnavP6igY/wbKjo7yb/WlhuViAUHfp9Ji6ghKh0iktM6dM9oHEFRz8RWpHHsCIJw+2V FyEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780033538; x=1780638338; 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=lWsl/VRQY0bxsHhpHtW0KMhyfJeJpL2Ax1pl/YFTWRY=; b=K3vgti4qFFyjH7tkohgnrGgc5oQFWO8WzQNsEOoytR6O1KQLvvk5Bx9XzirBGZOtc+ LN/67xDdoxZefPMq1AkSQ52JV7Rnmsit7UVja0SeRzmDarsKc78zKeeXN8Oyij4DHbgY T03lxdOKTq9Rb+IeX1s5zvDW8GaIIS26PNLvlUwRxmYWDB5NSigZnOaY8Y5Bjyg8w5jZ ac907DlHhX7NHADjV+UB/mdJzzwMC9otPQQNDPrY29xTKgP9AVWEyt/fSnDmZKf9tnk+ CUkFg+qwoY6OU/n04oY8VmrrrWWO+AG4wlXCkqRmf00aMKnDBQZfSKVWelZBJ2F90Iou MrVw== X-Forwarded-Encrypted: i=1; AFNElJ+YgQhyQvr5be8PYCLTY2PsBkBgI8MCH27RKluE9RL5mjcZbhv/7C1zdwgpFQp+xc82VdxZ/JSCfFWRAHYN@lists.postgresql.org X-Gm-Message-State: AOJu0Yy8i5FFotQar0O71R425HRzYS5Rq0yCxAdR9N1bpgh/W2fa6G4i MN10QwimAiOemasRdiTbC51qTQT3D8WG9mPxLVzeXzptab6dcVf9FvFSjWk003K4DLZWwyiFNQ1 FGsNEkMpbjrOccsFmNeTAClObOsGDNMk= X-Gm-Gg: Acq92OGKufcfZbxRT7FYVSiGB2V23JQWJektjMRK+Ggyw+GmquSE06XSpPeNcAZwhzr BdNEtaeGW44xXeHHa7oUyRo/rG5e788+FE85oCBXMZ5bKlTEPbFHZC0Rapt1c8RlOfFiogZ7SGv uN2Kz8STmsNdphVUiyjzW+WB17CMVeZTgBlX8A42stu3zcTnJX/pmof5u/0v1QgwuG3/546n8Nu Lv0s7Zt/+XD+LGs+z2nnPwfNebAmXNvIVFdodgxGFsUuuw1N/LkhpM3Ooj25ICHey3SL8AUCOFZ WGg+y3aW77qpJdvR2AGNs9IjSlhd021s/RwbFTUHPrhkev0VUOSDk/5AGFhUcg== X-Received: by 2002:a17:902:e545:b0:2ba:6ebe:4897 with SMTP id d9443c01a7336-2bf204d8c3amr20271615ad.3.1780033537615; Thu, 28 May 2026 22:45:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Fri, 29 May 2026 11:15:25 +0530 X-Gm-Features: AVHnY4K8hhhz42zpcaQ37MeBo889onnQ_BmHffVIT60k-CF0AkAx_B8cAxNJn_I Message-ID: Subject: Re: [PATCH] Release replication slot on error in SQL-callable slot functions To: Fujii Masao Cc: SATYANARAYANA NARLAPURAM , vignesh C , 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 Wed, May 27, 2026 at 5:40=E2=80=AFPM Fujii Masao = wrote: > > On Wed, May 27, 2026 at 8:00=E2=80=AFPM shveta malik wrote: > > pg_copy_physical_replication_slot() should not have it as the common > > 'copy_replication_slot' is already fixed in the patch. > > copy_replication_slot() calls create_physical_replication_slot() before > entering the PG_TRY/PG_CATCH block. So if create_physical_replication_slo= t() > throws an error, wouldn't the same issue still occur? > You are right. Using v5, if I force create_physical_replication_slot() to fail while executing pg_copy_physical_replication_slot() (through debugging), I can see that the next slot-related call hits an Assert. 1) I also noticed that for pg_copy_logical_replication_slot(), we do not hit the CATCH block of copy_replication_slot(), but instead the one in create_logical_replication_slot(). That behavior seems fine. However, I noticed some inconsistencies in the implementation. For create_physical_replication_slot(), the caller pg_create_physical_replication_slot() contains the TRY-CATCH block, whereas create_logical_replication_slot() contains its own TRY-CATCH block internally. I think it makes more sense to keep the TRY-CATCH handling inside the internal functions, i.e. create_logical_replication_slot() and create_physical_replication_slot(), since that would automatically cover all callers. For example, create_logical_replication_slot() is invoked from multiple places, so callers need not worry about cleanup handling themselves. Similarly, for create_physical_replication_slot(), we could move the TRY-CATCH block inside the function instead of having it in pg_create_physical_replication_slot(). Doing so would also resolve the issue with pg_copy_physical_replication_slot(). 2) I also feel that ReplicationSlotCreate() should be moved inside the TRY block in create_logical_replication_slot(). Currently, if in the future ReplicationSlotCreate() gains any post-slot-creation implementation that could throw an error, we may end up leaving the system in an unsafe state. Keeping it inside the TRY block would make the code more robust against such future changes. ~~ Reveiwign further. Need to review few more things on v5/v6. thanks Shveta