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.94.2) (envelope-from ) id 1tATkk-00Fy0m-C8 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 12:42:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tATkh-00Dy6d-Ml for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 12:42:44 +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.94.2) (envelope-from ) id 1tATkh-00Dy6V-Bx for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 12:42:43 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tATke-001MMp-7Z for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 12:42:43 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-53a0c160b94so5319162e87.2 for ; Mon, 11 Nov 2024 04:42:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731328960; x=1731933760; 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=LvNzZR/ABT0KHssFJQjbUM+3vfqG/vO0CpzYLgglqso=; b=EKpng7mS0AC+U4ab+eYo0S930s6deeYE5LyE4jd3bfEopw6FKPTmxkU29naoGt44zh 6r3B74b8FO4rQ0eBTbfSuxrBlKe6U3aXfIyf8LZK5NIRAzNY4resa+O7s+Kg/9A+J3DE kv9Ht970A7PVzVJK9xBAvyBvxfjNa6tAit3Ze3YWE63xPt18fQcvPXXNgq1ClbJRBAK+ HR9QNed1fz3W1GtuhMmwnH7TfOj2HZHGhLBz3BcDgOKKgKweEqPmolpFQVFY3CP5pZmv TQcHf5QZHLXCKmZD62RCX2951NK/KYE0KVqTAQMU4sJZAQRSt4XPZoAVCKjPruNQoPza DckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731328960; x=1731933760; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LvNzZR/ABT0KHssFJQjbUM+3vfqG/vO0CpzYLgglqso=; b=K4AMaNoHp8iMesF65kIOfUt6Ui4klFW3lHbDOPNjqwqyVOGw32NcEk3fjp8vbwwE8C ROIdusLid9Qrgm4B5Y1gb3lNLqTrxqg6uxdtvngqVq+kxOQ/CZRW5y2wL5syqC7ieTyX NDmk7Catv/p0BqeYEpBGlUlbzp3HFGQQsonAFG4dwlcgKqGiKOT/nal00BR97Q/GEWTS I8c8vUwkP+Gn7ZQ7knewJ5eOD+wRNEgcvG5UqnA3XCap5FFFQl6d+V8yi51gIDQHClKQ Hp9Tfow54jsTUlElTsRP3eXXnWd208cwFDLI5gsvLnth64DK9bXl1Bnxo4tXUzYK2mI/ lZwA== X-Forwarded-Encrypted: i=1; AJvYcCWF5X8pbzViiojDCqeZszJ5vTV4nbG+2XWF/aAXUYqW2QfcdVvg65+WrPnYZ5foWF1uivR7zDR2aZgw/eAl@lists.postgresql.org X-Gm-Message-State: AOJu0YzFPG+hthymDQF40s+Fbm1N/BLD3d/vKIU9CkHF7gWHX/qO4zce a+T8RUl77VUBXWNpsDbFV6tk0XxU6IiA3+LuomK68+UezlEVQGfH26q1DlcgZHWZVbsBJfbyoQ8 T3D5m8vIBvuteAZB8jr5/LjAsvg== X-Google-Smtp-Source: AGHT+IGN2TKeZTgcLMOjShu3R4sU0jjJQOWhKC3F3OC/O7+QciEnoucix8VCdsF4QUiZvUjBQfeA9sUWzXGulhogpgw= X-Received: by 2002:a05:651c:1602:b0:2fc:9afe:1157 with SMTP id 38308e7fff4ca-2ff201123a0mr61446541fa.2.1731328960114; Mon, 11 Nov 2024 04:42:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Nisha Moond Date: Mon, 11 Nov 2024 18:12:28 +0530 Message-ID: Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation To: shveta malik Cc: Bharath Rupireddy , Peter Smith , Amit Kapila , Ajin Cherian , Bertrand Drouvot , Masahiko Sawada , Nathan Bossart , PostgreSQL Hackers 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, Sep 18, 2024 at 3:31=E2=80=AFPM shveta malik wrote: > > On Wed, Sep 18, 2024 at 2:49=E2=80=AFPM shveta malik wrote: > > > > > > Please find the attached v46 patch having changes for the above rev= iew > > > > comments and your test review comments and Shveta's review comments= . > > > > > > When the synced slot is marked as 'inactive_timeout' invalidated on > hot standby due to invalidation of publisher 's failover slot, the > former starts showing NULL' inactive_since'. Is this intentional > behaviour? I feel inactive_since should be non-NULL here too? > Thoughts? > > physical standby: > postgres=3D# select slot_name, inactive_since, invalidation_reason, > failover, synced from pg_replication_slots; > slot_name | inactive_since | > invalidation_reason | failover | synced > -------------+----------------------------------+---------------------+--= --------+-------- > sub2 | 2024-09-18 15:20:04.364998+05:30 | | t | t > sub3 | 2024-09-18 15:20:04.364953+05:30 | | t | t > > After sync of invalidation_reason: > > slot_name | inactive_since | invalidation_reason | > failover | synced > -------------+----------------------------------+---------------------+--= --------+-------- > sub2 | | inactive_timeout | t | = t > sub3 | | inactive_timeout | t | = t > > For synced slots on the standby, inactive_since indicates the last synchronization time rather than the time the slot became inactive (see doc - https://www.postgresql.org/docs/devel/view-pg-replication-slots.= html). In the reported case above, once a synced slot is invalidated we don't even keep the last synchronization time for it. This is because when a synced slot on the standby is marked invalid, inactive_since is reset to NULL each time the slot-sync worker acquires a lock on it. This lock acquisition before checking invalidation is done to avoid certain race conditions and will activate the slot temporarily, resetting inactive_since. Later, the slot-sync worker updates inactive_since for all synced slots to the current synchronization time. However, for invalid slots, this update is skipped, as per the patch=E2=80=99s design. If we want to preserve the inactive_since value for the invalid synced slots on standby, we need to clarify the time it should display. Here are three possible approaches: 1) Copy the primary's inactive_since upon invalidation: When a slot becomes invalid on the primary, the slot-sync worker could copy the primary slot=E2=80=99s inactive_since to the standby slot and retain it, by preventing future updates on the standby. 2) Use the current time of standby when the synced slot is marked invalid for the first time and do not update it in subsequent sync cycles if the slot is invalid. Approach (2) seems more reasonable to me, however, Both 1) & 2) approaches contradicts the purpose of inactive_since, as it no longer represents either the true "last sync time" or the "time slot became inactive" because the slot-sync worker acquires locks periodically for syncing, and keeps activating the slot. 3) Continuously update inactive_since for invalid synced slots as well: Treat invalid synced slots like valid ones by updating inactive_since with each sync cycle. This way, we can keep the "last sync time" in the inactive_since. However, this could confuse users when "invalidation_reason=3Dinactive_timeout" is set for a synced slot on standby but inactive_since would reflect sync time rather than the time slot became inactive. IIUC, on the primary, when invalidation_reason=3Dinactive_timeout for a slot, the inactive_since represents the actual time the slot became inactive before getting invalidated, unless the primary is restarted. Thoughts? -- Thanks, Nisha