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 1k60lO-0005g4-SA for pgsql-general@arkaria.postgresql.org; Thu, 13 Aug 2020 00:06:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k60lN-0001BN-3e for pgsql-general@arkaria.postgresql.org; Thu, 13 Aug 2020 00:06:33 +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 1k60lM-0001BG-SB for pgsql-general@lists.postgresql.org; Thu, 13 Aug 2020 00:06:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k60lG-0008N8-NH for pgsql-general@lists.postgresql.org; Thu, 13 Aug 2020 00:06:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 07D06O1p328868; Wed, 12 Aug 2020 20:06:24 -0400 From: Tom Lane To: Ayub M cc: pgsql-general@lists.postgresql.org Subject: Re: hash joins are causing no space left error In-reply-to: References: Comments: In-reply-to Ayub M message dated "Wed, 12 Aug 2020 19:52:11 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <328866.1597277184.1@sss.pgh.pa.us> Date: Wed, 12 Aug 2020 20:06:24 -0400 Message-ID: <328867.1597277184@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ayub M writes: > This is PostgreSQL 11 on AWS, there is a mview query in this OLAP database, > the tables involved are huge - 50-100m records on average records hundreds > of columns in most cases. The query runs for a while and then errors out > saying "No space left on device". I could see it generating around 500gb of > temp file data. At times it goes thru and at times it fails - probably due > to other queries running at the same time and causing failure. Are you sure that these queries are actually producing the answers you want? It sounds suspiciously like you are computing underconstrained joins. > The joins are happening on around 10 tables and all are joining on the PK > and FK columns. I see partition pruning happening but the hash joins are > killing the query. > Is there any way to avoid hash joins? TBH, you are asking the wrong question. A merge join would take about as much temporary space, and a nestloop join over so much data would probably not finish in an amount of time you're willing to wait. Indexes are NOT a magic solution here. What you need to be thinking about is how to not need to process so much data. If you really need to have this proven to you, you can try "set enable_hashjoin = off", but I don't think you'll find that better. regards, tom lane