Give a “super” user more work_mem
You have a few possibilities.

To change work_mem for a user is easy:

ALTER ROLE alice SET work_mem TO '5GB';


If you can arrange things like alice is the user running those heavy queries, this might be enough.  If this number is huge (a significant portion of the RAM you have on your server), it makes sense to limit the user to have only a small number of connections (even 1 might make sense) at any time:

ALTER ROLE alice WITH CONNECTION LIMIT 2;


If this is not feasible, you can store your queries as functions.  The advantage of this is that you can set chosen parameters when defining the function, or after it:

ALTER FUNCTION heavy(integer) SET work_mem TO '2GB';
ALTER FUNCTION very_heavy(integer) SET work_mem TO '13GB';