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 1tSCKS-00Emhy-92 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Dec 2024 09:44:52 +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 1tSCKR-00BAHE-BQ for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Dec 2024 09:44:51 +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 1tSCKQ-00BAH6-Vz for pgsql-hackers@lists.postgresql.org; Mon, 30 Dec 2024 09:44:50 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tSCKP-001EQy-0R for pgsql-hackers@lists.postgresql.org; Mon, 30 Dec 2024 09:44:49 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3863703258fso5881902f8f.1 for ; Mon, 30 Dec 2024 01:44:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735551887; x=1736156687; 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=NtCnrIbEmFzLK0tfiirtf+o7Ug/fd7/Gufl79TjB/UM=; b=RjItcP2KFFIG+sy/4OF/88FDergqch8P0T7k8OKuv/SuFX5fhC3iPdBxMzr9UFlz/j Un5BGW+xH9JD2ZTWMb35huDFYRI8Xhnel46paEDDiSxiFzJ6IZknKdG5xdUsT/Xo0qBa U0GhhptRIQV7KjJqXzAAHRx9hUz6srMLQPXd7oCFQSAyPRRyKjZxx40Kbaib1Af1sk3D +OiPJSvrk22jXTzGuJ+YtVVEhNYe4IcLEtyl1ARMhbrCELce7D9CzvM0OtEpEP0S1oem Vfl4MR+3tUQtmmj1fRmDmxDF0mzFCEynzIrJi2ekwAMp4Poz7Go/a00wlVFQNBqT5pDz 7EmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735551887; x=1736156687; 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=NtCnrIbEmFzLK0tfiirtf+o7Ug/fd7/Gufl79TjB/UM=; b=MTOisCGKmNalPM6a4C+MEKeEgwIiAtkEfoxSctd/Sdqd+FubxoZlhZzBRg8RUaoJiv KvDHd0uENE98TnS7GvJoZHa2i2dBj0ZG4C01CrcVinslpuZJiVQJG3BJmyompakB01Cn BMo18Od+nXVW8C/wZVk9DYV77/FDPqWWL2ngrwO0JQFOG8huwlE3sgcafHjPrQWaRHih r/lT4NeapCA6SEXTk3/e0F8mpu1jfmfh75v+cnZWyn1aaxTqzC9ujS3l0AtzymHLgQLW AN+FUmevI80jjWxgSNiCEJokOFumOF7HDmsADjL+eTs8Ad7Eh9W5x8gQPOrwI2GoH4sT Q2IA== X-Gm-Message-State: AOJu0Yz0NafMEGt+qNCvTYShiNGVYxW67QAWzRXQA27njQu6nwKjwTpE MfN5wf3XIpx9VevrKfH9Aplk2x02O78TMj10t00uy6FPaLO8Hwwp X-Gm-Gg: ASbGncthFV3pYrD/sPyjOWmwaz4ay8NrvQJwAOU6T4GYwGuD2bZGmvCAIcpnf3p3qvV +EYtvAp8gobfTk0iewGAgFFCg/QIYCDkg3KJOP8BDvdDEVsJgQ8YrsqXW/dYU+yX/cRk4ppxTJx PxeZnxr8ZkAdmbvdynW/7KAhP860itHmPOlBolxMXov4sQilPx7ypWKRqWxh2keeU6WLZEDoN5O /hlYHkuVMhwfPetmo2CuO5WOqYCH8tKHeJj0lhR2Nt+wxYWRMxeT2uHYIpuLK8WK49owHWw3UOr 1IQbhhGb62QF1vFM/paxVWlffrtgxFOSk23Z7+sE/D0z4gNcLuGKHy1JOV82Jr9Fk001Q2o40ZS QnDeNR0s= X-Google-Smtp-Source: AGHT+IG6bMFZAd5cLUbGz5gVZksGWBYGfcwDd3bU1AcDGg6fgwgJfdcSKoNMtbOSHoIafc+DxiOdvA== X-Received: by 2002:a05:6000:703:b0:385:f7e5:de88 with SMTP id ffacd0b85a97d-38a229ec5b0mr25795205f8f.3.1735551886662; Mon, 30 Dec 2024 01:44:46 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c89e126sm29140977f8f.65.2024.12.30.01.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2024 01:44:46 -0800 (PST) Date: Mon, 30 Dec 2024 09:44:45 +0000 From: Bertrand Drouvot To: Michael Paquier Cc: Postgres hackers Subject: Re: Autovacuum giving up on tables after crash because of lack of stats 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 Hi, On Wed, Dec 25, 2024 at 10:10:44AM +0900, Michael Paquier wrote: > > 2) The main issue I am trying to tackle is autovacuum giving up on > tables if there are no stats entries, so we could add *some* WAL > logging of the relation stats that are relevant for autovacuum, then > replay them. I think that the correct approach here is to introduce > one new RMGR for pgstats, giving to each stats kind the possibility > to call a routine able to do WAL logging of *some* of its data (custom > structure size, custom data size), and insert records associated to > their stats kind. We are going to need a new optional callback > defined by a stats kind to be able to force some actions at replay, so > as stats kinds can decide what to do with the data in the record. > Generation of WAL records has to happen pgstat_report_stat() through > the flush callback of each stats kind when the stats stored locally > are synced with shared memory. There is a different reason for that: > stats are flushed when backends shut down, and we are still able to > generate some WAL at this stage. An advantage of this design is to be > able to decide which portions of which stats kind is worth > replicating, and we can take a step-by-step approach we what data and > how much data we want to replay (for example for tables we should not > care about replicating the number scans). I think that's a good idea. As you said that would give the ability to discard some stats from the replication and replicate some of them (n_dead_tup,...). > Another benefit of this > design is for custom stats kind: these can call the pgstats RMGR to > pass down some data and define their own callback to use at replay. > If we do that, flushing the stats file at each checkpoint is not > actually mandatory: the most critical stats could be in WAL. > Among all these ideas, 2) is by far the most relevant approach to me, +1 > because even if we do not flush pgstats at checkpoint, we can still > keep around relevant stats when performing crash recovery, while > copying around some stats on standbys. It should be possible for a > given stats kind to do a different action depending on if we're in > standby mode or just in crash recovery. And that would take care of > this autovacuum problem post-crash: we could have stats to help in the > decision of if a table should be vacuum or not. Note that the > implementation can be done in multiple steps, like: > - Adding the whole WAL pgstats facility and some tests related to it > (WAL logging with injection points for variable and fixed-numbered > stats in a custom stats kind). > - Deal about the autovacuum and relation stats part. > - Open the door for more replication of stats data, whatever that may > be. > > Comments, thoughts or tomatoes? I think that replicating stats that are used by autovacuum would be an additional benefit, so +1 for the idea number 2). This is an "issue" that has been raised multiple times (like in [1]). [1]: https://www.postgresql.org/message-id/20240607033806.6gwgolihss72cj6r%40awork3.anarazel.de Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com