Skip to content

Commit

Permalink
Lower the default long transaction threshold from 1 hour to 5 minutes (
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel committed Feb 7, 2020
1 parent 1bf5902 commit e3bb056
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# postgres-vacuum-monitor
## v.0.5.0
## v.0.7.0
- Lower the default `LongTransactions` threshold from 1 hour to 5 minutes and make this configurable via
the `long_running_transaction_threshold_seconds` setting.

## v.0.6.0
- Add `wait_event_type`, `transaction_id` and `min_transaction_id` to `LongTransactions` events.

## v.0.5.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The job itself needs a class to report the information and can be configured by
```ruby
Postgres::Vacuum::Monitor.configure do |config|
config.monitor_reporter_class_name = 'MetricsReporter'
# Optionally change the default threshold of 5 minutes for reporting long running transactions
config.long_running_transaction_threshold_seconds = 10 * 60
end
```

Expand Down
6 changes: 4 additions & 2 deletions lib/postgres/vacuum/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module Postgres
module Vacuum
class Configuration
attr_accessor :monitor_reporter_class_name
DEFAULT_LONG_RUNNING_TRANSACTION_THRESHOLD_SECONDS = 5 * 60
attr_accessor :monitor_reporter_class_name, :long_running_transaction_threshold_seconds

def initialize
@monitor_reporter_class_name = nil
self.monitor_reporter_class_name = nil
self.long_running_transaction_threshold_seconds = DEFAULT_LONG_RUNNING_TRANSACTION_THRESHOLD_SECONDS
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/postgres/vacuum/monitor/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Query
extend self

STATES = ["'idle in transaction'", "'active'"].freeze
TIME_LIMIT = 3600
THRESHOLD_SETTING = "'autovacuum_vacuum_threshold'".freeze
SCALE_FACTOR_SETTING = "'autovacuum_vacuum_scale_factor'".freeze
MAX_AGE_SETTING = "'autovacuum_freeze_max_age'".freeze
Expand All @@ -29,7 +28,7 @@ def long_running_transactions
WHERE state IN (#{STATES.join(', ')})
ORDER BY seconds DESC
) AS long_queries
WHERE seconds > #{TIME_LIMIT};
WHERE seconds > #{Postgres::Vacuum::Monitor.configuration.long_running_transaction_threshold_seconds};
SQL
end

Expand Down
2 changes: 1 addition & 1 deletion lib/postgres/vacuum/monitor/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Postgres
module Vacuum
module Monitor
VERSION = '0.6.0'.freeze
VERSION = '0.7.0'.freeze
end
end
end
2 changes: 1 addition & 1 deletion spec/postgres/vacuum/monitor/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ".long_query" do
it "respects the time window" do
expect(Postgres::Vacuum::Monitor::Query.long_running_transactions).to include "seconds > #{Postgres::Vacuum::Monitor::Query::TIME_LIMIT}"
expect(Postgres::Vacuum::Monitor::Query.long_running_transactions).to include "seconds > #{Postgres::Vacuum::Monitor.configuration.long_running_transaction_threshold_seconds}"
end

it "respects the states" do
Expand Down

0 comments on commit e3bb056

Please sign in to comment.