I like the new approach, but doesn't `EXPLAIN (BUFFERS)` leak some memory because the resource owner isn't registered on that path? It seems to be visible with pg_log_backend_memory_contexts.
#define INSTR_BUFUSAGE_ADD(fld,val) do { \
- pgBufferUsage.fld += val; \
+ instr_stack.current->bufusage.fld += val; \
#define INSTR_WALUSAGE_ADD(fld,val) do { \
pgWalUsage.fld += val; \
+ instr_stack.current->walusage.fld += val; \
Nitpick, but these could use += (val)
