Hi Alex,
> pg_locks.waitstart already provides this information. Any reason that
> is not sufficient?
I agree with Sami here. A backend waits on at most one lock at a time,
so a view on your side gives you the same thing today:
CREATE VIEW my_activity AS
SELECT a.*, l.waitstart AS lock_wait_start
FROM pg_stat_activity a
LEFT JOIN pg_locks l ON l.pid = a.pid AND NOT l.granted;
The only thing that view cannot give you is avoiding the lock manager
scan pg_locks does on every read. I do not think that is an issue
unless something queries the view very often, like a monitoring agent
sampling every second. If that is your case, please show numbers for
it. That is the case the patch would need to make.
Thanks,
Shihao