Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Locks by user? #51

Open
contentfree opened this issue Mar 17, 2023 · 4 comments
Open

Locks by user? #51

contentfree opened this issue Mar 17, 2023 · 4 comments

Comments

@contentfree
Copy link

It would be very useful to see metrics on locks by mode and user. (Trying to find out who's responsible for a bunch of DB contention…)

Is that possible?

@lesovsky
Copy link
Owner

It's possible, but... is that matter?

pg_locks contains stats like gauges, and stats collected from pg_locks (and pg_stat_activity btw) are "lossy" by design. The view shows a snapshot and taking such snapshots (metrics) it's unknown what was between two snapshots. Of course, we can take more snapshots, but this doesn't solve the problem - only long locks will be captured and lots of shorts locks stay invisible.

The second, pg_locks doesn't contain user attribute, pg_stat_activity have to be joined (which could potentially increase (but not too much) performance impact on instances with high number of connections and activity).

Will add the user label, but can't promise when.

@contentfree
Copy link
Author

contentfree commented Mar 17, 2023 via email

@lesovsky
Copy link
Owner

lesovsky commented Mar 18, 2023

We have multiple components
sharing a database and trying to figure out which one (or two or…) are
experiencing the locks.

In such case try to enable log_lock_waits in server configuration, it automatically logs all locks higher than deadlock_timeout (default 1s). From one side it could increase amount of logs (if there too many locks occur), but from other side you get comprehensive logs collected by Postgres itself instead of Prometheus 10s-15s scraping. And all you need then, is analyze postgres logs.

@contentfree
Copy link
Author

contentfree commented Mar 18, 2023 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants