Skip to content

Commit 6f36adf

Browse files
Update pg_long_running_transactions.go (#1092)
To extract time in seconds for pg_long_running_transactions_oldest_timestamp_seconds query which currently return epoch time. Signed-off-by: Jyothi Kiran Thammana <[email protected]>
1 parent a324fe3 commit 6f36adf

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: collector/pg_long_running_transactions.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ var (
5050
)
5151

5252
longRunningTransactionsQuery = `
53-
SELECT
54-
COUNT(*) as transactions,
55-
MAX(EXTRACT(EPOCH FROM clock_timestamp())) AS oldest_timestamp_seconds
56-
FROM pg_catalog.pg_stat_activity
57-
WHERE state is distinct from 'idle' AND query not like 'autovacuum:%'
53+
SELECT
54+
COUNT(*) as transactions,
55+
MAX(EXTRACT(EPOCH FROM clock_timestamp() - pg_stat_activity.xact_start)) AS oldest_timestamp_seconds
56+
FROM pg_catalog.pg_stat_activity
57+
WHERE state IS DISTINCT FROM 'idle'
58+
AND query NOT LIKE 'autovacuum:%'
59+
AND pg_stat_activity.xact_start IS NOT NULL;
5860
`
5961
)
6062

0 commit comments

Comments
 (0)