Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL8q4-0003nS-JE for pgsql-admin@arkaria.postgresql.org; Thu, 17 Oct 2019 16:41:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iL8q3-0003yp-84 for pgsql-admin@arkaria.postgresql.org; Thu, 17 Oct 2019 16:41:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL8q2-0003yh-Pz for pgsql-admin@lists.postgresql.org; Thu, 17 Oct 2019 16:41:22 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL8pv-00085l-DM for pgsql-admin@postgresql.org; Thu, 17 Oct 2019 16:41:22 +0000 Received: by mail-wm1-x343.google.com with SMTP id 5so3272608wmg.0 for ; Thu, 17 Oct 2019 09:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=BuWTeNe+KqNOhqoukqH4fURrfCM7FrNXumfaoNYOb24=; b=gaSf/APGAYC7Jjb7wxiO50BrzLhZf/AuRZLUjUNGbD8xD2qeHdXXaA2PhGJq7Tsyms DbzS+WczPJYKPa6GbPK3mkalx+qYZWd/IjCbUdowI+NmEGhfUm+ypBpMx0dh0eudYHfY VwPw5RioPScVATpkEwvkolmBwTHD9lwLOu466wj7t5JveOIcjo1whVxIXtH1zNJW5/1V U9etkMWZ4DnvhQ8IMO20+AGpJFcKkSOMgyNqceLRt0v5TXTRLnHN1H2yx1qfO7wb/CF7 fkPMW9lEuODXSMVeYH7OTBvBXEvwamf9OyXZtz5a63uM8GDxuZnmoFNr0/Fs3dj7WWet UF4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=BuWTeNe+KqNOhqoukqH4fURrfCM7FrNXumfaoNYOb24=; b=kwc482eKr1tIchYdCL/PpGdZT0rxgYUu+z548rV7FGIlMpdVCzdKNqw0TqU1MqEMx2 wyMgnN9e66KXTbJZ2dNQEERXlDaxJRZWDcRwesan9bRosl5/ud6M+W3rnL4b8IBT8IjW EfrFBZJOpTel07g3Kg4fjceVysLNJW/qHKygg7zjaTasSoK1uMPElhqwmEQP06wrFfTR fnMblH/x9EOGhvLkVzMlOWkVlIkHgvEO92I5pp1fh2Y17B18Yo1sv1bhr+ufQdXUyBXd 3YO5o8Y0dncc0/Rk3ZEZ1Rt7ECH6X9luyO/rRFOlmyZBNPlS91OCUwH3SuQPmXhAzajX mxwA== X-Gm-Message-State: APjAAAWQfx/YKUqUOotQ4EhfNWMyKOAwNmaUmVMJ8O6Kvzu4rw2Ep2Rf HFncqDjYBDn4hWwml+uw5OyXlg== X-Google-Smtp-Source: APXvYqwdslWLSoGyVxQ1DXcJCMOn7NNK/pfpgDDrLdZaCAL3lCfRZ/rBuoQdgG9SvGWnMVl9FL3vHw== X-Received: by 2002:a1c:d0:: with SMTP id 199mr3850862wma.67.1571330473987; Thu, 17 Oct 2019 09:41:13 -0700 (PDT) Received: from localhost.localdomain ([213.215.245.62]) by smtp.gmail.com with ESMTPSA id c132sm2631594wme.27.2019.10.17.09.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 09:41:12 -0700 (PDT) Message-ID: Subject: Re: Vacuum & pg_class.relallvisible From: Laurenz Albe To: Rob Emery , pgsql-admin@postgresql.org Date: Thu, 17 Oct 2019 18:41:12 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, 2019-10-17 at 17:32 +0100, Rob Emery wrote: > I've been attempting to figure out if the autovacuum/vacuum process will use > pgclass.relallvisible when vacuuming a table to know if it's able to > skip freezing at all. > > Basically we have tables that this query: > ``` > SELECT c.oid::regclass as table_name, > greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age > FROM pg_class c > LEFT JOIN pg_class t ON c.reltoastrelid = t.oid > WHERE c.relkind IN ('r', 'm') > ORDER BY age DESC > ``` > > returns the age as greater than 'autovacuum_freeze_max_age' which was making > us believe that autovacuum wasn't running. > > When we looked into the actual rows with: > > ``` > SELECT t_infomask::bit(16) as bits, t_infomask::bit(16) & (x'0100' | > x'0200') as isFrozen FROM heap_page_items(get_raw_page('tablename', > 0)) > ``` > we could see that it looks like all the rows in the table are frozen; > so it would never need a vacuum! > > I don't understand how the autovacuum knows that it can skip that > table without looking at all the rows, which is the process of > vacuuming that table! > > Much appreciated if someone can clean up my understanding. PostgreSQL 9.6 had this new feature: Avoid re-vacuuming pages containing only frozen tuples (Masahiko Sawada, Robert Haas, Andres Freund) Formerly, anti-wraparound vacuum had to visit every page of a table, even pages where there was nothing to do. Now, pages containing only already-frozen tuples are identified in the table's visibility map, and can be skipped by vacuum even when doing transaction wraparound prevention. This should greatly reduce the cost of maintaining large tables containing mostly-unchanging data. So, to the best of my knowledge (I didn't read the code), autovacuum should still launch an anti-wraparound worker, but that will look at the visibility map, determine it has nothing to do and just update "relfrozenxid". Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com