- No built-in routine or extension is there to show aggregation of work_mem for any query, as it is dynamically allocated. - If work_mem requirement exceeds then it spills to disk, which can be monitored through logs. Use log_temp_files and log_statement_stats to see temp files, their size may give clues. - pg_stat_statements and pg_stat_activity may also help in getting an idea about which queries are taking more time and their consumption of shared blocks etc.
Is there any statistics table or view in the PostgreSQL catalog, extension, or similar that collects and displays work_mem memory usage statistics? It would be interesting to know the use of the work_mem by user, application and/or database.