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 1p6DEl-0004Eg-Rm for pgsql-performance@arkaria.postgresql.org; Fri, 16 Dec 2022 16:07:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p6DEk-0003q1-Oo for pgsql-performance@arkaria.postgresql.org; Fri, 16 Dec 2022 16:07:02 +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 1p6DEk-0003lp-Bd for pgsql-performance@lists.postgresql.org; Fri, 16 Dec 2022 16:07:02 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p6DEg-0005tI-6v for pgsql-performance@lists.postgresql.org; Fri, 16 Dec 2022 16:07:01 +0000 Received: by mail-il1-x136.google.com with SMTP id m15so1466699ilq.2 for ; Fri, 16 Dec 2022 08:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=I2YtPGPf1ZjM9QNlUgkJp4ieE5S5guytmI5fs45t3Hc=; b=2cQ4zjco4fqE4S96zu4RXzmWe2vRNnz7P5CunbS/B8uufsSUlRzDwP9ANY4Is8th+h eSytGXadCtgfVvaXh4hmwkL+d+eUodalkSlfiExjhY51P4vuQkmtxOkp9nGr8ytrNCki RFN9FXowmEs1uqRsvWLMydHaD3+tddxvzVxOMIkA4VEIm4zGsmG3KPUaY8uBrFlqEfD/ U8wkL63CK+qWDnXhp+pNhMhgQ5ETT/DJ0e7C2BLXpJ6LlLaYvAPXWAdrA/X90Yn1MulZ CaF5I2q1L9vNQUg9gjk+t9QTE+UHtux9GCbDq3p2hUch6os4vp9xNlQ+ycQ5tfwVJj+N tHRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :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=I2YtPGPf1ZjM9QNlUgkJp4ieE5S5guytmI5fs45t3Hc=; b=s1gmj3vJXnfpRaRqAyxqm/5+FkiDYOZUe3VmQiyXIDBLGg03pwpp2Kk7QUF41+QSt6 FiRPBB0gyL5I4k6wsv0W0Rat8Pg6EVbiebXCyqgTCwM6hPCyi4La8+PmqrpEs9lW92OD DfAj8Of+XtT9PplTk95jWtEmPBKdr/ajcrxbXEEcZQG8r5mc5Ke1GOEsUzb5YAImitNG jVnPdzo/KThDbK5O+5qmXddeTCR8x/YaoswOaWv1kWu05UV/yKrJEHrWyeEIccqr3Cjy aL+QFXSkGZPAVsMYbmTvO9LlYltnYnZQTpKpCKPaN8lVW8I7XVBxNx3Y+T2na42XQQwp +Tng== X-Gm-Message-State: ANoB5pkYNwMgigiRV+va9TANS8K3h0CADrdqzqJG1ywwiTiPRH2U6itZ 9dvKkDuzxKYarpoJ8qWaCrGyd7rIOchJKVqd X-Google-Smtp-Source: AA0mqf7fVgEKfjoccMxlFvhneo5GKH+QDWfZ746nszLjH+493uZtWG8Z5+NXbcYPzLZc0d/7iahMMQ== X-Received: by 2002:a92:ccc4:0:b0:302:ccd6:5550 with SMTP id u4-20020a92ccc4000000b00302ccd65550mr19120048ilq.21.1671206817424; Fri, 16 Dec 2022 08:06:57 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id p14-20020a056638216e00b00363da904602sm861009jak.13.2022.12.16.08.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 08:06:56 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id E7D7D800656; Fri, 16 Dec 2022 10:06:55 -0600 (CST) Date: Fri, 16 Dec 2022 10:06:55 -0600 From: Justin Pryzby To: =?iso-8859-1?Q?Jo=E3o_Paulo_Lu=EDs?= Cc: pgsql-performance@lists.postgresql.org Subject: Re: Postgres12 looking for possible HashAggregate issue workarounds? Message-ID: <20221216160655.GQ1153@telsasoft.com> References: <21468a50-0684-4482-8f4d-d01b1f08021b.4e1a2d27-b57e-4ab1-b752-eaba6c32bb5b.359beaa8-9ef0-413f-a9b8-a521522bf026@emailsignatures365.codetwo.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: Archived-At: Precedence: bulk On Fri, Dec 16, 2022 at 03:24:17PM +0000, João Paulo Luís wrote: > Hi! Sorry to post to this mailing list, but I could not find many tips working around HashAggregate issues. > > In a research project involving text repetition analysis (on top of public documents) > I have a VirtualMachine (CPU AMD Epyc 7502P, 128GB RAM, 12TB HDD, 2TB SSD), > running postgres 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1) > and some tables with many rows: > 1 - the query is making a postgresql project have 76.7 GB resident RAM usage. > Having a WORK_MEM setting of 2GB (and "simple" COUNT() results), > that was not expected. > (I risk oom-killer killing my postgres as soon as I run another concurrent > query.) > The rows=261275 on HashAggregate (cost=26397219.92..26399832.67 rows=261275 width=8) seems VERY WRONG! > I was expecting something like rows=1.0E+09 instead. > I would guess that HashAggregate is behaving very badly (using to much RAM beyond WORK_MEM, amd also badly estimating the #rows and taking forever...) Huge memory use sounds like what was fixed in postgres 13. https://www.postgresql.org/docs/13/release-13.html Allow hash aggregation to use disk storage for large aggregation result sets (Jeff Davis) Previously, hash aggregation was avoided if it was expected to use more than work_mem memory. Now, a hash aggregation plan can be chosen despite that. The hash table will be spilled to disk if it exceeds work_mem times hash_mem_multiplier. This behavior is normally preferable to the old behavior, in which once hash aggregation had been chosen, the hash table would be kept in memory no matter how large it got — which could be very large if the planner had misestimated. If necessary, behavior similar to that can be obtained by increasing hash_mem_multiplier. -- Justin