Been using pg_stat_statements forever. Today I wanted to reset just the stats for a background job user so I could measure a new version’s impact, without losing the baseline for the API user.

SELECT pg_stat_statements_reset(
  (SELECT oid FROM pg_roles WHERE rolname = 'bg_worker')
);

You can also reset stats for a specific database or a specific queryid:

SELECT pg_stat_statements_reset(userid, dbid, queryid);

Where 0 means “all.” So pg_stat_statements_reset(0, 0, 0) is the full reset, which is what the bare pg_stat_statements_reset() does.

The docs technically cover this but I’d read “reset all stats” enough times to not realize it could be targeted. Saved me a lot of “let me just remeasure everything from scratch” pain today.