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 1lIIwE-0005rP-44 for pgsql-general@arkaria.postgresql.org; Fri, 05 Mar 2021 22:28:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lIIwC-0008E6-U0 for pgsql-general@arkaria.postgresql.org; Fri, 05 Mar 2021 22:28:48 +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 1lIIwC-0008Dz-M6 for pgsql-general@lists.postgresql.org; Fri, 05 Mar 2021 22:28:48 +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 1lIIw6-0002kV-Bl for pgsql-general@postgresql.org; Fri, 05 Mar 2021 22:28:47 +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 125MSeWZ1517659; Fri, 5 Mar 2021 17:28:40 -0500 From: Tom Lane To: Jeremy Finzel cc: Postgres General Subject: Re: Unkillable processes creating millions of tiny temp files In-reply-to: References: Comments: In-reply-to Jeremy Finzel message dated "Fri, 05 Mar 2021 15:34:37 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1517657.1614983320.1@sss.pgh.pa.us> Date: Fri, 05 Mar 2021 17:28:40 -0500 Message-ID: <1517658.1614983320@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jeremy Finzel writes: > We are running postgres 11.9 (were running 11.7 prior to recent restart) on > a large db (10s of TB) with 5 or 6 tablespaces and 1000s of tables/indexes. > Within the past few days we have started to see a few queries running for > over 8 hours which we then attempt to terminate, but will not terminate. > These queries are also generating hundreds of thousands of tiny/empty temp > files. In fact, before the restart there were over 23 million files in > pg_tmp which were removed. We also have verified no server settings have > changed for at least a couple weeks, well before this issue started > happening only in the past few days. Hm. For the query plan you show, I think the only plausible explanation for using temp files is that a hash join's hash table is exceeding work_mem so it's spilling batches of tuples to disk. With some bad luck those could be small not large. But I don't see anything in our commit logs between 11.7 and 11.9 that looks like it would have affected any of that behavior. (There were some changes to code governing temp-file tablespace selection, but that could only affect where the files get put not how big they are.) So I doubt that this can be blamed on the update, especially since if I read you correctly it didn't start happening immediately after the update. I'm wondering about changes in table statistics possibly causing a poorly-chosen change in the hashing parameters. What have you got work_mem set to? Can you comment on whether the estimated rowcounts shown in the query plan are accurate? Does manually ANALYZE'ing the tables used in the query change anything? The "unkillable" aspect is odd, but I wonder if that's just a red herring. A query that's generated lots of temp files will try to clean them up at termination, so maybe the backend is just sitting there removing temp files before it'll give control back. regards, tom lane