Skip to content

temp_file_limit

A per-process safety limit on disk space consumed at one time by executor temporary files.
Note

Fact — official short description: “Limits the total size of all temporary files used by each process.”

Identity

Type , Valueinteger
Upstream pg_settings type
Context , Valuesuperuser
Settable at runtime by a superuser
Unit , ValuekB
Raw unit
Range , Value-12147483647
Raw limits in the last observed version
Enum values , Value
— for non-enum types
Category , ValueResource Usage / Disk
Upstream classification
Latest boot value , Value-1
-1 kB

Lifecycle

Fact Value
First observed PG9.2
Present in PG9.2–19 Beta 3
Removed in No
Introduction commit 23e5b16c71f2 — Add temp_file_limit GUC parameter to constrain temporary file space usage.
Commit date 2011-07-17
Discussion

Default history

Measured PG9.0–19 Beta 3 boot defaults
Versions Raw boot_val Unit Human value
PG9.2–19 Beta 3 -1 kB -1 kB

How it works

temp_file_limit limits the total instantaneous size of temporary files owned by one PostgreSQL process, including sort and hash spill files and storage for held cursors. Exceeding it cancels the transaction.

The limit is per process, not cluster-wide, so concurrent backends and parallel workers can collectively consume multiples of it. The default -1 means no limit.

Explicit temporary-table storage is excluded from this limit. log_temp_files and pg_stat_database.temp_bytes observe related temporary-file activity but do not change the enforcement boundary.

Tuning advice

Tip

Advice. These are workload-specific starting points and must be validated with measurements.

Workload Guidance
OLTP Use a finite guardrail sized from filesystem headroom and worst-case concurrent spillers. Monitor temp_bytes and log_temp_files so the cap blocks pathological queries rather than routine bursts.
OLAP Allow a larger but still finite budget for known large joins and sorts, and coordinate it with query concurrency and parallelism. Test cancellation behavior before relying on the limit in production.
Small nodes Choose a modest fraction of the data filesystem and preserve emergency free space. Pair a lower limit with conservative work_mem and query timeouts.

Pigsty

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

Template Effective value Versus upstream boot Source expression
OLTP 5GB different {{ ([pg_size_twentieth, 200])|min }}GB
OLAP 20GB different {{ ([pg_size_twentieth * 4, 2000])|min }}GB
CRIT 5GB different {{ ([pg_size_twentieth, 200])|min }}GB
TINY 5GB different {{ ([pg_size_twentieth, 200])|min }}GB
Caution

Advice — pending human review. Fact from the current Pigsty template projection: OLTP: PG9.2–19 Beta 3 = 5GB (dcs); OLAP: PG9.2–19 Beta 3 = 20GB (dcs); CRIT: PG9.2–19 Beta 3 = 5GB (dcs); TINY: PG9.2–19 Beta 3 = 5GB (dcs). Advice, pending human review — Editorial inference: these values act as process-level circuit breakers while giving analytical spills more room; aggregate multi-process exposure still needs capacity review.

Common pitfalls

  • Treating a per-process limit as a cluster-wide disk cap.
  • Expecting it to constrain explicit temporary tables, which are excluded.
  • Leaving -1 on a filesystem where one runaway query can exhaust shared storage.
  • Setting the cap below normal spill sizes and discovering through transaction cancellations.

work_mem · hash_mem_multiplier · log_temp_files · temp_tablespaces · max_parallel_workers_per_gather

References