pghero 2.5.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pghero might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e147c844a9c109baa794e9a3950e747539e2b15f19b781e9822edaed5f216ff
4
- data.tar.gz: e18d81b6876148607514621d96b7b84f9436081f7eb4660008cbf3148578bbe5
3
+ metadata.gz: e7334e516c44c91605f37b8fd22b57a46b147cfe4191796e48624e8a15b45ca0
4
+ data.tar.gz: 1235c0626b5a7f2061f2bcfce062d4716f3de7a5c198aeed489eaf9d0c7549c0
5
5
  SHA512:
6
- metadata.gz: 1eea90a86822be5ee51a1b0b34e5e86297909a6bb41d4cf6589162285b8d2414b63c119cfba7d4df5b6f78d0b755ff517b47420c1ddd27a0cadcc51f0305f465
7
- data.tar.gz: afc7bb09d979dada5636a8056ae1d692b88d8fc0cfda0af8d81f02a4a413499027953c4506c7a627da27c5c9b9f87aca1c030d76a0caa758773c6483c4ac171a
6
+ metadata.gz: 52944fa0d91437a0fd42dc4e8705a4f833a3d60937748f1cbffd03aa9471af8ce2e30db7645c419590696dcbbe0e700941b838216ae3da7a5bc211f0067188a5
7
+ data.tar.gz: 8ff19581f7245ebc804ef49af131c9f6eca5ed8110b878ccb8e1b15cf94c2951d88e4329e1565145e03b21c63e3798be400dc74b2655c7489dca75ba9ca4aec5
@@ -1,3 +1,8 @@
1
+ ## 2.6.0 (2020-07-09)
2
+
3
+ - Added support for Postgres 13 beta 2
4
+ - Added support for non-integer explain timeout
5
+
1
6
  ## 2.5.1 (2020-06-23)
2
7
 
3
8
  - Added support for `google-cloud-monitoring` >= 1
@@ -43,7 +43,7 @@ module PgHero
43
43
  self.long_running_query_sec = (ENV["PGHERO_LONG_RUNNING_QUERY_SEC"] || 60).to_i
44
44
  self.slow_query_ms = (ENV["PGHERO_SLOW_QUERY_MS"] || 20).to_i
45
45
  self.slow_query_calls = (ENV["PGHERO_SLOW_QUERY_CALLS"] || 100).to_i
46
- self.explain_timeout_sec = (ENV["PGHERO_EXPLAIN_TIMEOUT_SEC"] || 10).to_i
46
+ self.explain_timeout_sec = (ENV["PGHERO_EXPLAIN_TIMEOUT_SEC"] || 10).to_f
47
47
  self.total_connections_threshold = (ENV["PGHERO_TOTAL_CONNECTIONS_THRESHOLD"] || 500).to_i
48
48
  self.cache_hit_rate_threshold = 99
49
49
  self.env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
@@ -55,15 +55,16 @@ module PgHero
55
55
  end
56
56
 
57
57
  def explain_timeout_sec
58
- (config["explain_timeout_sec"] || PgHero.config["explain_timeout_sec"] || PgHero.explain_timeout_sec).to_i
58
+ (config["explain_timeout_sec"] || PgHero.config["explain_timeout_sec"] || PgHero.explain_timeout_sec).to_f
59
59
  end
60
60
 
61
61
  def long_running_query_sec
62
62
  (config["long_running_query_sec"] || PgHero.config["long_running_query_sec"] || PgHero.long_running_query_sec).to_i
63
63
  end
64
64
 
65
+ # defaults to 100 megabytes
65
66
  def index_bloat_bytes
66
- (config["index_bloat_bytes"] || PgHero.config["index_bloat_bytes"] || 100.megabytes).to_i
67
+ (config["index_bloat_bytes"] || PgHero.config["index_bloat_bytes"] || 104857600).to_i
67
68
  end
68
69
 
69
70
  def aws_access_key_id
@@ -6,7 +6,7 @@ module PgHero
6
6
  explanation = nil
7
7
 
8
8
  # use transaction for safety
9
- with_transaction(statement_timeout: (explain_timeout_sec * 1000), rollback: true) do
9
+ with_transaction(statement_timeout: (explain_timeout_sec * 1000).round, rollback: true) do
10
10
  if (sql.sub(/;\z/, "").include?(";") || sql.upcase.include?("COMMIT")) && !explain_safe?
11
11
  raise ActiveRecord::StatementInvalid, "Unsafe statement"
12
12
  end
@@ -166,14 +166,15 @@ module PgHero
166
166
  if query_stats_enabled?
167
167
  limit ||= 100
168
168
  sort ||= "total_minutes"
169
+ total_time = server_version_num >= 130000 ? "(total_plan_time + total_exec_time)" : "total_time"
169
170
  query = <<-SQL
170
171
  WITH query_stats AS (
171
172
  SELECT
172
173
  LEFT(query, 10000) AS query,
173
174
  #{supports_query_hash? ? "queryid" : "md5(query)"} AS query_hash,
174
175
  rolname AS user,
175
- (total_time / 1000 / 60) AS total_minutes,
176
- (total_time / calls) AS average_time,
176
+ (#{total_time} / 1000 / 60) AS total_minutes,
177
+ (#{total_time} / calls) AS average_time,
177
178
  calls
178
179
  FROM
179
180
  pg_stat_statements
@@ -182,6 +183,7 @@ module PgHero
182
183
  INNER JOIN
183
184
  pg_roles ON pg_roles.oid = pg_stat_statements.userid
184
185
  WHERE
186
+ calls > 0 AND
185
187
  pg_database.datname = #{database ? quote(database) : "current_database()"}
186
188
  #{query_hash ? "AND queryid = #{quote(query_hash)}" : nil}
187
189
  )
@@ -1,6 +1,8 @@
1
1
  module PgHero
2
2
  module Methods
3
3
  module Users
4
+ # documented as unsafe to pass user input
5
+ # TODO quote in 3.0, but still not officially supported
4
6
  def create_user(user, password: nil, schema: "public", database: nil, readonly: false, tables: nil)
5
7
  password ||= random_password
6
8
  database ||= connection_model.connection_config[:database]
@@ -39,6 +41,8 @@ module PgHero
39
41
  {password: password}
40
42
  end
41
43
 
44
+ # documented as unsafe to pass user input
45
+ # TODO quote in 3.0, but still not officially supported
42
46
  def drop_user(user, schema: "public", database: nil)
43
47
  database ||= connection_model.connection_config[:database]
44
48
 
@@ -1,3 +1,3 @@
1
1
  module PgHero
2
- VERSION = "2.5.1"
2
+ VERSION = "2.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pghero
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-23 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord