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 1tJ0Ra-000QMh-F3 for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 01:14:14 +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 1tJ0RX-003d0y-Jz for pgsql-hackers@arkaria.postgresql.org; Thu, 05 Dec 2024 01:14:12 +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 1tJ0RX-003d0p-AA for pgsql-hackers@lists.postgresql.org; Thu, 05 Dec 2024 01:14:12 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJ0RV-0016La-JK for pgsql-hackers@lists.postgresql.org; Thu, 05 Dec 2024 01:14:11 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2ffdbc0c103so2829091fa.3 for ; Wed, 04 Dec 2024 17:14:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733361248; x=1733966048; 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=Z+9MHbFN1wNNJkg4kISkJc1mHbguAWPXo7wPGNfyjPY=; b=kPMRROXf6zwhwlbNIiDXJsxxQMzizceynPx4CRYfQ9LykITM1TZwZE0KcYjOWJ+rRJ Ed055NZE1/K7sEHWTaFhMP5iT+2rLrdnw74ssMxzeBmafP3rNFlpEZSlO/SATVijHq/I OgGZ2Ov8AEnkvOOM37fRZ0xQoeJuVX9hgbOqhVXjGaTpduApn1+IxfR0Dre7GtfoKB8l TZ+2hwUEEOM1yr2OfeUBCpDTSLHd1/ODV9pCdVbjb4hFiM8vcRJU30lEj6Shnhnm7TmN CsWJHHKgmShHoN8f7i2lsUNF6lDb2E10LQrHm6LTPlOHErroVHRj5wWlBBfxnLCMLVjp 5r8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733361248; x=1733966048; 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=Z+9MHbFN1wNNJkg4kISkJc1mHbguAWPXo7wPGNfyjPY=; b=ZIAksw7S8iMo00pDOz57yo9UYzOWaHIndDSPSj9a9GDbuBJyR3kGPR65nvvMLxP/Dy +xbgoTk/Q1kv7CEfmVIHvCT2PXyWktyiRjfXAcQu4jVXFLXGmFavrhQZjB7XynwWIWMc KLnMO+9NT19hjxQjzbuEdXxODtu3gICvNAF4h4p68yAgdVQLMEiGuVJrf9hDRzIz7REx mrrEpzTIkmmo++ZHNplprHMDUEI2wiF27jlRt+i0SMloqvG2RgCeJBwUUL1QZ9BKNf0W eOD2IRWAtvMAT5GskCGMNzauDYMT/u+G9yAXz5X1v63dNdOGw9RhaxcGBMavfXiGjm/Y cP5Q== X-Forwarded-Encrypted: i=1; AJvYcCVWSw+jr4qwiH+WiNwCpGbxntICDxTR5DZ4Gy5Xz8EN377+EfVugwgZuV8IGxcUjkFnPOl1pDePIZtlbGeZ@lists.postgresql.org X-Gm-Message-State: AOJu0Yzd/X4zAeMAJ1yfuGGCMdw9go83Nk46MukFYkIYT9irpS/3uv2o G4y3N1EtPMj7bwQ5rb20bwe9d+Hs3BBD5tEv2+PTW7rBfsWD8cv+I6wLYPR1PC1xD0v1vGgznVl CisW/VNlm3IDBWIcyi3cZdAOi9g0= X-Gm-Gg: ASbGnctLX0c707vkK0AY5f92fxIQAhqDLh0+qW0Qpe5M2HrbNc0j+EaWnr4Jamfvwhz 20BF4l3/UKhuk75yphOjJnBLSygSecRQZ X-Google-Smtp-Source: AGHT+IH1sS4kbKF/0thrpOD+Kp/exjWhI1pxr1Zjwv5g9PyxBj3W91BP4OAoDa7GZsHAVKDE3odfTvbU0CCYrjoZCn4= X-Received: by 2002:a2e:3507:0:b0:300:17a3:7ad9 with SMTP id 38308e7fff4ca-30017a37d6emr20832661fa.12.1733361247973; Wed, 04 Dec 2024 17:14:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Peter Smith Date: Thu, 5 Dec 2024 12:13:40 +1100 Message-ID: Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation To: vignesh C Cc: Nisha Moond , "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" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 4, 2024 at 9:27=E2=80=AFPM vignesh C wrot= e: > ... > > Currently, replication slots are invalidated based on the > replication_slot_inactive_timeout only during a checkpoint. This means > that if the checkpoint_timeout is set to a higher value than the > replication_slot_inactive_timeout, slot invalidation will occur only > when the checkpoint is triggered. Identifying the invalidation slots > might be slightly delayed in this case. As an alternative, users can > forcefully invalidate inactive slots that have exceeded the > replication_slot_inactive_timeout by forcing a checkpoint. I was > thinking we could suggest this in the documentation. > > + > + Slot invalidation due to inactive timeout occurs during checkpoi= nt. > + The duration of slot inactivity is calculated using the slot's > + pg_replication_slots= .inactive_since > + value. > + > + > > We could accurately invalidate the slots using the checkpointer > process by calculating the invalidation time based on the active_since > timestamp and the replication_slot_inactive_timeout, and then set the > checkpointer's main wait-latch accordingly for triggering the next > checkpoint. Ideally, a different process handling this task would be > better, but there is currently no dedicated daemon capable of > identifying and managing slots across streaming replication, logical > replication, and other slots used by plugins. Additionally, > overloading the checkpointer with this responsibility may not be > ideal. As an alternative, we could document about this delay in > identifying and mention that it could be triggered by forceful manual > checkpoint. > Hi Vignesh. I felt that manipulating the checkpoint timing behind the scenes without the user's consent might be a bit of an overreach. But there might still be something else we could do: 1. We can add the documentation note like you suggested ("we could document about this delay in identifying and mention that it could be triggered by forceful manual checkpoint"). 2. We can also detect such delays in the code. When the invalidation occurs (e.g. code fragment below) we could check if there was some excessive lag between the slot becoming idle and it being invalidated. If the lag is too much (whatever "too much" means) we can log a hint for the user to increase the checkpoint frequency (or whatever else we might advise them to do). + /* + * Check if the slot needs to be invalidated due to + * replication_slot_inactive_timeout GUC. + */ + if (IsSlotInactiveTimeoutPossible(s) && + TimestampDifferenceExceeds(s->inactive_since, now, + replication_slot_inactive_timeout_ms)) + { + invalidation_cause =3D cause; + inactive_since =3D s->inactive_since; pseudo-code: if (slot invalidation occurred much later after the replication_slot_inactive_timeout GUC elapsed) { elog(LOG, "This slot was inactive for a period of %s. Slot timeout invalidation only occurs at a checkpoint so if you want inactive slots to be invalidated in a more timely manner consider reducing the time between checkpoints or executing a manual checkpoint. (replication_slot_inactive_timeout =3D %s; checkpoint_timeout =3D %s, ....)" } + } =3D=3D=3D=3D=3D=3D Kind Regards, Peter Smith. Fujitsu Australia