Skip to content

Commit

Permalink
send alert for transaction wraparound
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Jun 19, 2024
1 parent fc10de8 commit 502a01d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions migrate/20240619_lantern_doctor_queries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

Sequel.migration do
up do
# percent toward transaction wraparound
sql = <<SQL
SELECT 2000000000 as max_old_xid,
setting AS autovacuum_freeze_max_age
FROM pg_catalog.pg_settings
WHERE name = 'autovacuum_freeze_max_age')
, per_database_stats AS (
SELECT datname
, m.max_old_xid::int
, m.autovacuum_freeze_max_age::int
, age(d.datfrozenxid) AS oldest_current_xid
FROM pg_catalog.pg_database d
JOIN max_age m ON (true)
WHERE d.datallowconn )
SELECT max(ROUND(100*(oldest_current_xid/max_old_xid::float))) > 85 FROM per_database_stats;
SQL
DB[:lantern_doctor_query].insert(
id: "98cf148c-a88c-85b7-9bec-dbc912b022be",
name: "Percent towards tx wraparound is >85%",
db_name: "postgres",
schedule: "45 */10 * * *",
condition: "unknown",
sql: sql,
type: "system",
response_type: "bool",
severity: "warning"
)
end
end
1 change: 1 addition & 0 deletions model/lantern/lantern_doctor_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def check_disk_space_usage(_db, _query_user)
server_type = serv.primary? ? "primary" : "standby"
output += "#{server_type} server - usage #{usage_percent}%\n"
end
rescue
end
output.chomp
end
Expand Down

0 comments on commit 502a01d

Please sign in to comment.