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 1rpM9f-006Jrs-IR for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Mar 2024 05:48:56 +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 1rpM9d-00AUwE-Q2 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Mar 2024 05:48:53 +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 1rpM9d-00AUtv-GU for pgsql-hackers@lists.postgresql.org; Wed, 27 Mar 2024 05:48:53 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rpM9Z-006eXL-Ix for pgsql-hackers@lists.postgresql.org; Wed, 27 Mar 2024 05:48:52 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-341b01dbebbso4911195f8f.0 for ; Tue, 26 Mar 2024 22:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711518529; x=1712123329; 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=E/sgn1i+YBDiDJY30F52Mwh7dH1Ao5w7KyGz0UKTjC8=; b=kcGfPC1m5TmMU0g30GVERLhn+3Boq1GiuPJdpHtU3kWjmYMOhFHsi9UMyNc0EqcStN Kan8J3hqWfJaP2mlaByMR9i8sQLxgfCc/WjLakP2arcfeC3UFJPtj3R+gM8x6B7VKjpE ecrWIPXuKGlqdLEKtfMpxNFtVZrqAfENXSd7gDry1r5sI94nVViZ3+cDoCEktvhwZbl0 E6cP58oQtQ2+FdONuXzXuNRX0nfngfdEyswVvK/5tlf36dw0R28fFlZ6x3/SgbU3FLVj 0XT9SAvjTUQKAEBM0beeZuJ7jiqV44zkhdj0N7AS09W5cg+Wxx46TfG1twZr1Nn4chnL SbTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711518529; x=1712123329; 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=E/sgn1i+YBDiDJY30F52Mwh7dH1Ao5w7KyGz0UKTjC8=; b=g280vEuA28+UNeWj0i+jzhUdfFWGC7kjPvtY9rH6hfFAZQ3fbHIc5lzq/1wetuPIy1 Nu88NZEGOyVfxYYJvnIUx1pXSNvFMHbJQqM1v2bmRzx5oN6w/fUcbVRcU16M24BjSAQq 40PXIRZdv/YM6fqJBlAnY5LjOTKajhSdMrwAK6DFAi0xmIPMhn3pAOax5pC/98uzwHoE 6tnZJl6nbC+VxJt1PyQd0FGJU9dwPkKGZIKzzszkiqZS2e/inNjsixiovGO++rS4c45f 6WO91csERBDS+5ThBqnA4vIUu9Fxny7DyKkJQzdRmnT9suVYmQkWwYO74XiHGUPPqfh7 4O6w== X-Forwarded-Encrypted: i=1; AJvYcCXAcj7rpFsGmVaPTCrle/X4zpH0KANQvsX69ARITfLJ428RNzBAbbVQiYgRZlRdnL90LT7Sf7Sx6PgLLTA/pajPedlmuzXtE7hX3pN377CYxcrr X-Gm-Message-State: AOJu0YyZYoJnI/q5nm5cRDwyxDdCoanBToWyPd7D9slZ0NVEyigNRvoR 0BRCR9jDe9xRUwX+0MkNwGpKmWMKVyo2CnK9oq2L1Qg7UNf2jz49 X-Google-Smtp-Source: AGHT+IG/6umu8Q0nc0Xq2oqPAzBCIDJQRaCAVXHL7/clwIRe1+fpazKJHP6p2MXUwo2bzfz9KTtpEA== X-Received: by 2002:a05:6000:c52:b0:341:cd0d:b78a with SMTP id do18-20020a0560000c5200b00341cd0db78amr1319737wrb.48.1711518528793; Tue, 26 Mar 2024 22:48:48 -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 bt3-20020a056000080300b00341d7596ec0sm3527859wrb.15.2024.03.26.22.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 22:48:48 -0700 (PDT) Date: Wed, 27 Mar 2024 05:48:46 +0000 From: Bertrand Drouvot To: Bharath Rupireddy Cc: shveta malik , Amit Kapila , 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 Wed, Mar 27, 2024 at 10:08:33AM +0530, Bharath Rupireddy wrote: > On Tue, Mar 26, 2024 at 11:22 PM Bertrand Drouvot > wrote: > > > > - if (!(RecoveryInProgress() && slot->data.synced)) > > + if (!(InRecovery && slot->data.synced)) > > slot->inactive_since = GetCurrentTimestamp(); > > else > > slot->inactive_since = 0; > > > > Not related to this change but more the way RestoreSlotFromDisk() behaves here: > > > > For a sync slot on standby it will be set to zero and then later will be > > synchronized with the one coming from the primary. I think that's fine to have > > it to zero for this window of time. > > Right. > > > Now, if the standby is down and one sets sync_replication_slots to off, > > then inactive_since will be set to zero on the standby at startup and not > > synchronized (unless one triggers a manual sync). I also think that's fine but > > it might be worth to document this behavior (that after a standby startup > > inactive_since is zero until the next sync...). > > Isn't this behaviour applicable for other slot parameters that the > slot syncs from the remote slot on the primary? No they are persisted on disk. If not, we'd not know where to resume the decoding from on the standby in case primary is down and/or sync is off. > I've added the following note in the comments when we update > inactive_since in RestoreSlotFromDisk. > > * Note that for synced slots after the standby starts up (i.e. after > * the slots are loaded from the disk), the inactive_since will remain > * zero until the next slot sync cycle. > */ > if (!(InRecovery && slot->data.synced)) > slot->inactive_since = GetCurrentTimestamp(); > else > slot->inactive_since = 0; I think we should add some words in the doc too and also about what the meaning of inactive_since on the standby is (as suggested by Shveta in [1]). [1]: https://www.postgresql.org/message-id/CAJpy0uDkTW%2Bt1k3oPkaipFBzZePfFNB5DmiA%3D%3DpxRGcAdpF%3DPg%40mail.gmail.com > > 7 === > > > > +# Capture and validate inactive_since of a given slot. > > +sub capture_and_validate_slot_inactive_since > > +{ > > + my ($node, $slot_name, $slot_creation_time) = @_; > > + my $name = $node->name; > > > > We know have capture_and_validate_slot_inactive_since at 2 places: > > 040_standby_failover_slots_sync.pl and 019_replslot_limit.pl. > > > > Worth to create a sub in Cluster.pm? > > I'd second that thought for now. We might have to debate first if it's > useful for all the nodes even without replication, and if yes, the > naming stuff and all that. Historically, we've had such duplicated > functions until recently, for instance advance_wal and log_contains. > We > moved them over to a common perl library Cluster.pm very recently. I'm > sure we can come back later to move it to Cluster.pm. I thought that would be the right time not to introduce duplicated code. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com