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 1tLCiR-00DMBb-Dh for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Dec 2024 02:44:43 +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 1tLCiO-00BBRM-HZ for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Dec 2024 02:44:41 +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.94.2) (envelope-from ) id 1tLCiO-00BBRE-3k for pgsql-hackers@lists.postgresql.org; Wed, 11 Dec 2024 02:44:41 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tLCiM-002BUD-KJ for pgsql-hackers@lists.postgresql.org; Wed, 11 Dec 2024 02:44:40 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-53e3a90336eso3829903e87.3 for ; Tue, 10 Dec 2024 18:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733885077; x=1734489877; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9Lu5MuRXQLS515fTQfeAUnPHBugMz/TZCtC8Jz2BT3o=; b=AUWnbne6iVc1cSkBHyvaUGY3QbyYrJ6TewHRY1/F9AdTA5NDT0LS9ndevBxKy99OUn iZ8iDzx0kfaMKRDzrpMdWNk6KGzUqklCz9PInYcPSNobp9yasP/IAYDwYl4+F97IRHY1 pz8yGyo048q23ynoTUK8Bj1Vn1zJ0V1unUTiKWDLZh43XQbK/QucgOhT8vNVOYxSFF6h Mcx/T8XbgmypbJj0Josijp8Tf+UXy17wPFYqzrmWFUoNkk5VU5lvSwXyt7gGKGWnC+QS LvLnRgfDOb2cnzD+sjxPAkwqbFjcAkSO2IQQY37U6VP9Q24iSVMi9bOZhOeFi2aZM9TJ tKCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733885077; x=1734489877; h=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=9Lu5MuRXQLS515fTQfeAUnPHBugMz/TZCtC8Jz2BT3o=; b=WHearWuX6vEQLFDUvzURobMH5/8Q9XdgW9Jm14OW7GDqCkd1rIrslMyeyDdkQ997n7 /HKGffXhIP+ta8NEXmVsZWlAEO95pRaVGkeRQ7UQgr13QP0UgtP+LwhcyHN/VubkwMHo pf6FWgLQNkmkQJWf3R+EkWPDFm3kZMs3fM9+3jb8lzq3D367NsiUfaueRYdXN7cf8bOt h65KmvHulszD5VgAPCRG+D+dp+zQpobe7pyuWNSdnXp2EUraTuAhVr8qB0hJfQjZ7dry xKkRM0dbtdK1CH/svA9+w6eszrZhvvPs0Svk001ZAi/vTOJPBgFx9b5/BenJJIsAfORi 9AhQ== X-Forwarded-Encrypted: i=1; AJvYcCUNew7/RacGlkfU3zTxJvivD3VKRYslf5IgMqfJGfVIpUJmYJ+oAx7lhBwqa7yogUT2TRbxOD0Y5FG128d2@lists.postgresql.org X-Gm-Message-State: AOJu0YyedAzyb9k5jli5hlERvzso5h4FnCkDFupbdrX/H5fa2rO75KU9 btb1sLtIf9Lr7WIFWVggvvg826qsJ47aIjAUHRs5Bq1UmCOHe0QjcFGX+U/KxKHfwTOjxqe2t3A GNToNX+nng0r5asBxHgIusfxOZEWvsyy+ X-Gm-Gg: ASbGncvfqV2OsoKmdVwQY8+GBVQkwRw3fce1wfs7jdAhC5wssxmOFPfJzMPY8Cjc+qm y6vTaDnL+dXNwytJzSjhyRHf081vOhvxreIs= X-Google-Smtp-Source: AGHT+IGAOYNh6NS0QtsOgD0aaNCNpwVq0z6zYzq8a0ZPyvmVFUkqjClN06UaxSz4F4ZMds23m4m+S7vlnXxsk82zdlA= X-Received: by 2002:a05:651c:988:b0:2f3:f7cf:2f01 with SMTP id 38308e7fff4ca-30240d82dfcmr3344081fa.41.1733885076345; Tue, 10 Dec 2024 18:44:36 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Wed, 11 Dec 2024 13:44:05 +1100 Message-ID: Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation To: Nisha Moond Cc: vignesh C , "Hayato Kuroda (Fujitsu)" , shveta malik , Bharath Rupireddy , Amit Kapila , Ajin Cherian , Bertrand Drouvot , Masahiko Sawada , Nathan Bossart , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Nisha. Here are some review comments for patch v54-0002. (I had also checked patch v54-0001, but have no further review comments for that one). ====== doc/src/sgml/config.sgml 1. + + Slot invalidation due to idle timeout occurs during checkpoint. + If the checkpoint_timeout exceeds + idle_replication_slot_timeout, the slot + invalidation will be delayed until the next checkpoint is triggered. + To avoid delays, users can force a checkpoint to promptly invalidate + inactive slots. The duration of slot inactivity is calculated using the slot's + pg_replication_slots.inactive_since + value. + + The wording of "If the checkpoint_timeout exceeds idle_replication_slot_timeout, the slot invalidation will be delayed until the next checkpoint is triggered." seems slightly misleading, because AFAIK it is not conditional on the GUC value differences like that -- i.e. slot invalidation is *always* delayed until the next checkpoint occurs. SUGGESTION: Slot invalidation due to idle timeout occurs during checkpoint. Because checkpoints happen at checkpoint_timeout intervals, there can be some lag between when the idle_replication_slot_timeout was exceeded and when the slot invalidation is triggered at the next checkpoint. To avoid such lags, users can force... ======= src/backend/replication/slot.c 2. GENERAL +/* Invalidate replication slots idle beyond this time; '0' disables it */ +int idle_replication_slot_timeout_ms = 0; I noticed this patch is using a variety of ways of describing the same thing: * guc var: Invalidate replication slots idle beyond this time... * guc_tables: ... the amount of time a replication slot can remain idle before it will be invalidated. * docs: means that the slot has remained idle beyond the duration specified by the idle_replication_slot_timeout parameter * errmsg: ... slot has been invalidated because inactivity exceeded the time limit set by ... * etc.. They are all the same, but they are all worded slightly differently: * "idle" vs "inactivity" vs ... * "time" vs "amount of time" vs "duration" vs "time limit" vs ... There may not be a one-size-fits-all, but still, it might be better to try to search for all different phrasing and use common wording as much as possible. ~~~ CheckPointReplicationSlots: 3. + * XXX: Slot invalidation due to 'idle_timeout' occurs only for + * released slots, based on 'idle_replication_slot_timeout'. Active + * slots in use for replication are excluded, preventing accidental + * invalidation. Slots where communication between the publisher and + * subscriber is down are also excluded, as they are managed by the + * 'wal_sender_timeout'. Maybe a slight rewording like below is better. Maybe not. YMMV. SUGGESTION: XXX: Slot invalidation due to 'idle_timeout' applies only to released slots, and is based on the 'idle_replication_slot_timeout' GUC. Active slots currently in use for replication are excluded to prevent accidental invalidation. Slots... ====== src/bin/pg_upgrade/server.c 4. + /* + * Use idle_replication_slot_timeout=0 to prevent slot invalidation due to + * inactive_timeout by checkpointer process during upgrade. + */ + if (GET_MAJOR_VERSION(cluster->major_version) >= 1800) + appendPQExpBufferStr(&pgoptions, " -c idle_replication_slot_timeout=0"); + /inactive_timeout/idle_timeout/ ====== src/test/recovery/t/043_invalidate_inactive_slots.pl 5. +# Wait for slot to first become idle and then get invalidated +sub wait_for_slot_invalidation +{ + my ($node, $slot, $offset, $idle_timeout) = @_; + my $node_name = $node->name; AFAICT this 'idle_timeout' parameter is passed units of "seconds", so it would be better to call it something like 'idle_timeout_s' to make the units clear. ~~~ 6. +# Trigger slot invalidation and confirm it in the server log +sub trigger_slot_invalidation +{ + my ($node, $slot, $offset, $idle_timeout) = @_; + my $node_name = $node->name; + my $invalidated = 0; Ditto above review comment #5 -- better to call it something like 'idle_timeout_s' to make the units clear. ====== Kind Regards, Peter Smith. Fujitsu Australia