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 1u7bAD-002Ipa-UX for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 14:33: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 1u7bAB-006qlq-8r for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Apr 2025 14:33:24 +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 1u7bAA-006qli-TB for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 14:33:23 +0000 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7bA8-001Xxu-1O for pgsql-hackers@lists.postgresql.org; Wed, 23 Apr 2025 14:33:22 +0000 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3d9030c2b73so9765575ab.0 for ; Wed, 23 Apr 2025 07:33:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745418800; x=1746023600; 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=RvZNnLlPrcnzmtq1BTj9jSblx3JFgxxI57PMm71NQ58=; b=f4P3Y6HMHZkjLLxHOkcGVzD7zXcZciZQaht/1++1T9QvLlrJ+chJ/Q4+KYbJA1iHCS xBSnxCZ5PSTR7oTNJ3UMGYhUJKe+K1pVRwyFuPmhIL65lTZ6r6pexaYMgpwS/y+s/wm3 UPeIOwlkwSXHak4A/ZCzAs5sf3rnuZGBlpn0mQdemiJwHdQ6EEMt1pSmcZLir06IFNzG r3BPoF+orCzw6iPsoXjqu6hx0E5RdwQ5QEI1SkCDnIUhpQI8QqTouw0SpESZqlrdb9tA PUBP5TEcyI6F6L1xniBSlL+9Bkmt5ps/fEfrXahPA+rSAtyU6Os1nDEA6KUa8w143Vlu XwXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745418800; x=1746023600; 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=RvZNnLlPrcnzmtq1BTj9jSblx3JFgxxI57PMm71NQ58=; b=uj70RoyTBZkOV1B6UD5Fz7uat7uUBXk9Za2gL3aAuaKRZo79nvVOqyHYtAIxRU/shM coXLJy5429Du89ZusnSUruyDBHS82RnUj+ysRXd0s75h6BgFJp6fFyidiZeVnbBrdVQd kMbOsHWOucDl5yjoT+Dy3+G2ID2fLfyCeu/hp3RFcjJD5osak5octVjdeuiOlBWhzH6B UswW4VCTDwmTZSeo60OvFVn97mZ2qrppAjjjHobOTb+JbhhO+hM+dKt6LQ/HM8XetN4K IRdWnB2V4G6tNG58PbCyCk8xWErlwU1GDQkjU2y1Ig5QiU4ApqWGp8105UyS4jD6fj97 VtAw== X-Forwarded-Encrypted: i=1; AJvYcCVwQ+uf085rh5yL+JAJPrZT6kimo7ZpRMJgqKvEiU7yI3t9mXdg2IC5h1soFu9LCfzKsy3GcxjTTda/MOpD@lists.postgresql.org X-Gm-Message-State: AOJu0YzT0ukhbkur4V7routVpT0Gaed09D7IIg1VWzxpK36kHwixU+p1 F/iZGmIeNtepYSQMnpZn2z+8iIyqyRyIEu46C09S+f8UMvlExT5u X-Gm-Gg: ASbGncuXWu4Ok/5VbrGa/dlBI4qXZrhRyFpdNjj6kOUKaMUy/mjA6JMJ6Uodsa/GL8v dh4t4d9MZMSNH+00q4FbXI76eDv7nxPe7mxwtatgLWrlG7N10K3Czze4g9VmEC3Vb9nP5ZaBGq2 nYr+m/9C3fJfml1Rq0Ittk6dBy5FOS+/0mEEamawgSQmEUWESouXcwWMKSc8ffaXeS6IlIcJ8PD F/kwuxkEjk8tka3du5yLFlaW0mqJ3kbBDp0C80NL3MLxl+HmmcuD4Rb2RX3n6qYFybPNe5C2Mlr eAJwwDahXXkik8oMmLGTpyglP1+zbsfbdyBQDE2VCQBhPYxs/7+nkCUSpJ4EqdkOLW0hFdBCgHV avhGO6PItIP83ngqIS9Je7YrCGreod3p0BjkUNwsIWA== X-Google-Smtp-Source: AGHT+IG1ag1q7RtU5wqisyo8IEpAUFsPfrtLPrTsAo5Eebbb+JfJkaExNxPsMPTYUS6CbyybSuxqdg== X-Received: by 2002:a05:6e02:219e:b0:3d4:3ab3:daf0 with SMTP id e9e14a558f8ab-3d88edae7f9mr215162965ab.7.1745418800014; Wed, 23 Apr 2025 07:33:20 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4f6a37fb41dsm2837398173.38.2025.04.23.07.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Apr 2025 07:33:19 -0700 (PDT) Date: Wed, 23 Apr 2025 09:33:17 -0500 From: Nathan Bossart To: Christoph Berg Cc: Nathan Bossart , Corey Huinker , pgsql-hackers@lists.postgresql.org Subject: Re: vacuumdb --missing-stats-only and pg_upgrade from PG13 Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1IeyT3aJTime+xBw" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --1IeyT3aJTime+xBw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 23, 2025 at 04:01:33PM +0200, Christoph Berg wrote: > If I create a table in a PG13-or-earlier cluster, never ANALYZE it, > and then pg_upgrade to 18 and run vacuumdb --analyze-only > --missing-stats-only, the table will not get analyzed. The only table > visited there is pg_largeobject. I suspect this is due to commit 3d351d9, which started using -1 for reltuples before the first vacuum/analyze. Before that, we set it to 0, which could also mean the table is empty. --missing-stats-only checks for reltuples != 0. My first reaction is that we should just remove the reltuples != 0 check. That means vacuumdb might analyze some empty tables, but that doesn't seem too terrible. -- nathan --1IeyT3aJTime+xBw Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fix_missing_stats_only.patch" diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index 22067faaf7d..79b1096eb08 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -954,7 +954,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, appendPQExpBufferStr(&catalog_query, " EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n" - " AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" @@ -967,7 +966,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n" " WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n" - " AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n" " AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND NOT EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext_data d\n" " WHERE d.stxoid OPERATOR(pg_catalog.=) e.oid\n" @@ -979,7 +977,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, " JOIN pg_catalog.pg_index i" " ON i.indexrelid OPERATOR(pg_catalog.=) a.attrelid\n" " WHERE i.indrelid OPERATOR(pg_catalog.=) c.oid\n" - " AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n" " AND i.indkey[a.attnum OPERATOR(pg_catalog.-) 1::pg_catalog.int2]" " OPERATOR(pg_catalog.=) 0::pg_catalog.int2\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" @@ -994,7 +991,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_attribute a\n" " WHERE a.attrelid OPERATOR(pg_catalog.=) c.oid\n" - " AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n" " AND a.attnum OPERATOR(pg_catalog.>) 0::pg_catalog.int2\n" " AND NOT a.attisdropped\n" " AND a.attstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" @@ -1011,7 +1007,6 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, appendPQExpBufferStr(&catalog_query, " OR EXISTS (SELECT NULL FROM pg_catalog.pg_statistic_ext e\n" " WHERE e.stxrelid OPERATOR(pg_catalog.=) c.oid\n" - " AND c.reltuples OPERATOR(pg_catalog.!=) 0::pg_catalog.float4\n" " AND e.stxstattarget IS DISTINCT FROM 0::pg_catalog.int2\n" " AND c.relhassubclass\n" " AND NOT p.inherited\n" --1IeyT3aJTime+xBw--