From: "Soroosh Sardari" <soroosh.sardari@gmail.com>
> I wonder if anyone could help me to find the module of pg that is
> responsible for the temporal space and external sort in the PG source
> code.
See src/backend/utils/sort/ for sort implementation.
That uses BufFile in src/backend/storage/file/buffile.c,
which in turn uses OpenTemporaryFile in src/backend/storage/file/fd.c.
Regards
MauMau