Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPfiN-00066f-Kg for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Apr 2020 05:08:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPfiK-0001If-JS for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Apr 2020 05:08:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPfiK-0001Cf-7l for pgsql-hackers@lists.postgresql.org; Sat, 18 Apr 2020 05:08:24 +0000 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jPfiG-0000zu-LQ for pgsql-hackers@lists.postgresql.org; Sat, 18 Apr 2020 05:08:23 +0000 Received: by mail-qv1-xf42.google.com with SMTP id di6so2010923qvb.10 for ; Fri, 17 Apr 2020 22:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Q7vmB+tKVlaRPiGGYcjVl0sNVs/a9kxg6TOsD4H1IbY=; b=sYD+jcrd6ozt2uebroneq+931rprPK08ZOXeDdGpQjLbHATZJeu5Z9ad8BoQkxFpnd 7rwL5lEg4alTSkuRgKU5eP2znw7+rOOtROKaIBsJ5iv0Qr5wB5L7bhjOGnBXmZdpz3qd Qq7BYmLxLJhXcIuj3g8rCUIai9yCV7uqWSc3ajZtEtOMekuF+Puov/FEzzBpBTTlhXvc eIE721RzBfuqx4lBgcu0QMcGqaqygZKuMsSv7EmncHsiHCT3rUz3t7rPcdk+QsY92XKv Qnt0M4264F2sQOHKX1ofDXBAzrRu056EaH42ipZQOcvr9OUIAFTwQ5G6MuVP/1ozhNAC m4pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=Q7vmB+tKVlaRPiGGYcjVl0sNVs/a9kxg6TOsD4H1IbY=; b=hkEUb0mQZ4NOr+Ht2OHgCJpkTLj3L9FpQgAiyMTKpF2ealwnVmJJdSNd2mgEQ7e4Tl k7bcojn4U+kGg68poHIYX+TzHVxQQs4KliZI8fGjJgmyv2yzMkS3eHiMcIHC701EGyRy k+KU3gmWskw8mDsSyGeVOt7QP78cxVtSV+sd3LW09Q8GgkA91XBESg+GbHc1LYS7ZGJH E/HSqsZI3wlZGbuDLnYNnir+5RWjO3GS2OJ6GpFvlYQTzKiKOuvw2pJz9MpPOi5a+xPv xyU50T0Gq5bVoWuZsptgJtKTGPpVCDP6szX1xx+COtXDsna3/LKlbNnbXvgbWViOpAG5 aeaQ== X-Gm-Message-State: AGi0PuYbiQZf4TiN/EniLP1rplKyAPf2PtluVEy8nnr3s385lDT66vu9 WDz5bqkyMaR8NOOj4lGYX5X8xw== X-Google-Smtp-Source: APiQypKHsr1e6K9/WbDVTsxJCKwsdHkFr/VNZOdiPJOlENBzmhwOF9PW80PLWN2Mv5mMKwnLP0H+EQ== X-Received: by 2002:a0c:ed42:: with SMTP id v2mr2906686qvq.94.1587186498518; Fri, 17 Apr 2020 22:08:18 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id l189sm18415519qkd.112.2020.04.17.22.08.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Apr 2020 22:08:17 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 02A12800A81; Sat, 18 Apr 2020 00:08:15 -0500 (CDT) Date: Sat, 18 Apr 2020 00:08:15 -0500 From: Justin Pryzby To: Amit Langote Cc: yuzuko , Alvaro Herrera , Masahiko Sawada , Laurenz Albe , PostgreSQL Hackers , Greg Stark Subject: Re: Autovacuum on partitioned table (autoanalyze) Message-ID: <20200418050815.GE26953@telsasoft.com> References: <20200228022545.GA19686@alvherre.pgsql> <20200318163039.GL26184@telsasoft.com> <20200407033256.GG2228@telsasoft.com> <20200416141910.GM2228@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Apr 17, 2020 at 10:09:07PM +0900, Amit Langote wrote: > On Thu, Apr 16, 2020 at 11:19 PM Justin Pryzby wrote: > > On Thu, Apr 16, 2020 at 06:16:45PM +0900, yuzuko wrote: > > I don't think that adequately allows what's needed. ...(paragraph with my typos elided)... > > For example, say a new customer has bunch of partitioned tables which each > > currently have only one partition (for the current month), and that's expected > > to grow to at least 20+ partitions (2+ years of history). How does one set the > > partitioned table's auto-analyze parameters to analyze whenever any child is > > analyzed ? I don't think it should be needed to update it every month after > > computing sum(child tuples). > > > > Possibly you could allow that behavior for some special values of the > > threshold. Like if autovacuum_analyze_threshold=-2, then analyze the parent > > whenever any of its children are analyzed. > > > > I think that use case and that need would be common, but I'd like to hear what > > others think. > > Having to constantly pay attention to whether a parent's > analyze_threshold/scale_factor is working as intended would surely be > an annoyance, so I tend to agree that we might need more than just the > ability to set analyze_threshold/scale_factor on parent tables. > However, I think we can at least start with being able to do > *something* here. :) Maybe others think that this shouldn't be > considered committable until we figure out a good analyze threshold > calculation formula to apply to parent tables. > > Considering that, how about having, say, a > autovacuum_analyze_partition_parent_frequency, with string values > 'default', 'partition'? -- 'default' assumes the same formula as > regular tables, whereas with 'partition', parent is analyzed as soon > as a partition is. I assume you mean a reloption to be applied only to partitioned tables, Your "partition" setting would mean that the scale/threshold values would have no effect, which seems kind of unfortunate. I think it should be called something else, and done differently, like maybe: autovacuum_analyze_mode = {off,sum,max,...} The threshold would be threshold + scale*tuples, as always, but would be compared with f(changes) as determined by the relopt. sum(changes) would do what you called "default", comparing the sum(changes) across all partitions to the threshold, which is itself computed using sum(reltuples) AS reltuples. max(changes) would compute max(changes) compared to the threshold, and the threshold would be computed separately for each partition's reltuples: threshold_N = parent_threshold + parent_scale * part_N_tuples. If *any* partition exceeds that threshold, the partition itself is analyzed. This allows what I want for time-series. Maybe this would have an alias called "any". I'm not sure if there's any other useful modes, like avg(changes)? I guess we can add them later if someone thinks of a good use case. Also, for me, the v7 patch warns: |src/backend/postmaster/autovacuum.c:3117:70: warning: ‘reltuples’ may be used uninitialized in this function [-Wmaybe-uninitialized] | vacinsthresh = (float4) vac_ins_base_thresh + vac_ins_scale_factor * reltuples; ..which seems to be a false positive, but easily avoided. This patch includes partitioned tables in pg_stat_*_tables, which is great; I complained awhile ago that they were missing [0]. It might be useful if that part was split out into a separate 0001 patch (?). Thanks, -- Justin [0] https://www.postgresql.org/message-id/20180601221428.GU5164%40telsasoft.com