Manually trigger "Write current results to disk" during query
No, PostgreSQL does not keep transactions in progress cached in memory. They are written to disk as usual.

All that happens at commit time is that the write ahead log (WAL) and the commit log are flushed to disk.

So you must investigate further to find the cause for your I/O overload.

Useful lines of investigation are:


use pg_stat_statements with pg_stat_statements.track = all to find the SQL statements that cause the load.
set track_io_timing = on to see which queries contribute most to the I/O load.
check if each function call runs in a separate transaction or not.

If yes, bundle several calls in a single transaction - perhaps the many WAL flushes are killing you.