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 1wDEtJ-002lXt-1d for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 05:03:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wDEtH-003p1S-1s for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Apr 2026 05:03:47 +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 1wDEtH-003p1J-0L for pgsql-hackers@lists.postgresql.org; Thu, 16 Apr 2026 05:03:47 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wDEtE-00000001GDe-3SPk for pgsql-hackers@postgresql.org; Thu, 16 Apr 2026 05:03:46 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7d4be94eeacso7861648a34.2 for ; Wed, 15 Apr 2026 22:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776315824; cv=none; d=google.com; s=arc-20240605; b=Z5Z8ThL2/5gtogEGQohPkA9ac21sVZhnamPtGyU+eJHwB2G5dfEU7Nq1IReRgJ9l4M jI1d3GYNdeiQXjhDHge7nt7opiCmYb4sPWx1DPeJ4jBbAC4qDxMwyJwPhMac0WFLA/Um 5GkYPVcPYCnVyGFQKNGCZm+8h1x0I36c6EZ5NG7Doi4UX/6DbCh+0+Trqz5qX5XMLABJ ntXlsu3zDC2TE5OzIQSjSbsWa/CoO1Kvh6bM2czVrLwwZLi1ljgGWv3xx7npqY0h6WY3 f2BwntlCe1bkBdodL8pqbQ+7yi/8Vgs8sV45Shv5lRsJhu6ORq7ig9V2xBTNMQxsF7go zteA== 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=49lKpZalvSbCoLgfWjWf0jvhc0E7cOT7lfNLxj3FVIk=; fh=DQlAHAhCzydLyHGDL2G4BV59lzjePte/AziN/EyuTNc=; b=cd1vtryHvlFIf+W04YGbVkiep21L+iC+mvRQwe6HiWRC02/eANi6eRLUT9yt+PxwDR YbbLsc5fH76P/4XEAp/5ekPCmvtoOMkiKPsW8Y9Wjsrox5Nk+JcGWjrsVd+FifelW9Be PZGmbxI3OPuVxPirZ+Lru/BG1gG7Bm6hgVMZJIYzcVRXisPjxXofB4TwcAapBy0QEqXa rZUnFmAYX3NxJ+bpKurx4robuiGtkfKbm4OSZNyf9jR5yDRBMC6WHT97PiPKwNOLkfS0 ZchaR0h2PGteZNzNLDlvF2QfcjkMWNLIchn5nlbEc/4yGY+qGMsxAGRpNvPC2lBSrFMN TTsw==; darn=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=1776315824; x=1776920624; darn=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=49lKpZalvSbCoLgfWjWf0jvhc0E7cOT7lfNLxj3FVIk=; b=NX8yJ+8aFKPwe8E7uikuw5rshQHDelAPSn7Jaa9Y3vMdRvYZX6KHGavyrDuw34JgTx ao1qMAfwXsWQCKDPjXYYOgZytoDK2wkhrluzVJN46lNyrk+r3jv8HxofNmBLgjXFtcol +zeX7PbS0jAyAKYnM6Kmx2NZDUZrkl3BXh4DozQkf3YMFznKKaabHVp4a4P/IcpBZfKd HXBdakV/SefwGNRQwoSyOM5pl7xBuHom7pOd1xx5h6nbTOm49gPyn6rjKhjp2yPBdkUK QgSBg88z9IKuas8ZAXHJm9c4goyFE48etr+TOIM2fwZz36+g+Mf+NOh1pYIAxhcA99wf 4sTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776315824; x=1776920624; 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=49lKpZalvSbCoLgfWjWf0jvhc0E7cOT7lfNLxj3FVIk=; b=lwHTJTy5ZvGX+DF7Up6OQB3IBEMaeXblivRxbL47mD0I9ipOyouMi8MiAczLjOCHIr R9EKj20iY7nu3wMDst7SiswcY187n4w8Q3yvXB7qRPV6YaC7+tY1qtvxmvWAyDbHUiBB ziC/2zb0WMi9yQcNlhSCmI6Fu/CUh7uMbFQs5kYXKg0KycDcfeifbZyIcsj9B3DcfiLx ym/9NsW1Ct351k9mpUCtkNhnhfq+iy48RTZJy2s7vWRoVwsuDS0arefKoHFfoqqQbEf5 Z2fOXBP/m4pceIsJo49mK7HP2MdCMieFF1vRVBClzqi8liPAQQco2h/UWvavwRoAxOCS GIQQ== X-Forwarded-Encrypted: i=1; AFNElJ9yfa7yXlmAi1f72XbJa9TQ2wFP64T2iFle5k6NrhiWX+ggF+s79VhbbaGQMjQSe41DUqMMyI61XKHpERMg@postgresql.org X-Gm-Message-State: AOJu0YwBgpHRTNwsLiRQMaWsHqBTm8hQcdXi+R8ZgTqfYG5N4ACmmU8Z c/Wy9Zzm54dF58o5E5vZxKsZpPEW5MwfeKyvsTr6XrQl25poYPNFzrChUiMPJoRON5pekkfyrMn gDWSLoDLrGAKaW3MADYeGcu0sTvSwI9Y= X-Gm-Gg: AeBDievKproLQOb8nWO51/kfDgyrBf370ePSQZ1LW48iL6mN2R+Z19HoV2SGs2d1UBE w18sBHMOAfUtJcz//W+ORKRBY2EpBHaKp2U890JVrI2pO5U80hmBsYnceYIvQzj6tGUDkwwoD64 lW1xQ8awXnxvDWNfIrhrHsefhO2VKGx5ZKIWuVdQ30Fpc4T2UbAjL1FOKjzbYn9onNKuquLK1qn pXrW9t0kHmTLHuSKstcddg7rZB14hdUEKIKt9yU/IYe5EY6Rk+3Vu4wPH++KfStinfrBHXwv+7T 1TOGDpXJN8m7CMmLFqlBAGdbUa7RVtS2l/YSVMg= X-Received: by 2002:a05:6820:1504:b0:693:17ae:cd09 with SMTP id 006d021491bc7-69317aecf72mr3095016eaf.20.1776315824469; Wed, 15 Apr 2026 22:03:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Wed, 15 Apr 2026 22:03:33 -0700 X-Gm-Features: AQROBzC7_2lvdUVVl6Uvu5IHfhwzncp_5TwGIyQAXRLTI5WhMf3MtbqJv4I8a34 Message-ID: Subject: Re: Introduce XID age based replication slot invalidation To: Masahiko Sawada Cc: Srinath Reddy Sadipiralla , SATYANARAYANA NARLAPURAM , "Hayato Kuroda (Fujitsu)" , John H , PostgreSQL-development 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 Hi, On Mon, Apr 6, 2026 at 10:42=E2=80=AFAM Bharath Rupireddy wrote: > > On Mon, Apr 6, 2026 at 1:45=E2=80=AFAM Masahiko Sawada wrote: > > > > > I took a look at the v10 patch and it LGTM. I tested it - make > > > check-world passes, pgindent doesn't complain. > > > > While reviewing the patch, I found that with this patch, backend > > processes and autovacuum workers can simultaneously attempt to > > invalidate the same slot for the same reason. When invalidating a > > slot, we send a signal to the process owning the slot and wait for it > > to exit and release the slot. If the process takes a long time to exit > > for some reason, subsequent autovacuum workers attempting to > > invalidate the same slot will also send a SIGTERM and get stuck at > > InvalidatePossiblyObsoleteSlot(). In the worst case, this could result > > in all autovacuum activity being blocked. I think we need to address > > this problem. > > Thank you! > > You're right that multiple autovacuum workers can wait on the same > slot for SIGTERM to take effect on the process (mainly walsenders) > holding the slot. Once the process holding the slot exits, one worker > finishes the invalidation and the others see it's done and move on. > > However, IMHO, this is unlikely to be a problem in practice. > > First, SIGTERM must take a long time to terminate the process holding > the slot. This seems unlikely unless I'm missing some cases. > > Second, the slot's xmin must be very old (past XID age) while the > process is still running but slow to exit. If we set max_slot_xid_age > close to vacuum_failsafe_age (e.g., 1.6 billion. I've added this note > in the docs), it seems unlikely that the replication connection would > still be active at that point. > > Also, concurrent invalidation can already happen today between the > startup process and checkpointer on standby. > > If needed, we could add a flag to skip extra invalidation attempts > based on field experience. Since this feature is off by default, I'd > prefer to keep things simple, but I'm open to other approaches. > > Thoughts? Thank you Sawada-san. I've been thinking more about it and I agree we need to address this. While I still think the scenario is unlikely in practice (SIGTERM would have to take a long time, the slot's xmin would have to be very old while the walsender is still running, etc.), I think it's worth handling. I can think of a couple of approaches: 1. Use ConditionVariableTimedSleep instead of ConditionVariableSleep when called from an autovacuum worker. Workers don't block forever, but they still wait for the timeout duration, still send redundant SIGTERMs, and a correct timeout value needs to be chosen. When it expires, the worker either retries (still stuck) or gives up (same as approach 2). 2. Make the vacuum path non-blocking when another process is already invalidating the same slot. The first process to attempt invalidation proceeds normally: it sends SIGTERM and waits on ConditionVariableSleep for the process holding the slot to exit. But if a subsequent autovacuum worker finds that another process has already initiated invalidation of this slot, it skips the slot and proceeds with vacuum instead of waiting on the same ConditionVariableSleep. I think approach 2 is simple. If another process is already invalidating the slot, there's no reason for the autovacuum worker to also block. The tradeoff is that this vacuum cycle's OldestXmin won't move forward and it will need another cycle for this relation. But that's fine given that the scenario as explained above is unlikely to happen in practice. Please let me know if my thinking sounds reasonable. I'm open to other ideas too. Thoughts? --=20 Bharath Rupireddy Amazon Web Services: https://aws.amazon.com