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 1v6Vvu-005l4j-Js for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Oct 2025 15:18:26 +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 1v6Vvs-00B17v-7J for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Oct 2025 15:18:25 +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 1v6Vvr-00B17n-T9 for pgsql-hackers@lists.postgresql.org; Wed, 08 Oct 2025 15:18:24 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v6Vvq-0013Ud-0e for pgsql-hackers@postgresql.org; Wed, 08 Oct 2025 15:18:24 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-93ba2eb817aso447035739f.2 for ; Wed, 08 Oct 2025 08:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759936700; x=1760541500; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=kS+g50v6V+puV1jxQk9IM+5WbSYDBYqnBazYTgPp5mc=; b=dqT+gipkI/WJFz5rHnAnDcBlDzLN52SPB0IHVKiTC1KOyNhSaUwbmAcV15Vyqx1cAx sASQsUb+jwp54agBWatM+Ol2BHWFMg7AiGlxFk8a0kEARfRJF+iiEdSpZM5VPBoxkCP0 GQxleaL/y9U0ER8jWh0c8Am8/m86dd+q//tCaSQAum/D6vDlvlcUnRM+hq6xR68cm0nY aqhdt9/FNQCiUS1wuJpooc4BNa/Wf5RJx1B8HIxZdxGASwJj0MUtRhWn2NS5fIOxwizK 41yJEt603fVcNXv7mwOM1gjnqhume3/lZnuqbwoNhnZnWYq4XdggeKeW+Be1GgFdrMdT vnBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759936700; x=1760541500; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kS+g50v6V+puV1jxQk9IM+5WbSYDBYqnBazYTgPp5mc=; b=c/cuMBUjFJP9nfw1HRyGsHpVjY5UBf82CD6tYkeWFZ/e1c7wp2QGLVY0UnbX5iTOtI GUXCffYie+Rvee/oM9SYjHX1MQefa+vqp6lxxQBLXKEf1Z5DSNOEYtkv8szCacHNWo3x CQdEVoxPAHAFAGrSOWSff4NM/xKnM3NWk/RrRetKejTG9FgQTCL/Q17sXpbJr8RR8d8O 30j8RycH7oPa1xahVI/1Upr8guucilrfzmSj6h6uvx1gmsP+Pl/KGgpvY9zDX/56GFd0 Nfu8g2r3IK+UNc5K8xKje198HypzmYAN+lY/fLkHy41AcU60RJi1jTFcQwK7W+pl8xXX Hd4Q== X-Gm-Message-State: AOJu0YyAp0PvN88zXej/jZYJsY5S0qcbSMPbQUC/7VG/79+D9i8Nz+pP IjKmkgUvAV8+q5wkcykZ6sWcDm0tHutG5VRfhZUImgw3KZjaaU48PttNqgdOsQ== X-Gm-Gg: ASbGncuYPqEzkel9XlWBR1zHKFnbItVPbogoQuew1iC5Q5D4nreSIcw3iBSffG1ERVz cWTVYlaXR0ODrtdZ0M4aQNjhzDB9+VfQJ4ydyAW3uf8Qagu3SfzYwCYJuKhhp63+rNmVLKdWwT5 NTSCzK/0PJS90ZHvBLUk/NUOgB0X+X2cqw3dKpLpyeThgVyrBEebmU/ExJGpMKWeeP31n+zLIP8 KkYk/tBvZwN48GNPZhPAUjrAtNhXEKbPuHVhVZEV4a/SaKGkwA6KhKLMmTxxm1p6cTd0ZnzbKxb mGgFkH3vm2l8fmbC9/PyKhpm1dIKDLLmRTX2PZOaTexdRewC2qJRVj/IwNVjk0P6YK4+9o76QLh 00WQMYV9cdmSWEoeBrB6ybesRoNgaYD1xkeuHOBH1vxvhsFzl9698Ot+22efOjrxgquMXpryqSU e5lmFcEhxXyE+0XvZ8CT8w0gFXWLELxELnIqTbEpRjffDWQoQ= X-Google-Smtp-Source: AGHT+IFI03EDA/cNFNOd9BFnYG0atWQJUPHqLCD+4yg79nZXOMzvlZT8c+cRlnC3dk+K2AfpAFIiPw== X-Received: by 2002:a92:ca4f:0:b0:42d:84ea:b370 with SMTP id e9e14a558f8ab-42f873d1fa9mr34125885ab.16.1759936699546; Wed, 08 Oct 2025 08:18:19 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-42f90343080sm78145ab.22.2025.10.08.08.18.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Oct 2025 08:18:19 -0700 (PDT) Date: Wed, 8 Oct 2025 10:18:17 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: another autovacuum scheduling thread Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2AXllIwTMvAwquZP" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --2AXllIwTMvAwquZP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline /me dons flame-proof suit My goal with this thread is to produce some incremental autovacuum scheduling improvements for v19, but realistically speaking, I know that it's a bit of a long-shot. There have been many discussions over the years, and I've read through a few of them [0] [1] [2] [3] [4], but there are certainly others I haven't found. Since this seems to be a contentious topic, I figured I'd start small to see if we can get _something_ committed. While I am by no means wedded to a specific idea, my current concrete proposal (proof-of-concept patch attached) is to start by ordering the tables a worker will process by (M)XID age. Here are the reasons: * We do some amount of prioritization of databases at risk of wraparound at database level, per the following comment from autovacuum.c: * Choose a database to connect to. We pick the database that was least * recently auto-vacuumed, or one that needs vacuuming to prevent Xid * wraparound-related data loss. If any db at risk of Xid wraparound is * found, we pick the one with oldest datfrozenxid, independently of * autovacuum times; similarly we pick the one with the oldest datminmxid * if any is in MultiXactId wraparound. Note that those in Xid wraparound * danger are given more priority than those in multi wraparound danger. However, we do no such prioritization of the tables within a database. In fact, the ordering of the tables is effectively random. IMHO this gives us quite a bit of wiggle room to experiment; since we are processing tables in no specific order today, changing the order to something vacuuming-related seems more likely to help than it is to harm. * Prioritizing tables based on their (M)XID age might help avoid more aggressive vacuums, not to mention wraparound. Of course, there are scenarios where this doesn't work. For example, the age of a table may have changed greatly between the time we recorded it and the time we process it. Or maybe there is another table in a different database that is more important from a wraparound perspective. We could complicate the patch to try to handle some of these things, but I maintain that even some basic, incremental scheduling improvements would be better than the status quo. And we can always change it further in the future to handle these problems and to consider other things like bloat. The attached patch works by storing the maximum of the XID age and the MXID age in the list with the OIDs and sorting it prior to processing. Thoughts? [0] https://postgr.es/m/CA%2BTgmoafJPjB3WVqB3FrGWUU4NLRc3VHx8GXzLL-JM%2B%2BJPwK%2BQ%40mail.gmail.com [1] https://postgr.es/m/CAEG8a3%2B3fwQbgzak%2Bh3Q7Bp%3DvK_aWhw1X7w7g5RCgEW9ufdvtA%40mail.gmail.com [2] https://postgr.es/m/CAD21AoBUaSRBypA6pd9ZD%3DU-2TJCHtbyZRmrS91Nq0eVQ0B3BA%40mail.gmail.com [3] https://postgr.es/m/CA%2BTgmobT3m%3D%2BdU5HF3VGVqiZ2O%2Bv6P5wN1Gj%2BPrq%2Bhj7dAm9AQ%40mail.gmail.com [4] https://postgr.es/m/20130124215715.GE4528%40alvh.no-ip.org -- nathan --2AXllIwTMvAwquZP Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-autovacuum-order-tables-by-m-xid-age.patch