Skip to content

Commit

Permalink
Fix the oldest query display
Browse files Browse the repository at this point in the history
It didn't take into account whether the session was idle, so it was
inaccurate

Also add some workaround for issue powa-team/powa-archivist#98
until the archivist is fixed
  • Loading branch information
marco44 committed Feb 7, 2025
1 parent 55e8b54 commit c0a541f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions powa/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,14 @@ def _get_metrics(cls, handler, **params):
@property
def query(self):
query = powa_get_pgsa_sample(per_db=True)

# Those greatests are to avoid having negative values returned, see https://github.com/powa-team/powa-archivist/issues/98
cols = [
"extract(epoch FROM ts) AS ts",
"max(backend_xid_age) AS backend_xid_age",
"max(backend_xmin_age) AS backend_xmin_age",
"max(backend_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_backend",
"max(xact_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_xact",
"max(query_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_query",
"greatest(max(backend_xid_age),0) AS backend_xid_age",
"greatest(max(backend_xmin_age),0) AS backend_xmin_age",
"greatest(max(backend_start_age) FILTER (WHERE datid IS NOT NULL),0) AS oldest_backend",
"greatest(max(xact_start_age) FILTER (WHERE datid IS NOT NULL),0) AS oldest_xact",
"greatest(max(query_start_age) FILTER (WHERE datid IS NOT NULL AND state !~ 'idle'),0) AS oldest_query",
"count(*) FILTER (WHERE state = 'idle') AS nb_idle",
"count(*) FILTER (WHERE state = 'active') AS nb_active",
"count(*) FILTER (WHERE state = 'idle in transaction') AS nb_idle_xact",
Expand Down
12 changes: 6 additions & 6 deletions powa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,14 @@ def _get_metrics(cls, handler, **params):
@property
def query(self):
query = powa_get_pgsa_sample()

# Those greatests are to avoid having negative values returned, see https://github.com/powa-team/powa-archivist/issues/98
cols = [
"extract(epoch FROM ts) AS ts",
"max(backend_xid_age) AS backend_xid_age",
"max(backend_xmin_age) AS backend_xmin_age",
"max(backend_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_backend",
"max(xact_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_xact",
"max(query_start_age) FILTER (WHERE datid IS NOT NULL) AS oldest_query",
"greatest(max(backend_xid_age),0) AS backend_xid_age",
"greatest(max(backend_xmin_age),0) AS backend_xmin_age",
"greatest(max(backend_start_age) FILTER (WHERE datid IS NOT NULL),0) AS oldest_backend",
"greatest(max(xact_start_age) FILTER (WHERE datid IS NOT NULL),0) AS oldest_xact",
"greatest(max(query_start_age) FILTER (WHERE datid IS NOT NULL AND state !~ 'idle'),0) AS oldest_query",
"count(*) FILTER (WHERE state = 'idle') AS nb_idle",
"count(*) FILTER (WHERE state = 'active') AS nb_active",
"count(*) FILTER (WHERE state = 'idle in transaction') AS nb_idle_xact",
Expand Down

0 comments on commit c0a541f

Please sign in to comment.