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 1lvf5E-0000eW-Rp for pgsql-admin@arkaria.postgresql.org; Tue, 22 Jun 2021 12:00:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvf5D-0007ue-I6 for pgsql-admin@arkaria.postgresql.org; Tue, 22 Jun 2021 12:00:47 +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 1lvf5D-0007uV-98 for pgsql-admin@lists.postgresql.org; Tue, 22 Jun 2021 12:00:47 +0000 Received: from mout.perfora.net ([74.208.4.194]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvf59-0007tt-G2 for pgsql-admin@lists.postgresql.org; Tue, 22 Jun 2021 12:00:46 +0000 Received: from [192.168.1.165] ([72.205.28.227]) by mrelay.perfora.net (mreueus004 [74.208.5.2]) with ESMTPSA (Nemesis) id 1M5x4x-1ltjPY1zHH-007U87; Tue, 22 Jun 2021 14:00:39 +0200 Subject: Re: Temp files for simple queries To: Julien Rouhaud Cc: "Radoulov, Dimitre" , pgsql-admin@lists.postgresql.org References: <45cc44dd-b830-5df5-1f09-171e9874bbc0@gmail.com> <16aa733d-bcaf-0aa6-f3f0-5206de695e92@gmail.com> <20210622115506.o2u4u5krplxxc54k@nol> From: MichaelDBA Message-ID: <6fab4381-4a47-0b99-43a9-1ff1c97efd39@sqlexec.com> Date: Tue, 22 Jun 2021 08:00:37 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 PostboxApp/7.0.48 MIME-Version: 1.0 In-Reply-To: <20210622115506.o2u4u5krplxxc54k@nol> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Provags-ID: V03:K1:Hof128sDmDOIZ2nLbRUfwPChhjLKUbD3f+KBqiYkVo4BScwKohp GAw1oV3UkdWh+gOnRl3Wt76h+BBUW9lKSsBYDQURJU8TxwQy8sWLBme0vJ6cwiPLP14yVet t6Mxt2RO8HO4vnpCrOxnF47Ed/mHEz640BJIzOoI5xa4uUd7Vw33TiEVbuFOqFfh/jMTsBZ BaRpVO39gaL7tXBsK33Iw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:8FF+27oqkdU=:04oO6X9+J6o3rnry80Jxkn 4aDatDuPbb/Kfa+YggUFz+K3zxEJHs/g5GMxR7CFLVtCQhqDRkfT4+gnR+cNxZWKbM3Vc+82j n/NOnOqogwzEvuGwIJkjxWJxb6czM+GbqNy6X8y7odank9vXsNjCRX5y9Do2Ga4zyixabgUlN HsmB2E6UMpgME8nwvSNIQdh6U/BQyYcm5qVIE7ClgjMQ5J8zKVTBsjEI9m6q/ZDFxQ6jXD6xH F5+3nLtX7cMcFDujIN3Fivg8G8cjc9lO0Wsoj0/ET2lc7XSJWGB9StARDZf6TTn4xUZXHnKVn 0JILeEtYjxIhrYibeVBFXSq760uQzrYSVkzDyjiZY82mH+Of8g8etHnv+cDF06y6wTC33yZsz mkdo1ntacz9bIit69GKwaCQhVFaf9/wcsJ7+7cCdaPLW7i1xEPiqmyosmp6N8PwU39HufoJc2 ewqeVsU2ZYVAWPf0omURBcyKxqTjELSjY5lYcj9KKJHGl/BMkAIo1hNlR98PnLtw2CtxMBnhN gSHXgHqr+KgvshAkdtH8RM= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I'm wondering if bloat could be causing a problem.  Perhaps more blocks are written to disk including a lot of blocks with little or no data due to bloat. Julien Rouhaud wrote on 6/22/2021 7:55 AM: > On Tue, Jun 22, 2021 at 01:51:55PM +0200, Radoulov, Dimitre wrote: >> Just to clarify: the size of the temp file is 7MB and with work_mem of 4MB >> it clearly doesn't fit. >> >> But why an "order by" of a 440kB of data would require 7MB. >> >> One possible reason is that that the number of records in that table varies >> significantly during the day, > That would be the logical explanation. You could configure auto_explain to > make sure of that (https://www.postgresql.org/docs/current/auto-explain.html). > >> but - if that's the case - I would expect that >> the table would be much bigger than 440kB (size taken using \dt+). > Not necessarily. autovacuum can truncate the file if all the trailing blocks > are empty (and if it can acquire an exclusive lock fast enough), so if some > client inserts a lot of rows, process them and remove them all, and later on > slowly start to insert new rows you will get that behavior. > >