SQLSTATE 53400 ERROR Class 53: Insufficient Resources

configuration_limit_exceeded temporary file size exceeds temp_file_limit (N kB) — 53400

PostgreSQL error "temporary file size exceeds temp_file_limit (N kB)" (SQLSTATE 53400): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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_limit set 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

  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”.

Was this helpful?