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 1vq8ZM-005HhI-0S for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 11:39: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 1vq8ZL-003cVv-0U for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Feb 2026 11:39: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 1vq8ZK-003cVn-2e for pgsql-hackers@lists.postgresql.org; Wed, 11 Feb 2026 11:39:43 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vq8ZJ-000000008nl-1TMg for pgsql-hackers@lists.postgresql.org; Wed, 11 Feb 2026 11:39:43 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-354bc7c2c46so2589695a91.0 for ; Wed, 11 Feb 2026 03:39:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770809979; cv=none; d=google.com; s=arc-20240605; b=c2N+uL15rVlDCAk10M9cBXBuYEioI7ZI6TUa0E/UEfrS9yC3iYTN/w0SE3lBNohVXc NcyJdXQKJG455QpyIC1KsFugn5bZqG3BK8g6ZiowkZRvKhh1HkmEeyBFEhk2GG5qq9E4 LfVRDzKZyk1Kvnr+uuFqEfV/DH3VxgsjPASnZxQcfFSeNnMfCq2c7PNQinaZqqvqjfLY +pgKaL1QONYt4zH5sNftSGd8w02kKxhPAVP19HjdKIdm5hO9WFjk4pPuI8pLHrI3s3+A gA2+Fzs7PKnOhoStT3nh0uQfrLoiTTqMH9qrUz1CJhcvAV2qyP0F0beRbwx/FHKH5NmV 40tA== 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=pbt9DhWb/Nd7zHm3vyph76dxtWS+cwT3eKQayNkpDRo=; fh=poyflU2+Jkhowy95TagUK3idBFxdE+8qHz0/B93vJdQ=; b=cwpHgos3rmYXPssikkOY6Xtf7vM3tD+YjyuVYwX5yk6x+UuLcQQGFyx4kieVD0F63h OLQA2coonmx4RGhzf0st1J7u822uMhEpVpPxGM3ro2vkvvXpNzfe+ZZ/jhIvJh7hAoko YFAGP/XLa5eH9QZi12Gr+kdYbxzFX3cCBzKseHJCAC+qa/oExvkhA/3rJ7HbfXBXXp4D fqHufdAlkc4amqNemrPimyFzikhTbX08GzbVZp65ompLFXv38tdLF3RSxaDimJJ0A+Ok ttu8uoJQUxaoFv9miJPLh7w2JPsGJSpbjjoqQUx4EQw1rkCI42McGmm2lUR/ysRjmpyU 3f0A==; 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=20230601; t=1770809979; x=1771414779; 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=pbt9DhWb/Nd7zHm3vyph76dxtWS+cwT3eKQayNkpDRo=; b=Y8JlJvX6dVTWW4oBXM90Yvp8VO4Our/vXGRk+Hn1a0tlHhyks0RCHo3P2dvlhZKxnn IlmzBVkxrwOFB4CDXInEo7f/Ex7+SqvhaJn0vQauHlPhUIzh3eHYmDbXuP3gv3gEMn+V Kgq9EQdxty9VDNDlhxzqpGpQmXgbPI41vikuJ3klM1ORpiAVjDfLMRzl1mxj101S/7ck RO4o+nFpLriUz0xk00BCu7cqK/HeBzdGj73C/wm7czZ6MhLLcNLgqdmlDYJeisU209Ue twq0NssnSSF8t7ZPdYcB47KlnRenguj+SUrrJBeH3bfXJdMCZ4If5ex+q95ogCryyhEL AMhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770809979; x=1771414779; 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=pbt9DhWb/Nd7zHm3vyph76dxtWS+cwT3eKQayNkpDRo=; b=lsm9dKHkiFUGTcIspQqK6x8VrQkHYGYvoZlSrgHvvlBMjemicbNjsn6eW0dj8CqTT1 GoXZLvWjkBA9AW6PdBRVHfQ8kFOB9kWZc3JI7HR7n3W2bU+VZ91+tqbhbyVkdNpy1ui8 fpNmQLtmhIqqTMcv2d1+EGra9ShA9exPCwgTvYdDIfUmwDxoTrX+uFTQIjpLc2DtJ759 PHPfkqq7J1pQlRDn5DZ+mCOpA1jFlfP9Sw91p4cveIHQSuHvIq+9fRX3w00hqvtqPLHv x5f0wmXwEQrWvdgq7cdlO1tl4wIlAzvk1yKm0zzmKtraeG35LaZKymDtfuKHwMB364iq mZ4A== X-Forwarded-Encrypted: i=1; AJvYcCWpn1ZtG12d2HZdqsk/VIhn5ssBCq/7akFodgJTQz6PMDwX3whagtI+Inc53egYDHn0TH4+NYLRDfJ8F8E7@lists.postgresql.org X-Gm-Message-State: AOJu0YxlFtDaR3LqlxFtsDHKXj+Qh4GWfcJkU+7xw37BzT4do8o1h4UZ 4KD+rR7I1oK1I8IRN3jHh4vnsoP0ZCIRYSs/rxLxTDRDjBFEyoYSKdrTx/JGNEKGtiiIsqNwh2S nlhHqYM+O13rnmTUL4z7WLxKfXkw2fQU= X-Gm-Gg: AZuq6aK+0LufO61jdXebTJ60uxV4q6rdEMbe64MTlVnOR1yGKTB8pAwaIGUngrhh0R6 l7YIA6unFQVTas8j0dhRWWOYMTo6lYHA7WaPUMM4XO75HEJCQWLh/bjBviLM4/UmqR/UqXkwH9J QoJGJebXFlzexxGjUJMi/S7h1H1WRMqGo+AoNXqJEU+HCyIFSIV4lJNezBn1E/urtgEwFMCzz8O k6Xw5AoEDha0W5b59e4dPXYokCmhsFmr5wgwq7sGY9xtRakiuMZw1ltXBT/qxEv53HGqDauIoFQ nDtseNHUDdOvkYe44CJJ6PzU2VTZEPl8OKgynCgUB7RHON2QPtIu X-Received: by 2002:a17:90b:3d45:b0:354:5ac4:2d5c with SMTP id 98e67ed59e1d1-35667d4d352mr4483530a91.26.1770809979213; Wed, 11 Feb 2026 03:39:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Wed, 11 Feb 2026 17:09:26 +0530 X-Gm-Features: AZwV_QidAPfo_AUH2GuC3B6oySrT1RFci6PkBkIYEPqjcsuqSgxHkGeT4vvT2OY Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: Amit Kapila Cc: Heikki Linnakangas , "Hayato Kuroda (Fujitsu)" , "pgsql-hackers@lists.postgresql.org" , "Zhijie Hou (Fujitsu)" , Doruk Yilmaz , 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, Feb 11, 2026 at 3:41=E2=80=AFPM Amit Kapila wrote: > > On Wed, Feb 4, 2026 at 11:32=E2=80=AFAM shveta malik wrote: > > > > On Wed, Feb 4, 2026 at 12:38=E2=80=AFAM Heikki Linnakangas wrote: > > > > > > > > > > > The second patch rearranges the if-else statements to check those > > > conditions. I found the current logic hard to follow, this makes them > > > feel more natural, in my opinion at least. > > > > I=E2=80=99m not fully convinced that it makes the code clearer or bette= r to > > understand. For example, consider the following error case: > > > > else if (curstate->acquired_by =3D=3D 0 && curstate->refcount > 0) > > ereport(ERROR, > > (errcode(ERRCODE_OBJECT_IN_USE), > > errmsg("replication origin with ID %d is already active > > in another process", > > curstate->roident))); > > > > > > The condition was self explanatory earlier. The condition has now been > > rewritten (or reduced) to: > > if (acquired_by =3D=3D 0 && curstate->refcount > 0) > > > > However, this is not exactly the same as the earlier logic. On closer > > inspection, the condition 'curstate->acquired_by =3D=3D 0', while no > > longer stated explicitly, was implicitly guaranteed by the preceding > > error block: > > > > if (curstate->acquired_by !=3D 0) > > ERROR; > > > > One way to make this clearer would be to structure the logic as: > > > > if (curstate->acquired_by !=3D 0) > > ERROR; > > else if (curstate->refcount > 0) > > ERROR; > > > > Even then, it is still not clear why this error (the case where > > curstate->refcount > 0 and curstate->acquired_by =3D=3D 0) is raised on= ly > > when acquired_by =3D=3D 0, or how the same situation is expected to be > > handled when acquired_by !=3D 0. The earlier code was clearer in this > > regard (at least to me), as it first handled the > > 'curstate->acquired_by !=3D acquired_by' case, making the overall logic > > somehow easier to understand. Perhaps we can try by adding a comment > > or restructure in some other way if possible and needed? > > > > I see your point but one advantage with the proposed code change is > that it started to appear that we can extend this part of code easily > in the future as it separates most of the handling related to when a > user has given acquired_by parameter's value as zero and non-zero. Okay, yes. So I am okay with it. The slight change I suggested (if to else-if) and a comment will make it more clean. > > > > It has one user-visible > > > effect: If you call the function with acquired_pid !=3D 0 and the ori= gin > > > has no state slot, *and* there are no free slots, you previously got > > > this error: > > > > > > postgres=3D# select pg_replication_origin_session_setup('other', 123)= ; > > > ERROR: could not find free replication state slot for replication > > > origin with ID 2 > > > HINT: Increase "max_active_replication_origins" and try again. > > > > > > Now you get this: > > > > > > postgres=3D# select pg_replication_origin_session_setup('other', 123)= ; > > > ERROR: cannot use PID 123 for inactive replication origin with ID 2 > > > > > > Both error messages are more or less appropriate in that situation, b= ut > > > I think the new behavior is slightly better. The fact that the origin= is > > > inactive feels like the bigger problem here. > > > > I am okay with this change though. Let's see what others have to say. > > > > Either message is fine with me in this situation. > > -- > With Regards, > Amit Kapila.