agora inbox for pgsql-admin@postgresql.org  
help / color / mirror / Atom feed
From: Paul Smith* <paul@pscs.co.uk>
To: pgsql-admin@lists.postgresql.org
Subject: Re: small temp files
Date: Mon, 22 Jul 2024 14:34:09 +0100
Message-ID: <fe4b82fa-9907-43f9-b6ff-e1cbc768158d@pscs.co.uk> (raw)
In-Reply-To: <8E03B792-C389-456D-913D-4F2B0EBB903E@elevated-dev.com>
References: <7A0C9A69-5632-4CFC-B156-53FAAAB33E26@elevated-dev.com>
	<a9dee6e8-6197-d9bb-028e-6d020167bf57@jakobs.com>
	<8E03B792-C389-456D-913D-4F2B0EBB903E@elevated-dev.com>

On 22/07/2024 14:28, Scott Ribe wrote:
> I understand those things--my question is why, with work_mem set to 128MB, I would see tiny temp files (7452 is common, as is 102, and I've seen as small as 51).
>
 From the manual:

"Note that a complex query might perform several sort and hash 
operations at the same time, with each operation generally being allowed 
to use as much memory as this value specifies before it starts to write 
data into temporary files. Also, several running sessions could be doing 
such operations concurrently. Therefore, the total memory used could be 
many times the value of|work_mem|; it is necessary to keep this fact in 
mind when choosing the value. Sort operations are used for|ORDER 
BY|,|DISTINCT|, and merge joins. Hash tables are used in hash joins, 
hash-based aggregation, memoize nodes and hash-based processing 
of|IN|subqueries."

So, if it's doing lots of joins, there may be lots of bits of temporary 
data which together add up to more than work_mem. AIUI PostgreSQL 
doesn't necessarily shove all the temporary data for one query into one 
file, it may have multiple smaller files for the data for a single query.

view thread (8+ messages)  latest in thread

Message-ID: <fe4b82fa-9907-43f9-b6ff-e1cbc768158d@pscs.co.uk>
Permalink:  ../fe4b82fa-9907-43f9-b6ff-e1cbc768158d@pscs.co.uk/
Also on:    postgresql.org/message-id/fe4b82fa-9907-43f9-b6ff-e1cbc768158d@pscs.co.uk

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: paul@pscs.co.uk, pgsql-admin@lists.postgresql.org
  Subject: Re: small temp files
  In-Reply-To: <fe4b82fa-9907-43f9-b6ff-e1cbc768158d@pscs.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox