Diagnostic Queries
Symptoms
A query’s temporary files exceeded the configured temp_file_limit. PostgreSQL aborts the query with SQLSTATE 53400 (configuration_limit_exceeded).
- A spill-to-disk operation grew past temp_file_limit.
- Common with large sorts, hashes, or CTEs.
- The limit is a safety valve against runaway temp usage.
What the server log shows
ERROR: temporary file size exceeds temp_file_limit (5242880 kB)
Why PostgreSQL raises this — what the manual says
Section 19.4.2 Disk (temp_file_limit):
“A transaction attempting to exceed this limit will be canceled.”
When an operation cannot fit in work_mem, PostgreSQL spills to temporary files. If their total size exceeds temp_file_limit, the query is cancelled with 53400 to protect disk space.
Common causes
- A huge sort/hash/aggregate spilling massive temp data.
temp_file_limitset conservatively.- A query processing far more data than expected (bad plan or missing filter).
Relevant GUC parameters
| Parameter | Default | Effect |
|---|---|---|
temp_file_limit |
-1 | Per-process cap on temp file space; -1 means unlimited. |
work_mem |
4MB | Higher values reduce spilling, lowering temp file usage. |
How to fix it
- Optimize the query to process less data (better filters/indexes/joins).
- Raise
temp_file_limitif the workload legitimately needs more temp space. - Increase
work_memfor the session to reduce spilling.
Related & next steps
Reference: PostgreSQL 18 Section 20.4 “Resource Consumption”.
Thanks — noted. This helps keep the database accurate.