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 1u7Kda-00EdEf-3t for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Apr 2025 20:54:38 +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 1u7KdY-000KYi-6i for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Apr 2025 20:54:37 +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 1u7KdX-000KYZ-TR for pgsql-hackers@lists.postgresql.org; Tue, 22 Apr 2025 20:54:36 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7KdV-001TLb-21 for pgsql-hackers@lists.postgresql.org; Tue, 22 Apr 2025 20:54:36 +0000 Received: by mail-il1-x131.google.com with SMTP id e9e14a558f8ab-3d900fda7bdso11079735ab.0 for ; Tue, 22 Apr 2025 13:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745355273; x=1745960073; 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=bkSt1U9fY5WYsFjd9qPeo3hlStN8h2i/jusUqXl0yHU=; b=GE1zpPu2AzdrQLsdwc5eajwc/47tDUXvG43MBLn/MOOstboDl8BIkN9feC+yBLBuJO Vvr66itXsjOz0hpYeeqzNNSZoMAcM+NFAtt6QCsYT2V8zKvzseJDrFfn881Ln1a76lL6 iSQCHSFfI5StQdip0Q8y1Rjp9GSEH3QO8TPEdd54ErPjQ2AjkSU/jVSd7wdo4c3mRbBh tUBXMm7ku7cwKssPTMfhbK2UfiBGgJIKPbDXRJkOglnnMPaHXEZdu9bX2v2gofxuyvWx Za0VjEHY8JBsVmEb1vgNTDgKDcnoHyOsGCm8G2jZSgbmTcnFusovs1dI17eq1Kmnzehx 7q3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745355273; x=1745960073; 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=bkSt1U9fY5WYsFjd9qPeo3hlStN8h2i/jusUqXl0yHU=; b=TKXvADZncfQ7H3eyBwVrSKSu8BqynJaWCasQb2RVtSGxVc/oGhcZoz8q3Q3L0yMmZv cNMVv2Mjdis7QLzw2SBeJ8zbvCq63CN81Fk3gZWBycI4RnxfIrcQuqIHEzzMdjPch9cp 5/JfD+XPqE9HOAxbFLlVs9/fWYEyZoDG5PqWP1bFWQm2kk1iguW91PcKEud7kH4LTB5S RcGhwSb5i4Jm7ydU0PcPmnmSj5o/etY7MXFT/bf8KLEhe6Uhdvum08BU4nTxe/yGSby5 LM3QtxYMQuyrnh39/2mN5pIr6XXlGMm8wSG+a6a8cS+u7CupzoUmp6kfYLPIEaBVdbJ1 b8+g== X-Forwarded-Encrypted: i=1; AJvYcCXbXVrq2xz2SKyxYW3NSRPyZM8nHZXFDN5Mf+mFZsuvBRIrhnycaqBCxo9QjVMeTB9pgvoAtLpUIdkg5TlN@lists.postgresql.org X-Gm-Message-State: AOJu0Yxoj2d5l2qOb1YVK/jUeW+OIKp94YF2PglP4xrRFYcm3Pk/RSZl G9m1C9GQiXk+RSv/ripPLwG4hjeJs9JXHhkV6NXs/2guZv/KvoI5 X-Gm-Gg: ASbGncv8iAfQe0ZhRnDRYniK6Hjen/Kq9wYxRgzJOCq+dstCwFtGlhkT6Tn2p8Zohj1 CUzLPD0X7pa/T54LnfOJJ9g9q7gdAYmqoCFpaZ+SBynq1ZLGZNfROyfqH+02IHNiy+s+CvVddgc GIXksKCeZi/0sAwEHGFOPd8V5MIPhETZqUe1nIWM+GOVZvB1otyHVxKa9cqViY8hobTFHceTPZp luUr6LHyKRLBap9s+QzvD0KJZ6LdGDFSVxqEeEuEI0CdvvLkBtrVXpYT9DmLvQc7q2kSFFmwchp /PD7BEHJOX+lxZne1NK3y2M6X9tGHrLB4rCUE9C2OK5ZLKdI5e4NGgPjaleRzg4ytS7Nll0FW40 5sawdJwjgMc+7SyAMBzCIac6ZZ2DwlSE= X-Google-Smtp-Source: AGHT+IGh3Alau/xF68mF2aseqwxNfObK76GQiRwSruJ9ZJlB59PmNWo0rdVszwdWvbffkjNBybXwlA== X-Received: by 2002:a05:6e02:1688:b0:3d3:f27a:9101 with SMTP id e9e14a558f8ab-3d88ed7c428mr161027425ab.1.1745355272730; Tue, 22 Apr 2025 13:54:32 -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-3d9276ac29bsm363335ab.63.2025.04.22.13.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Apr 2025 13:54:32 -0700 (PDT) Date: Tue, 22 Apr 2025 15:54:30 -0500 From: Nathan Bossart To: Christoph Berg Cc: Corey Huinker , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Update guidance for running vacuumdb after pg_upgrade. 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 Tue, Apr 22, 2025 at 09:43:56PM +0200, Christoph Berg wrote: > Re: Nathan Bossart >> Update guidance for running vacuumdb after pg_upgrade. >> >> Now that pg_upgrade can carry over most optimizer statistics, we >> should recommend using vacuumdb's new --missing-stats-only option >> to only analyze relations that are missing statistics. > > I've been looking at vacuumdb --missing-stats-only because Debian's > pg_upgradecluster is using that now. > > I am wondering if this is really good advice in the pg_upgrade > documentation. Sure it's nice that optimizer statistics are carried > over by pg_upgrade, but the pg_stat_user_tables statistics are not > carried over, and afaict these are the numbers that determine when the > next autovacuum or autoanalyze run is going to happen. By removing the > "please run vacuumdb on all tables" step from the pg_upgrade docs, we > are effectively telling everyone that they should be starting with > these numbers all 0, postponing the next run to some indeterminate > point. Running `vacuumdb --missing-stats-only` does not fix that > because it's skipping the tables. Is that the message we want to send? > > (If I am misinterpreting the situation the docs should still explain > why this is ok.) relation_needs_vacanalyze() uses dead_tuples, ins_since_vacuum, and mod_since_analyze. IIUC a full post-upgrade vacuumdb run would only set dead_tuples to a nonzero value, so the worst-case scenario is that it would take longer before a vacuum is triggered based on autovacuum_vacuum_{threshold,max_threshold,scale_factor}. To address this, I think we'd need to recommend using "vacuumdb --all --analyze-only" instead. We could alternatively suggest first running "vacuumdb --all --analyze-in-stages --missing-stats-only" (to fill in any missing stats) followed by "vacuumdb --all --analyze-only" (to update dead_tuples). However, I'm not sure how concerned to be about this. It does seem bad that it might take longer for tables to be vacuumed for the first time after upgrade, but I believe that's already the case for any type of unclean shutdown (e.g., immediate shutdown, server crash, starting from a base backup, point-in-time recovery). I see that we do recommend running ANALYZE after pg_stat_reset(), though. In any case, IMO it's unfortunate that we might end up recommending roughly the same post-upgrade steps as before even though the optimizer statistics are carried over. -- nathan