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 1vnVyR-008EMi-1A for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 06:02:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnVyQ-009KOn-1d for pgsql-hackers@arkaria.postgresql.org; Wed, 04 Feb 2026 06:02:46 +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 1vnVyQ-009KOY-0P for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 06:02:46 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnVyN-00000000yej-2PgB for pgsql-hackers@lists.postgresql.org; Wed, 04 Feb 2026 06:02:45 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-34c3259da34so242250a91.2 for ; Tue, 03 Feb 2026 22:02:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770184961; cv=none; d=google.com; s=arc-20240605; b=AedKBy5416EVLkKfsFdDakaquJLjsWj7sRFmAEWXq7a9IzqXQ+D7SQLhy9raRxGojL BiVa7mjdN5eBvby9iVu/grbD/OzZ83DZBN8THuCwqbwdGsU/dwJM/DBzgHNXdN7MwbyV c2DoeouoXwv314lpe7epfWFAB5fWSZ3+Z7tDdcp1pVt0elgsgG2KylKuLUpwz29CHVDC yHB9sVq72D9CZQ8E0qxq1SBiXFlQVPKIbuwCDuT+ZbXN6MnTcUO8/4Lf3nWoGeBLXNXs XHlw85Aj61T8bRn9kmfuUSxyEYEivtQ7zAGoO/hvq8g6QrqY7/o5N/Vd2uke7YJCMcKq T3MA== 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=Utt0VZzHsFaD7TkrJz/JN9dLL4XqIo1pViDUjom3Grk=; fh=IGlqPK/sxs0nuje3/EF5cjjhzFP06DSWWSf+nbNJ/6A=; b=TVC97/eAJfpSOKSrPzoD1V4J0FdrLSkD63dAHR6hxqUqRetbtoWkO+MDPF9/T4ast9 liQfNK/5UEss8MDuG/Co3Di6UnaESi33hRqJGAnLVedm0AXwVR9ZoxuxxSwtJ+eD0Sst axVoLz86axBZuxjLLziWOZAJTn7HUi0iHUeSPYxMUInzCJCVlPAD+Yr4P0xuE0WRt4ww 50cuEKuDlspQY+oNWkGees7oxR+rzq3xJ62VAWWZmg5xuU5XlM1lxwYz6bJ4cOUHm5oV nXfhKhmCeCLlDjLFhPV/BGGs7N4gtKofw/UKQ8VMhzSNL6VL5v9TMd8aAX7bBLb5RxEJ cFSA==; 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=1770184961; x=1770789761; 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=Utt0VZzHsFaD7TkrJz/JN9dLL4XqIo1pViDUjom3Grk=; b=V6Dlpb4BjhZJHciKOXkrVCXeO0rAlTF19ex0YknxQPFcyvubs8vFoZkufZH7YMDotd 5eVclPS/oV7oaYlYuwQrhx6X1fBWwlglDyccMv8VzbZ5iHAVIEHVtXjUa6hGUs8MuRxG OoUvCISNIQ/JFZ1qbQCx/ILDkupNwjfj6VHW8zHmcW1nZ1ImIZcviixJqoVnpIIXyp92 9YNUkmThMM1KdQsaWqv68erh744RH4YnhFpPtOpJEbNY4YTdrSysPzO5IawKOU8+EYVt 2uJlTbP2ZzNUP639e9P4gOYtdqj9RORX6dzmjN3ImwRFAZCVylJfV7y5L+NIZvI3zOWv av9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770184961; x=1770789761; 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=Utt0VZzHsFaD7TkrJz/JN9dLL4XqIo1pViDUjom3Grk=; b=g3T3FFZuxTemuqn5yt0VoKfM/7U5yrs+aSaS1nWW/GQsxhKDNuKoN9wOGbg5t2zfio UC4+5FeOtPKpahqn0jxWgO5YS2rCZqhMkaUj0G0jCfK+HdjPB/Ul2aomqU2plwyOpGpz 1jhvNqF5fOqlsqyoaHbhX5h660OWOE8vH+V6NY60qgGEliJ4iiZhNr6lM158wJYHg/Yo 3JoQDeZ927/fC3Z51xQE3/iKkbH3QNWIo4IEH5AzGFntStTzb88jUQgP3VysBJohYnwK NQmo2Fd0UXIQrPOVKzn7BeZKf8zwnh8SaTi2pbKvTXsqj68aVVyedIy/1E5f4anWKBxm +b5A== X-Forwarded-Encrypted: i=1; AJvYcCWpv/rV5qs0RZLz8aynNjCGz2/jnCLuKvWbSVIYeANShwEX0n2HyKXkpgechhgu+6mFexecKtYIYsCDrXY9@lists.postgresql.org X-Gm-Message-State: AOJu0Yw2tlqejnWgNG9Q/y13b9R/7kSyQB/YdyqRoF2xHU4aqefDc659 vxVmFmeUOndP+LcPuZ3SQFRdDU54mHYQprOQV2GDShngZJfa409+MeVHIAkKbdec0Y6/yXyzm92 pkIbWBCuSOFYYLdfJ/G59ZmHnmvcrlA4= X-Gm-Gg: AZuq6aL9FI477o6jWvkHMnOdBlyNqtqYtXtGZcEzkFW77ghisAQYAT/e+VSM0a6uD4S oG73Y7ERo/lWTGp65iZcOoNHjdxq257yW7wWLhZ9Y4E+xvdLMpPjiNBzSfJ/yevW9LsdNNH1lPO q9Wykp3xZQEYnFKh+gXu1+lqdBfnbRnO62rfc13CAujAK4bYSL229AUWfedyCk96STYMn6mFf1u YjBwNcDU4s4rSSH4U/pkWX+K1v4tiHopwhHfD4DRat7O5Y5cQXYB044LO2zSnWM2oo5bWpx1xni VV97tVW4/VR0PK+8BwzwhQBYLUO5dpR7apKQCF6BaiNEsBUPsEbTlcRDIiPM45f5r64qgTiP X-Received: by 2002:a17:90b:2e0d:b0:32d:d5f1:fe7f with SMTP id 98e67ed59e1d1-3548711595dmr1775597a91.15.1770184961063; Tue, 03 Feb 2026 22:02:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Wed, 4 Feb 2026 11:32:29 +0530 X-Gm-Features: AZwV_QjFrVmbrjZMf_OXmexDK5lcXZS4pp5fndWQnt5ak3spaQhrAUrdtR5oiNA Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: Heikki Linnakangas Cc: Amit Kapila , "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 4, 2026 at 12:38=E2=80=AFAM Heikki Linnakangas wrote: > > The new error message is not great: > > postgres=3D# select pg_replication_origin_session_setup('myorigin', 12345= 678); > ERROR: could not find replication state slot for replication origin > with OID 1 which was acquired by 12345678 > > Firstly, replication origin is not an OID. Secondly, it's a little > confusing because the "replication state slot" is in fact present. > However, it's currently inactive, i.e. not "acquired" by the given PID. > > I propose to change that to: > > postgres=3D# select pg_replication_origin_session_setup('myorigin', 12345= 678); > ERROR: replication origin with ID 1 is not active for PID 12345678 > > That's more in line with this neighboring message: > > ERROR: replication origin with ID 1 is already active for PID 701228 Thank You for your suggestions here. The suggested error message looks better. Thus patch001 LGTM. > > I also wonder if the error code is appropriate. That error uses > ERRCODE_OBJECT_IN_USE, but if the problem is that the origin is > currently *not* active, that seems backwards. I didn't change that in > the attached patch, but it's something to think about. I agree that ERRCODE_OBJECT_IN_USE doesn=E2=80=99t seem like the best fit i= n below code. IMO, ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE would be more suitable.But let's hear from others. if (curstate->acquired_by !=3D acquired_by) { ereport(ERROR, (errcode(ERRCODE_OBJECT_IN_USE), errmsg("replication origin with ID %d is not active for PID %d", curstate->roident, acquired_by))); } > > 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 better 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 only 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? > It has one user-visible > effect: If you call the function with acquired_pid !=3D 0 and the origin > 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, but > 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. thanks Shveta