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 1sJDzd-003RC9-EB for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jun 2024 15:10: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 1sJDza-000X59-So for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jun 2024 15:09:59 +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 1sJDza-000X50-Il for pgsql-hackers@lists.postgresql.org; Mon, 17 Jun 2024 15:09:59 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sJDzZ-001lWs-2N for pgsql-hackers@lists.postgresql.org; Mon, 17 Jun 2024 15:09:58 +0000 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-7e21dfbc310so184541139f.1 for ; Mon, 17 Jun 2024 08:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718636996; x=1719241796; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KnfzrTNewNcj9DdPcibWjIvHqOeOsRFogbTjnvtBPpQ=; b=V43dlJADytVts74WeTglhOdeBQYcOmUpAN2Af+C/XOHhobF30kRaLm1JdUoR0GbYXY s3aSWO1dVh7HapeYisfMyaDTD+1TfY6ErLqMRVgeXzJI+An3/osirVio7F0KCgZn8S8Q Qb+dc6VlfDV2avfDcqU1q9OXxfySLnwN3Q+O6E86gyWJpxdiEi/tPVzDCRVin21ayzoV rfxXR8+aEEp2+Em4Q1mW5d4TbqAZizfNFNNxl/xC+LVBADAtXffIJFjY+QIN3pdFJGFK WIUO5AXdMuVrLeig1LJN8onA2Ff4VEGmVC1RNPIjxbMN1C/g/buS+2YGqVlcLX4qGodF Xuvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718636996; x=1719241796; h=in-reply-to: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=KnfzrTNewNcj9DdPcibWjIvHqOeOsRFogbTjnvtBPpQ=; b=QgZDWt1LdYiWJwaYVgQjNO2Ch4G7hetddbcAQouIYsxyu5l9AK+0EehSei0xVXqdz0 d3baqqbGw7Rt12GX5pyhR8vwZXfpBhWhM0aKjF7wK40hj3D0rqgb6YXY+aAozbgXJOWB 029SQ9FbaW6qayw5OnPZWFR2rRSUgG29JO4KzvxfbP5uL58BgdUbawD19IDGQhgdP9ue cB5fS8AR7YO5WjDG2n4ae93M8JnLtsCcpdLKEmyaj5Y8t8hFBmDlvMku9BkkOWcdutnq zMxkI8psHEszh7daKaj/HfxRiRiwhK6zkX8xIn8mkxqNfBIYIicdm/5eSB77g2G3Puqb Ec8g== X-Forwarded-Encrypted: i=1; AJvYcCUTdjTvqzBs2Z7GXmFmDK6kT0pf5wpvVlPrRAGObttmhPYq21ddyrT76kb1bABzazwkgCToR73EbCMVAWUBtRKmBrhA9hP0OzgDvk9nqz75DR+u X-Gm-Message-State: AOJu0Yx/4l0p1wFQmisEYHcJ13YWkgF6qrxSNkIW5m4hK/UhDmvWspTO GrcpQ3lYaX2/TZ9FaKmBoHBy3dwQdl7P6N7PLrDWmF88CLIg/7BQ X-Google-Smtp-Source: AGHT+IH01OmE5N1kwDFag2tHZ03HBDIxsuuTgx43uAnS1smU9deUWWfI7jBjs55ili9Qb00RV7riTA== X-Received: by 2002:a05:6602:2d84:b0:7eb:b188:1c96 with SMTP id ca18e2360f4ac-7ebeb4ae4dcmr1198983439f.5.1718636995954; Mon, 17 Jun 2024 08:09:55 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-7ebdb74cd1asm235544039f.0.2024.06.17.08.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:09:55 -0700 (PDT) Date: Mon, 17 Jun 2024 10:09:53 -0500 From: Nathan Bossart To: Bharath Rupireddy Cc: Amit Kapila , Bertrand Drouvot , shveta malik , Masahiko Sawada , 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=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jun 17, 2024 at 05:55:04PM +0530, Bharath Rupireddy wrote: > Here are my thoughts on when to do the XID age invalidation. In all > the patches sent so far, the XID age invalidation happens in two > places - one during the slot acquisition, and another during the > checkpoint. As the suggestion is to do it during the vacuum (manual > and auto), so that even if the checkpoint isn't happening in the > database for whatever reasons, a vacuum command or autovacuum can > invalidate the slots whose XID is aged. +1. IMHO this is a principled choice. The similar max_slot_wal_keep_size parameter is considered where it arguably matters most: when we are trying to remove/recycle WAL segments. Since this parameter is intended to prevent the server from running out of space, it makes sense that we'd apply it at the point where we are trying to free up space. The proposed max_slot_xid_age parameter is intended to prevent the server from running out of transaction IDs, so it follows that we'd apply it at the point where we reclaim them, which happens to be vacuum. > An idea is to check for XID age based invalidation for all the slots > in ComputeXidHorizons() before it reads replication_slot_xmin and > replication_slot_catalog_xmin, and obviously before the proc array > lock is acquired. A potential problem with this approach is that the > invalidation check can become too aggressive as XID horizons are > computed from many places. > > Another idea is to check for XID age based invalidation for all the > slots in higher levels than ComputeXidHorizons(), for example in > vacuum() which is an entry point for both vacuum command and > autovacuum. This approach seems similar to vacuum_failsafe_age GUC > which checks each relation for the failsafe age before vacuum gets > triggered on it. I don't presently have any strong opinion on where this logic should go, but in general, I think we should only invalidate slots if invalidating them would allow us to advance the vacuum cutoff. If the cutoff is held back by something else, I don't see a point in invalidating slots because we'll just be breaking replication in return for no additional reclaimed transaction IDs. -- nathan