I discovered that one can set the work_mem from PHP after connecting to the database and before issuing heavy requests :
<?php $conn = pg_connect("service=test"); // Set work_mem to 128MB $res = pg_query(sprintf("SET work_mem = '%s'", pg_escape_string('128MB'))); // Run your query $res = pg_query("SELECT * FROM your_heavy_request"); pg_close($conn); ?>
That allows you to set the work_mem depending on your requests without bothering the DBA 🙂