DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Developer Options

trace_sort

Emit information about resource usage in sorting.

  • Default: off
  • Type: bool
  • Applies: Session (any user)

In plain words

Turns on a running commentary for every sort: how much memory it was allowed, whether it fit in memory or had to spill to disk, and how long each phase took. Useful when you want to understand why a sort is slow or uses temp files.

For DBAs and operators

Unlike many developer options this one works in standard packaged builds. The messages are at LOG level, so they reach the server log, and the client too if client_min_messages = log. Captured on 18.6 sorting 20,000 integers:

LOG: begin datum sort: workMem = 4096, randomAccess = fLOG: performsort of worker -1 starting: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 sLOG: internal sort of worker -1 ended, 769 KB used: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s

workMem is work_mem in kB; "worker -1" is the leader (parallel workers number from 0). When the data does not fit you see external sort, the number of runs written and merge passes, which tells you how far off work_mem is. Index builds (CREATE INDEX) report their sorts too, using maintenance_work_mem.

For day-to-day tuning, EXPLAIN (ANALYZE) (Sort Method: external merge Disk: …) and log_temp_files are simpler; trace_sort is the detailed view.

How to change it

Any user can change it for their session with SET.

See it in context

Local (per-backend) memory Life of a query

Related parameters

work_mem maintenance_work_mem log_temp_files client_min_messages

All Developer Options parameters