Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIpLI-0008GU-GL for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2020 08:00:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIpLH-0002Pc-6H for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2020 08:00:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jIpLG-0002PV-TI for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2020 08:00:18 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jIpLA-0002v1-QY for pgsql-hackers@postgresql.org; Mon, 30 Mar 2020 08:00:17 +0000 Received: by mail-lf1-x142.google.com with SMTP id e7so13336868lfq.1 for ; Mon, 30 Mar 2020 01:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lIviXlEFfc15OXFPJX6G5xjxXS8l8lw5Q/8ipG1TCo4=; b=LYN0QrIGdlEvgti83xiyJk/zRtszNQjeOT1p15oi4FgtOHcr+gyERzdgwJzyiiX7j9 4cDTB4Mh3OVe32RlLH94AOCotkprgk0UTTlkD6VkZL0o/jbch5v14wKxa89TDHHnT222 +RiK7nG9f/EU5tw/us8DduAmrYaS0xytBCkEY5/A7XaVnUIkdxGrkoQWeRaaX68i6fQu tnUJXrMCf9XP5tta2/yOoEWi0jVcc6ZbJOqKFreApE4aWGtKxKXjkVLr/Mq43KyuZBLN KST59sG5IygQbkFtnQFA53ziwaH5zgOL65OPD7IAYCQX/cNaLRjAh51dRGUUs83JlDPd ueIg== 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:in-reply-to; bh=lIviXlEFfc15OXFPJX6G5xjxXS8l8lw5Q/8ipG1TCo4=; b=FmvYNEiEjxYfS7f4nXLGITeqLqvglnfeJ1fEQHet/5nWAipIvbhSBiq2zIMzZL5GnX fHiDHAGV6C63m7939Ww+b+Abgg/xfjoZfuGFLkGOzH+TbOiZVpWzVYvFK2KCbcAt2ouC HrOU579V/On+HHanR76Q1VQIhyoC/IGJGB7xp1f+C9c8BQS5jXkBRpkLuA+NWlYhwo1a BYOVigWJVdXSywYPjVFXpHCShFr20LSs/PJlwuCPiV4cicIhR/sZzNXVDqr7KouE6mK5 Gu2Y4nBTDNVckzdtGeCKApML9uCzUaNCoGaVwC0YQalINWbOC8IVlmOJmMz67X4Lu/39 lYOg== X-Gm-Message-State: AGi0PuZNaxtqUkp3859ZpROAxgeBbVtajtPhN0blywB8VLj/c+ELf0eT 16Gl69M8i1Uw6wNrwA64RI4= X-Google-Smtp-Source: APiQypLisU5RyRzQ5Yl+5i1JRJ/57H6+9zKJLVjBN71vdbcbPnQFhOHXs6IdRMCYk+E5U1UfyCeGvQ== X-Received: by 2002:a05:6512:443:: with SMTP id y3mr6781961lfk.166.1585555210629; Mon, 30 Mar 2020 01:00:10 -0700 (PDT) Received: from nol (82-64-124-11.subs.proxad.net. [82.64.124.11]) by smtp.gmail.com with ESMTPSA id m14sm7246779lfo.25.2020.03.30.01.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2020 01:00:10 -0700 (PDT) Date: Mon, 30 Mar 2020 10:00:05 +0200 From: Julien Rouhaud To: Masahiko Sawada Cc: Amit Kapila , Dilip Kumar , Robert Haas , PostgreSQL Hackers Subject: Re: pg_stat_statements issue with parallel maintenance (Was Re: WAL usage calculation patch) Message-ID: <20200330080005.GC79261@nol> References: <20200328133827.GA12854@nol> <20200328151721.GB12854@nol> 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: Precedence: bulk On Mon, Mar 30, 2020 at 04:01:18PM +0900, Masahiko Sawada wrote: > On Mon, 30 Mar 2020 at 15:46, Masahiko Sawada > wrote: > > > > On Sun, 29 Mar 2020 at 20:44, Masahiko Sawada > > wrote: > > > > > > > > > I think we need to change parallel maintenance commands so that they > > > > > > report buffer usage like what ParallelQueryMain() does; prepare to > > > > > > track buffer usage during query execution by > > > > > > InstrStartParallelQuery(), and report it by InstrEndParallelQuery() > > > > > > after parallel maintenance command. To report buffer usage of parallel > > > > > > maintenance command correctly, I'm thinking that we can (1) change > > > > > > parallel create index and parallel vacuum so that they prepare > > > > > > gathering buffer usage, or (2) have a common entry point for parallel > > > > > > maintenance commands that is responsible for gathering buffer usage > > > > > > and calling the entry functions for individual maintenance command. > > > > > > I'll investigate it more in depth. > > > > > > > > [...] > > > > I've attached two patches fixing this issue for parallel index > > creation and parallel vacuum. These approaches take the same approach; > > we allocate DSM to share buffer usage and the leader gathers them, > > described as approach (1) above. I think this is a straightforward > > approach for this issue. We can create a common entry point for > > parallel maintenance command that is responsible for gathering buffer > > usage as well as sharing query text etc. But it will accompany > > relatively big change and it might be overkill at this stage. We can > > discuss that and it will become an item for PG14. > > > > The patch for vacuum conflicts with recent changes in vacuum. So I've > attached rebased one. Thanks Sawada-san! Just minor nitpicking: + int i; Assert(!IsParallelWorker()); Assert(ParallelVacuumIsActive(lps)); @@ -2166,6 +2172,13 @@ lazy_parallel_vacuum_indexes(Relation *Irel, IndexBulkDeleteResult **stats, /* Wait for all vacuum workers to finish */ WaitForParallelWorkersToFinish(lps->pcxt); + /* + * Next, accumulate buffer usage. (This must wait for the workers to + * finish, or we might get incomplete data.) + */ + for (i = 0; i < nworkers; i++) + InstrAccumParallelQuery(&lps->buffer_usage[i]); We now allow declaring a variable in those loops, so it may be better to avoid declaring i outside the for scope? Other than that both patch looks good to me and a good fit for packpatching. I also did some testing on VACUUM and CREATE INDEX and it works as expected.