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 1rp3vN-004rEw-Rh for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 10:20:58 +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 1rp3vM-00DR9f-A9 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Mar 2024 10:20:56 +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 1rp3vM-00DR9V-0l for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 10:20:56 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rp3vJ-006Z3G-J4 for pgsql-hackers@lists.postgresql.org; Tue, 26 Mar 2024 10:20:55 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2d6ee6c9945so1585571fa.3 for ; Tue, 26 Mar 2024 03:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711448453; x=1712053253; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=EOdKy+0s9qIdQdOMJoqs0hTXWqg+/q2FhaCI+KTmV00=; b=D+foQUIc0yZmE75B7Ex7YZQ8vZCRAkHzclDLknP+EeNKHQdZ7KzbtCgNSS+arGMoGq Y732l9+IcceMNYBO7N4Pu69v8XFEk4lAesXrKFNi75qUxQ2O7SqWQB/Etj/dZuXYQHI9 e487jly9E8Q1gis3yeyIXfmfj0TB+DbgI3lzHcTaSNUE1xhILD88nap7jBdeuMue6Fjl PCH9tNb0C4NvD7smotO7eg4LGsAXsbmNC77Gu3J3ActV7wvoy3sZVyz9JiGwVbQ+4ChJ Kv7nMEsZTvMUyskucWafyVHq5Ke+Ui4TOgmCk0+z8YMpaDgLsSSuMgV3Nh0HbKQoONMt GfTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711448453; x=1712053253; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EOdKy+0s9qIdQdOMJoqs0hTXWqg+/q2FhaCI+KTmV00=; b=mxcyvOJpkJImbWldcjoenbU3Bbl6pUuwelvkge6xgzV/jLdknIX1r8Z8jkI40gWPGc wHkTrGuBFCilqmLUFX9v5hhfEkmu7dj7Av/5Zolcv6/8r2XpgoDijS8HRgPLCOEEXHfG 6DW3nec9JlcFnG0qtVRtAGk66bH10bf6Py6APQhDHGO3mHHo89xQWSEpn39JpUhmQX5J dQYoEFGNaj+E2cKCX3WJVeG50ZdFcqXOgKGyw1FOJ7wNzazvfO+8lilhvWlU6ZGjOIDP N4OLANLvugZieCFDUuWqFui4MyiZWAlyTLco6D/4qn5YpW46phgqKAowHIiE4NBdivE4 Puog== X-Forwarded-Encrypted: i=1; AJvYcCVELDGiD/AKtQfVBvAjtmuJxg4+DGAsXgqC+iSeoXBBcZ2LFdZ1D/TVsAkl5Azx4LJw6ijpb3HoIbbg7Nv7I4ATrYjPCXPf0/uis52/8ikMokcA X-Gm-Message-State: AOJu0YzF/lDSssjitut9LAOKlKDl9WD2dGJ/fXM8cHFTTGRo/SYS9IlV 9Zfpa6XLIQlFyKEX/v4p1KgyMMeTLlURgsRncc8Sno92edOxCJrq X-Google-Smtp-Source: AGHT+IGroMNcHPgI5F0Tg8j3jwD89aYzjBLW75eoX7XZdoWPg31TQWik3yPAfx4sTt2RXY5V2bqqOQ== X-Received: by 2002:a2e:350a:0:b0:2d4:7a3:67a7 with SMTP id z10-20020a2e350a000000b002d407a367a7mr647098ljz.22.1711448452450; Tue, 26 Mar 2024 03:20:52 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id h20-20020a05600c351400b0041477f95cf6sm11124767wmq.13.2024.03.26.03.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 03:20:52 -0700 (PDT) Date: Tue, 26 Mar 2024 10:20:50 +0000 From: Bertrand Drouvot To: shveta malik Cc: Amit Kapila , Bharath Rupireddy , Nathan Bossart , PostgreSQL Hackers Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Mar 26, 2024 at 03:17:36PM +0530, shveta malik wrote: > On Tue, Mar 26, 2024 at 1:54 PM Bertrand Drouvot > wrote: > > > > Hi, > > > > On Tue, Mar 26, 2024 at 01:37:21PM +0530, Amit Kapila wrote: > > > On Tue, Mar 26, 2024 at 1:15 PM Bertrand Drouvot > > > wrote: > > > > > > > > 2 === > > > > > > > > It looks like inactive_since is set to the current timestamp on the standby > > > > each time the sync worker does a cycle: > > > > > > > > primary: > > > > > > > > postgres=# select slot_name,inactive_since from pg_replication_slots where failover = 't'; > > > > slot_name | inactive_since > > > > -------------+------------------------------- > > > > lsub27_slot | 2024-03-26 07:39:19.745517+00 > > > > lsub28_slot | 2024-03-26 07:40:24.953826+00 > > > > > > > > standby: > > > > > > > > postgres=# select slot_name,inactive_since from pg_replication_slots where failover = 't'; > > > > slot_name | inactive_since > > > > -------------+------------------------------- > > > > lsub27_slot | 2024-03-26 07:43:56.387324+00 > > > > lsub28_slot | 2024-03-26 07:43:56.387338+00 > > > > > > > > I don't think that should be the case. > > > > > > > > > > But why? This is exactly what we discussed in another thread where we > > > agreed to update inactive_since even for sync slots. > > > > Hum, I thought we agreed to "sync" it and to "update it to current time" > > only at promotion time. > > I think there may have been some misunderstanding here. Indeed ;-) > But now if I > rethink this, I am fine with 'inactive_since' getting synced from > primary to standby. But if we do that, we need to add docs stating > "inactive_since" represents primary's inactivity and not standby's > slots inactivity for synced slots. Yeah sure. > The reason for this clarification > is that the synced slot might be generated much later, yet > 'inactive_since' is synced from the primary, potentially indicating a > time considerably earlier than when the synced slot was actually > created. Right. > Another approach could be that "inactive_since" for synced slot > actually gives its own inactivity data rather than giving primary's > slot data. We update inactive_since on standby only at 3 occasions: > 1) at the time of creation of the synced slot. > 2) during standby restart. > 3) during promotion of standby. > > I have attached a sample patch for this idea as.txt file. Thanks! > I am fine with any of these approaches. One gives data synced from > primary for synced slots, while another gives actual inactivity data > of synced slots. What about another approach?: inactive_since gives data synced from primary for synced slots and another dedicated field (could be added later...) could represent what you suggest as the other option. Another cons of updating inactive_since at the current time during each slot sync cycle is that calling GetCurrentTimestamp() very frequently (during each sync cycle of very active slots) could be too costly. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com