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 1vfX2r-002Zw9-2f for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 05:34:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfX2r-002xr9-07 for pgsql-hackers@arkaria.postgresql.org; Tue, 13 Jan 2026 05:34:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vfX2q-002xr1-21 for pgsql-hackers@lists.postgresql.org; Tue, 13 Jan 2026 05:34:20 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vfX2o-00093b-1D for pgsql-hackers@lists.postgresql.org; Tue, 13 Jan 2026 05:34:19 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-34cf1e31f85so4242371a91.1 for ; Mon, 12 Jan 2026 21:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768282458; x=1768887258; 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=ofKnvfjYlwDX6mPABfDkcEN1c2tN6lxnn5L1rzu/+pE=; b=OLvIc0jGM1MMlO6BXK/WlnXxrrf8nbjLC+9wO3XBwKbaqcpJYw/tbEj5TsL2dRkcMo a4f8rGOrKSiN44sDuRC3os58OM6iWvy1TBzqktHYbAJcvi0Jt0NdwwFSxcT0s5qHxdkR mFxm/jOhu8PxGBN53esTtjiAgpHwVBwVTJL0Crkeparki0+0WrO/76ije6TPQzx2gXn7 j9NHmI6I6j65N5VgOJnCpVTzrqjOIX2WPZohR2mspTmQ10U5lJgMfunpchOucAsr5bSj kijilB6y8g62mWSkH/O884Jc8KwhFwntkfhDaGDOy94znjVAhm5ycr2KvETq6KnzF3Qq 815A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768282458; x=1768887258; 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=ofKnvfjYlwDX6mPABfDkcEN1c2tN6lxnn5L1rzu/+pE=; b=l06VEWB2+ikVr0mhf2G41P22YimwreVh4QPhs1fUtzAAl3kqPMjHkELDlG8O2HYVlI fnMsUTgFL1JB7OhM9yOSnKITgT+k1r9esSz/ObQabl78cFPgcNknUEWP7FW4llDd0SXl z4UE3E32DzQ145HWR3ZAiMTBKwlheocpZwnX+ADr0qoC8nWuoosOQKd+6l8HV+OF1uHE p1xH9ZFMoOdcPbniX8CLM0F+yS/Oksvv0K/HNV7mv+r5diEn0BY5SLidhnU1noZ3i+wY lbUhZkFxYGgRBtAwVSb/v32qjxaoVJlJdsrv7LmEdbFwTFGYC0xjUQKyHlZi8MDOKYoO v2IA== X-Forwarded-Encrypted: i=1; AJvYcCX8rjb253gamWBOJT+7HSHwljev2WCryvNKaDORyKnmR0/WEDOCath+6YnyUa+4U1y5nC1BUFl4331JlTm8@lists.postgresql.org X-Gm-Message-State: AOJu0YxEJ2BUJbNcAqvbnuYjR05gymrhwmD5n3WbMW8V7gz3ZSq9Ni++ czH6pmpUVQ9DEnNWtZpOD5pwFOpueffDG+uK+B0Vz5rIj/XxFepyxcjoZvewMM2oma2JD2cPPS+ LnAz6vfPnoXvgdMyNMYOShlzuCg5+K/8= X-Gm-Gg: AY/fxX60FiY6odiV9Oud8A8PuHkNjGP379FNeh6J5VnziW0J/y3i9+5q/wXpsoMjajl QzFaxp2pNQtpEWrbPmeJVyPumqtnod5KXD8mO4psh8E7OgEcETaj2tz/DmK6Mt38UPhu4MXkzog NjcRQBQIRiJSIVWPQCnp2wdK/UFKTQoqOOAZ3mHOM+hsa8k57lkL2PNGYrWMBAgmswjwkTLN51n qB1afF0Y0eqvERxF++r+/ZUjcYiL5zaJShzwd3s+959C+hnaXh4HsPebx/wLCdPIb3oNNI3sPUt 0cV15dnjCtkUlK+VIDVa8YqMIqadpjwmEL5Z7a1ZiQ== X-Google-Smtp-Source: AGHT+IE0ZiJgS6w/GI9hiJW6dAZsp6xa4V1XTCcXnSc+/EkPOCU1Q/sOZOW+tgFJSCyCXzQoBTZrbxo5FDUmJ67vBgY= X-Received: by 2002:a17:90b:1d45:b0:340:4abf:391d with SMTP id 98e67ed59e1d1-34f68b78f32mr19926149a91.16.1768282458156; Mon, 12 Jan 2026 21:34:18 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Tue, 13 Jan 2026 11:04:06 +0530 X-Gm-Features: AZwV_QiJ8Pj5eW8pXbs1O7f08gq96FwF_MXPPZPC3UiX5XHX6ZwTVVWJBc00pLo Message-ID: Subject: Re: [Patch] add new parameter to pg_replication_origin_session_setup To: "Hayato Kuroda (Fujitsu)" Cc: Amit Kapila , "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 Tue, Jan 13, 2026 at 9:39=E2=80=AFAM Hayato Kuroda (Fujitsu) wrote: > > Dear Amit, Shveta, > > Thanks for suggestions. PSA new patches. > > > > Since user is not aware of internal acquired_by logic, the error migh= t > > > not make much sense to him as to why one session is able to reset > > > while another is not. Shall we make it: > > > > > > ERROR: cannot reset replication origin "origin_name" while it is > > > still shared by other processes > > > DETAIL: the current session is the first process for this replicatio= n > > > origin, and other processes are sharing it. > > > HINT: ensure this replication origin is reset in all other processes= first. > > > > > > > How about a slightly tweaked version of these messages: > > ERROR: cannot reset replication origin "origin_name" because it is > > still in use by other processes > > DETAIL: This session is the first process for this replication origin, > > and other processes are currently sharing it. > > HINT: Reset the replication origin in all other processes before retryi= ng. > > I followed the Amit's idea, but the origin ID is used instead of origin n= ame. > I read other functions, and the name is directly output when 1) the speci= fied > origin does not exist or 2) the name is reserved. We seem to use ID as mu= ch as > possible. > > > > > > 2) > > > When the first session leaves, while the second session is still usin= g > > > origin, the third session is able to drop the origin which is not > > > right. > > > I think replorigin_state_clear() needs a change. > > > 'if (state->acquired_by !=3D 0)' check should be replaced by 'if > > > (state->refcount > 0)' > > > > > > Patch 001 had correct changes in replorigin_state_clear(), IMO we > > > still need those > > Good finding. I put it in 0002 because it handles some cases related with > acquired_by =3D 0. > > > > > > > 3) > > > When first session leaves, while second session is still using origin= , > > > now correctly third session is not able to join it. It gives error: > > > postgres=3D# SELECT pg_replication_origin_session_setup('origin'); > > > ERROR: replication origin with ID 1 is already active for another pro= cess > > > > > > Error is not very informative provided the fact that now sharing is > > > allowed. Shall it be: > > > > > > > Yeah, sharing is allowed but only when used in parallel context by > > passing PID. I think a slightly modified version of the above message > > such as: "replication origin with ID 1 is already active in another > > process" should be sufficient. > > Fixed but ereport() was used because I thought this is usar-facing. Feel = free to > change to elog() again based on your matter. > Thanks for the patch. All scenarios (known to me) seem to work well. Few trivial comments: 1) +step s1_reset: SELECT pg_replication_origin_session_reset(); After the above step, please add a step to attempt dropping the replication origin. The original issue was that once s1 releases the origin, it becomes eligible for dropping, so the test should explicitly verify this behavior. 2) Also before the above step, please add a step where s0 tries to reset the origin while s1 is still acquiring it. It is needed to cover the path where s0 should fail to release origin. 3) + /* + * Reset the PID only if the current backend is the first to set up this + * origin. This prevents resetting the PID when other backends are still + * using this origin. + */ The second sentence seems contradictory to the logic, as we are resetting the PID here regardless of whether other backends are using it. Suggestion: /* * Reset the PID only if the current backend is the first to set up this * origin. This avoids clearing the first process's PID when any other * session releases the origin. */ 4) + * PID was not noted in the origin. This can happen the process + * originally acquired the origin exits without releasing. To make the + * staus clean again, other processes cannot acquire the origin till + * all using ones release. + */ Slight tweak: /* * The origin is in use, but PID is not recorded. This can happen if * the process that originally acquired the origin exited without releasing= it. * To ensure correctness, other processes cannot acquire the origin * until all processes currently using it have released it. thanks Shveta