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 1v1ZhM-00A785-31 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 00:19:00 +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 1v1ZhJ-00GeCB-GO for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Sep 2025 00:18:57 +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 1v1ZhJ-00GeC2-4U for pgsql-hackers@lists.postgresql.org; Thu, 25 Sep 2025 00:18:57 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1ZhG-002GlW-1l for pgsql-hackers@postgresql.org; Thu, 25 Sep 2025 00:18:55 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-4256f499013so2085275ab.1 for ; Wed, 24 Sep 2025 17:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758759534; x=1759364334; darn=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=DUHjmC0T/OnLLSSgnPSa1uHW4WPeMRSQrakU8SHqa48=; b=IlSkRgt3ltRnKL44OcQ5KYaAlNfz5zHO9/uEDDb/+4c6hg7qjm+PDdhHr6zuIBISDv So4OMgS9OaDqSH+9jM+WkfQtb3JbB/jRRF8d4SF8Ea0ivzkV0TxEVdO4hOZBCAyiP+bT bdRNnsVz0Cp5A2GL9PKNUfsIPxMxxLm9PpxFMEQ+3ozvtC1iqjPFcDJRL1iega+TQGGC 8jXQ5ZABwMMbF8fQiWRs5JBChs/O62FNVeypDZsatKET4ViaNtsr2LX6Rpyt6bSEXB31 J4Bh3+vjEwVbXn493ilt2/J28cmpuIAB85RQvGphdbArUhFnOx3fMqkLTvWnJH1JSyRn dW0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758759534; x=1759364334; 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=DUHjmC0T/OnLLSSgnPSa1uHW4WPeMRSQrakU8SHqa48=; b=f0jqoJZ74kd/XHtDbpBQuWLYkc95fMSolli3BucBTqeiku6gd+XoxhC23XxuL2GAai 34i+u0hMUcl6Xayk7NuVy1VaWw95/1mtDgwScmnmBkKRpfW/9byuDdr3MRxUYGErChYR RK5b7k7asixJUk3GAC9oW6jreIJRxSqc4vkK4qxdtWNUOhxFKXL3md9ipMQBMbUN/T1e +bM2N+GqHyN1Sod28bOZRIyAkEoZgSgoEJCbMTZqZjSDO2GI3CMIVQRgZlsoOf6p0vQf gyMB7RnK4psmnN02UZ4qRdWDmEwSLm0XbOLsaqGtGtwoV0sYLpFnv2QM2jaYxYwjwkRO 6n3w== X-Gm-Message-State: AOJu0YwRhKVD6N5MD3OJaW0/j52A1jhyRmryAnid+rRoQpcNj5asoRqo KcOVXiz1yCnyR4ZfoPIW5zzFXcmTFfzLom3rDBI/oBnqQn/McAE2Irq/+L6IezogpMUa+uav163 +++EqHL37XDmmaYpqsrJr3sorPpWgoXTjDlzU X-Gm-Gg: ASbGncuRo4u7m1ayRSz+WUDyvTYHWHfDQhOY6zs+kMcdEia60W5jZY0qy/zkqJEahlp NdjSIJF444NXSpU5KLMJLVlOlZCh6EJgbwSYbhlAwVX3pGnglNg9s/4ZiPZBjO0KgM7OhOQVsnY MVesLu6ZZYtCTDPv+A47lelQH3K9KAnMowx+dUeafcn1DW0SsRnAOTFcV/bIWIhdyYW+J/uiMy+ N1CpZNvjBTnzoy0AEMgzZvqb6WGoYrlj+gFNwuY X-Google-Smtp-Source: AGHT+IHYDNhH1XeLzRHKScq0TehFhOLvRr2pjjCzR2FKGqaIwLDfsWSATX0C7JKmYSrApWxve8bzjdmzw9OOt3+vwes= X-Received: by 2002:a05:6e02:4514:b0:425:7526:7f56 with SMTP id e9e14a558f8ab-425955d0ae3mr19274925ab.5.1758759534190; Wed, 24 Sep 2025 17:18:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Wed, 24 Sep 2025 17:18:42 -0700 X-Gm-Features: AS18NWBYc4K1_ThngEQghiVTBt3JkUlAU95y01ZwoF9_VbsirYxkncjRRw3WKYE Message-ID: Subject: Re: Introduce XID age based replication slot invalidation To: John H Cc: pgsql-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, On Thu, Sep 18, 2025 at 10:20=E2=80=AFAM John H wrote: > > I'd like to restart the discussion about providing an xid-based slot > invalidation mechanism. The previous effort [1] presented an XID and > time-based invalidation and the inactive time-based approach was > implemented first. The latest XID based patch from Bharath Rupireddy > can be found here [2]. > > When thinking about availability of the database, inactive replication > slots cause two main pain points: > 1) WAL accumulation > 2) Replication slots with xmin/catalog_xmin can hold back vacuuming > leading to wrap-around > > It's easy to imagine a high-XID churning workload in one cluster while > another has large batch jobs where changes get synced out > periodically. There isn't a "one-size" fits all setting for > 'idle_replication_slot_timeout' in these two cases. +1. > The attached patch addresses this by introducing 'max_slot_xid_age' in > a similar fashion. Replication slots with transaction ID greater than > the set age will get invalidated allowing vacuum to proceed, biasing > towards database availability. > > Invalidation happens in CHECKPOINT, similar to > 'idle_replication_slot_timeout', and when VACUUM occurs. > > The patch currently attempts to invalidate once-per-autovacuum worker. > We're wondering if it should attempt invalidation on a per-relation > basis within the vacuum call itself. That would account for scenarios > where the cost_delay or naptime is high between autovac executions. IMO, computing XID horizons per-relation during vacuum is good. The main reason we try to invalidate replication slots based on the XID age in the vacuum path is to help the database when it needs it most - when vacuum is computing the XID horizons. That said, it would be good to have performance analysis with a large number of replication slots, comparing once-per-relation vs. once-per-autovacuum worker vs. once-per-autovacuum launcher wake-up cycle. I haven't looked at the patch in depth, but it would be good to have a TAP test with more realistic production workloads. We could set this value to less than 1.5 billion and use xid_wraparound test to quickly reach the wraparound limits, then verify if this setting can help prevent the database from reaching wraparound errors. This approach would also validate the age calculations in try_replication_slot_invalidation with higher limits. --=20 Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com