work_mem
How much memory a single sort or hash table may use before spilling to disk. The most misunderstood setting in PostgreSQL.
The misunderstanding is that the limit applies per query or per connection. It applies per operation: a query with three sorts and two hash joins can use five times the value, and running it with parallel workers multiplies that again. The 4 MB default means larger sorts fall back to an external merge algorithm against disk, which shows up as external merge Disk in EXPLAIN ANALYZE and can be orders of magnitude slower. The temptation is to raise it substantially at the global level, which combined with a hundred concurrent connections is a well-known way to get killed by the kernel's OOM handler. Keep it low globally and raise it per session for the queries that need it.