temporary file size exceeds temp_file_limit (N kB)

SQLSTATE 53400 condition configuration_limit_exceeded class 53 — Insufficient Resources severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A query’s temporary files exceeded the configured temp_file_limit. PostgreSQL aborts the query with SQLSTATE 53400 (configuration_limit_exceeded).

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

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

  1. Optimize the query to process less data (better filters/indexes/joins).
  2. Raise temp_file_limit if the workload legitimately needs more temp space.
  3. Increase work_mem for the session to reduce spilling.

Related & next steps

Reference: PostgreSQL 18 Section 20.4 “Resource Consumption”.