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 1snGWO-002F8z-9o for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Sep 2024 11:56:01 +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 1snGWN-00DMVY-Gf for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Sep 2024 11:55:59 +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 1snGWN-00DMVQ-5R for pgsql-hackers@lists.postgresql.org; Sun, 08 Sep 2024 11:55:59 +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 1snGWJ-0008ca-3A for pgsql-hackers@lists.postgresql.org; Sun, 08 Sep 2024 11:55:58 +0000 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2f759688444so12731931fa.1 for ; Sun, 08 Sep 2024 04:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725796555; x=1726401355; 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=3yVf+PQhlgNLpvSKPKlIUUt2LWRerDjndRfQFNSDpHI=; b=eJ0OABfMuENgJug8vP5FhpZ0DS+T+ACWzq/T+bPjEWe61rHiRxS+OzPRifbwnbOXGg kWtkHqeCH5mdaG0RYOBGDwdfPyRE9+iKkXwBbjaWimeIzefUM1nI5g6sIsZhcK8MH3D+ KAIIu5UXOhIkOhWU7vLrE1Xi+uksDMbT2ZN0HbyKJj1J5HOtIGA8ghmJcaOtkzo8jpiC NowZxH50wLE5WeCq1XE6dE9xHfPAZjsXH4U2A2S8gB5ffc/qyW87/Hzzd6qQsgZOj98s SULINHLFrvr4RyfS/bUlyRtAzxHgUCNGOk43gTzNonPGOTNF2tbOD+4xBL46jY2oFWzs +ZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725796555; x=1726401355; 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=3yVf+PQhlgNLpvSKPKlIUUt2LWRerDjndRfQFNSDpHI=; b=FuYgR8gwtm+Zw1WLKhHoAXM6VQ+u1AG0OovOBHjZY9Zltq8HS0iQvKSStwkSlj1XQv UxKvIR0zKmy1NkhGIBq+8nip51uuHXIP0v676kBvhf5ANvIpEMc+tcyWAamFwLp7m4aH nCH/N9XYQiELoO8EuHe4tuVszDD7sw5Cb49vf6zVb9R8D7jvCL3Zm30NbvTvz4b9/pfK vkI+xuC6173rq5m4SK2yn7TnWdtKYFqOku+XzBZ1F0TD73Q+MNe/HNhxEsYTU+hbuRQ1 2pMlqjU3/s054cGmRv6F+QAWDtjK6R6Bk3Wr6z0s1fRkXxgJF6D5rpetI3D9/PTXMEuI nTfQ== X-Forwarded-Encrypted: i=1; AJvYcCWKtm57Nol8nzN7fcumNfhJEZZG6xDxEf9YrpFZvVWE6MUcsYDqDF5/mXJ5xoHq7qXPCC6hyAGk83f8uKrE@lists.postgresql.org X-Gm-Message-State: AOJu0Yw8LSDNTZqS04OcPoXL/Wlg7l4d+T6K23d8MDzBjxDlwyNoAknZ zLnFabApYjbBxYKzMGWXhsPWyAXAj2XgJGOCJipX9dcybKFzt04RoHlKMIGsgZFoA4aYPCc48CR 2fjHEoDWoqAI0L1sKSbadPk1+okI= X-Google-Smtp-Source: AGHT+IFROcLC8olHv9SHDirLEdSS8xeAKgOls5iFJ8nNLtPy/0uW5RcfKkAqh77+9k5wtGJ5EgkMqRMV1GctONlNamc= X-Received: by 2002:a2e:a983:0:b0:2ef:1db2:c02a with SMTP id 38308e7fff4ca-2f751eb2464mr67686421fa.6.1725796554598; Sun, 08 Sep 2024 04:55:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Sun, 8 Sep 2024 17:25:42 +0530 Message-ID: Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation To: shveta malik Cc: 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 Hi, Thanks for reviewing. On Tue, Sep 3, 2024 at 3:01=E2=80=AFPM shveta malik wrote: > > 1) > I see that ReplicationSlotAlter() will error out if the slot is > invalidated due to timeout. I have not tested it myself, but do you > know if slot-alter errors out for other invalidation causes as well? > Just wanted to confirm that the behaviour is consistent for all > invalidation causes. Will respond to Amit's comment soon. > 2) > When a slot is invalidated, and we try to use that slot, it gives this ms= g: > > ERROR: can no longer get changes from replication slot "mysubnew1_2" > DETAIL: The slot became invalid because it was inactive since > 2024-09-03 14:23:34.094067+05:30, which is more than 600 seconds ago. > HINT: You might need to increase "replication_slot_inactive_timeout.". > > Isn't HINT misleading? Even if we increase it now, the slot can not be > reused again. > > Below is one side effect if inactive_since keeps on changing: > > postgres=3D# SELECT * FROM pg_replication_slot_advance('mysubnew1_1', > pg_current_wal_lsn()); > ERROR: can no longer get changes from replication slot "mysubnew1_1" > DETAIL: The slot became invalid because it was inactive since > 2024-09-04 10:03:56.68053+05:30, which is more than 10 seconds ago. > HINT: You might need to increase "replication_slot_inactive_timeout.". > > postgres=3D# select now(); > now > --------------------------------- > 2024-09-04 10:04:00.26564+05:30 > > 'DETAIL' gives wrong information, we are not past 10-seconds. This is > because inactive_since got updated even in ERROR scenario. > > ERROR: can no longer get changes from replication slot "mysubnew1_1" > DETAIL: The slot became invalid because it was inactive since > 2024-09-04 10:06:38.980939+05:30, which is more than 129600 seconds > ago. > postgres=3D# select now(); > now > ---------------------------------- > 2024-09-04 10:07:35.201894+05:30 > > I feel we should change this message itself. Removed the hint and corrected the detail message as following: errmsg("can no longer get changes from replication slot \"%s\"", NameStr(s->data.name)), errdetail("This slot has been invalidated because it was inactive for longer than the amount of time specified by \"%s\".", "replication_slot_inactive_timeout."))); > 3) > When the slot is invalidated, the' inactive_since' still keeps on > changing when there is a subscriber trying to start replication > continuously. I think ReplicationSlotAcquire() keeps on failing and > thus Release keeps on setting it again and again. Shouldn't we stop > setting/chnaging 'inactive_since' once the slot is invalidated > already, otherwise it will be misleading. > > postgres=3D# select failover,synced,inactive_since,invalidation_reason > from pg_replication_slots; > > failover | synced | inactive_since | invalidation_reas= on > ----------+--------+----------------------------------+------------------= --- > t | f | 2024-09-03 14:23:.. | inactive_timeout > > after sometime: > failover | synced | inactive_since | invalidation_reas= on > ----------+--------+----------------------------------+------------------= --- > t | f | 2024-09-03 14:26:..| inactive_timeout Changed it to not update inactive_since for slots invalidated due to inactive timeout. > 4) > src/sgml/config.sgml: > > 4a) > + A value of zero (which is default) disables the timeout mechanism. > > Better will be: > A value of zero (which is default) disables the inactive timeout > invalidation mechanism . Changed. > 4b) > 'synced' and inactive_since should point to pg_replication_slots: > > example: > pg_replication_slots.<= structfield>synced Modified. > 5) > src/sgml/system-views.sgml: > + ..the slot has been inactive for longer than the duration specified > by replication_slot_inactive_timeout parameter. > > Better to have: > ..the slot has been inactive for a time longer than the duration > specified by the replication_slot_inactive_timeout parameter. Changed it to the following to be consistent with the config.sgml. inactive_timeout means that the slot has been inactive for longer than the amount of time specified by the paramet= er. Please find the v45 patch posted upthread at https://www.postgresql.org/message-id/CALj2ACWXQT3_HY40ceqKf1DadjLQP6b1r%3D= 0sZRh-xhAOd-b0pA%40mail.gmail.com for the changes. --=20 Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com