pghero 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: 408d3e02f0d03c8da95d11eaeea8a6c0fb8be19e
4
- data.tar.gz: 557d0b3c72e111fe2355b80eda417ad731d2a345
3
+ metadata.gz: fb091e2ecc7b76f41e0af306855d6df60f9ace12
4
+ data.tar.gz: c82ae33d920f6b7862b8aa9cc46e7abe0fffa5c2
5
5
  SHA512:
6
- metadata.gz: e480e555168eaea71a6eada2f669058ee6097d0ac54e1812648025deeae343727a35f7c30287af8abb5c451d2de6d481fd9c099cf96e76fc92b7becd82740e00
7
- data.tar.gz: 8bd10dc018837518f2f623575d2b6f1c2f975b493b1434800fa31a2f999b933bc70318751041431e7ae7d63dc83602c2982b439e6c569dcd0dfd4de7442ef566
6
+ metadata.gz: c24fd383eb9069a9445a2e826e65dbb5eaeb3e9a7ab03c202dc1acaf42ef866e52f6895a8f202043f16b82eb41cc8ad297773d8e57811e5b0e928052e3cf699e
7
+ data.tar.gz: 0d7193d888ae03896d64080dfa14dd811fc6e8b7aea621c913b34f082a4baa7da113339aa3dfcca9828276034cf0c8c163599a73d5bb23ae5ede1dccca21d028
@@ -1,3 +1,8 @@
1
+ ## 0.1.7
2
+
3
+ - Added support for pg_stat_statments on Amazon RDS
4
+ - Added `long_running_query_sec`, `slow_query_ms` and `slow_query_calls` options
5
+
1
6
  ## 0.1.6
2
7
 
3
8
  - Added methods to create and drop users
data/README.md CHANGED
@@ -4,13 +4,13 @@ Postgres insights made easy
4
4
 
5
5
  [View the demo](https://pghero.herokuapp.com/)
6
6
 
7
- ![Screenshot](https://pghero.herokuapp.com/assets/screenshot-57d07895ddb050f8dd46b98e73ef1415.png)
7
+ ![Screenshot](https://pghero.herokuapp.com/assets/screenshot-d09df77e5e1de184ae1fcfb2e5f49387.png)
8
8
 
9
9
  Supports PostgreSQL 9.2+
10
10
 
11
11
  :speech_balloon: Get [handcrafted updates](http://chartkick.us7.list-manage.com/subscribe?u=952c861f99eb43084e0a49f98&id=6ea6541e8e&group[0][32]=true) for new features
12
12
 
13
- For pure SQL, check out [PgHero.sql](https://github.com/ankane/pghero.sql)
13
+ For pure SQL, check out [PgHero.sql](https://github.com/ankane/pghero.sql) and for a standalone app, check out [PgHero Solo](https://github.com/bmorton/pghero_solo)
14
14
 
15
15
  A big thanks to [Craig Kerstiens](http://www.craigkerstiens.com/2013/01/10/more-on-postgres-performance/) and [Heroku](https://blog.heroku.com/archives/2013/5/10/more_insight_into_your_database_with_pgextras) for the initial queries :clap:
16
16
 
@@ -115,9 +115,7 @@ end
115
115
 
116
116
  The [pg_stat_statements module](http://www.postgresql.org/docs/9.3/static/pgstatstatements.html) is used for query stats.
117
117
 
118
- ### Common Issues
119
-
120
- #### Installation
118
+ ### Installation
121
119
 
122
120
  If you have trouble enabling query stats from the dashboard, try doing it manually.
123
121
 
@@ -134,7 +132,17 @@ Then restart PostgreSQL. As a superuser from the `psql` console, run:
134
132
  CREATE extension pg_stat_statements;
135
133
  ```
136
134
 
137
- **Note:** Query stats are not available on Amazon RDS. [Tell Amazon you want this.](https://forums.aws.amazon.com/thread.jspa?messageID=548724)
135
+ #### Amazon RDS
136
+
137
+ Change `shared_preload_libraries` to `pg_stat_statements` in your [Parameter Group](https://console.aws.amazon.com/rds/home?region=us-east-1#parameter-groups:) and restart the database instance.
138
+
139
+ As a superuser from the `psql` console, run:
140
+
141
+ ```psql
142
+ CREATE extension pg_stat_statements;
143
+ ```
144
+
145
+ ### Common Issues
138
146
 
139
147
  #### pg_stat_statements must be loaded via shared_preload_libraries
140
148
 
@@ -175,6 +183,26 @@ PGHERO_SECRET_ACCESS_KEY=secret123
175
183
  PGHERO_DB_INSTANCE_IDENTIFIER=datakick-production
176
184
  ```
177
185
 
186
+ ## Customize
187
+
188
+ Minimum time for long running queries
189
+
190
+ ```ruby
191
+ PgHero.long_running_query_sec = 60 # default
192
+ ```
193
+
194
+ Minimum average time for slow queries
195
+
196
+ ```ruby
197
+ PgHero.slow_query_ms = 20 # default
198
+ ```
199
+
200
+ Minimum calls for slow queries
201
+
202
+ ```ruby
203
+ PgHero.slow_query_calls = 100 # default
204
+ ```
205
+
178
206
  ## TODO
179
207
 
180
208
  - show exactly which indexes to add
@@ -18,7 +18,6 @@ module PgHero
18
18
  @unused_indexes = PgHero.unused_indexes
19
19
  @good_cache_rate = @table_hit_rate >= 0.99 && @index_hit_rate >= 0.99
20
20
  @query_stats_available = PgHero.query_stats_available?
21
- @rds = PgHero.rds?
22
21
  end
23
22
 
24
23
  def indexes
@@ -1,13 +1,4 @@
1
1
  <div id="status">
2
- <div class="alert alert-<%= @query_stats_enabled && @slow_queries.empty? ? "success" : "warning" %>">
3
- <% if !@query_stats_enabled %>
4
- Query stats must be enabled for slow queries
5
- <% elsif @slow_queries.any? %>
6
- <%= pluralize(@slow_queries.size, "slow query") %>
7
- <% else %>
8
- No slow queries
9
- <% end %>
10
- </div>
11
2
  <div class="alert alert-<%= @long_running_queries.empty? ? "success" : "warning" %>">
12
3
  <% if @long_running_queries.any? %>
13
4
  <%= pluralize(@long_running_queries.size, "long running query") %>
@@ -22,6 +13,15 @@
22
13
  Low cache hit rate
23
14
  <% end %>
24
15
  </div>
16
+ <div class="alert alert-<%= @query_stats_enabled && @slow_queries.empty? ? "success" : "warning" %>">
17
+ <% if !@query_stats_enabled %>
18
+ Query stats must be enabled for slow queries
19
+ <% elsif @slow_queries.any? %>
20
+ <%= pluralize(@slow_queries.size, "slow query") %>
21
+ <% else %>
22
+ No slow queries
23
+ <% end %>
24
+ </div>
25
25
  <div class="alert alert-<%= @missing_indexes.empty? ? "success" : "warning" %>">
26
26
  <% if @missing_indexes.any? %>
27
27
  <%= pluralize(@missing_indexes.size, "table appears", "tables appear") %> to be missing indexes
@@ -38,6 +38,31 @@
38
38
  </div>
39
39
  </div>
40
40
 
41
+ <% if @long_running_queries.any? %>
42
+ <div class="content">
43
+ <h1>Long Running Queries</h1>
44
+
45
+ <%= render partial: "queries_table", locals: {queries: @long_running_queries} %>
46
+ </div>
47
+ <% end %>
48
+
49
+ <% if !@good_cache_rate %>
50
+ <div class="content">
51
+ <h1>Low Cache Hit Rate</h1>
52
+
53
+ <p>
54
+ Index Hit Rate: <%= (@index_hit_rate * 100).round(1) %>%
55
+ <br />
56
+ Table Hit Rate: <%= (@table_hit_rate * 100).round(1) %>%
57
+ </p>
58
+
59
+ <p>
60
+ The cache hit rate <%= link_to "should be above 99%", "https://devcenter.heroku.com/articles/understanding-postgres-data-caching", target: "_blank" %> in most cases. You can often increase this by adding more memory.
61
+ <!-- TODO better suggestions -->
62
+ </p>
63
+ </div>
64
+ <% end %>
65
+
41
66
  <% if !@query_stats_enabled %>
42
67
  <div class="content">
43
68
  <h1>Query Stats</h1>
@@ -47,8 +72,6 @@
47
72
  Query stats are available but not enabled.
48
73
  <%= button_to "Enable", enable_query_stats_path, class: "btn btn-info" %>
49
74
  </p>
50
- <% elsif @rds %>
51
- <p>Query stats are not available on Amazon RDS. <%= link_to "Tell Amazon you want this.", "https://forums.aws.amazon.com/thread.jspa?messageID=548724", target: "_blank" %></p>
52
75
  <% else %>
53
76
  <p>Make them available by adding the following lines to <code>postgresql.conf</code>:</p>
54
77
  <pre>shared_preload_libraries = 'pg_stat_statements'
@@ -62,39 +85,13 @@ pg_stat_statements.track = all</pre>
62
85
  <div class="content">
63
86
  <h1>Slow Queries</h1>
64
87
 
65
- <p>Slow queries take 20 ms or more on average and have been called at least 100 times.</p>
66
- <p><%= link_to "Run EXPLAIN", explain_path %> on queries to see where to add indexes.</p>
88
+ <p>Slow queries take <%= PgHero.slow_query_ms %> ms or more on average and have been called at least <%= PgHero.slow_query_calls %> times.</p>
89
+ <p><%= link_to "Explain queries", explain_path %> to see where to add indexes.</p>
67
90
 
68
91
  <%= render partial: "query_stats_table", locals: {queries: @slow_queries} %>
69
92
  </div>
70
93
  <% end %>
71
94
 
72
- <% if @long_running_queries.any? %>
73
- <div class="content">
74
- <h1>Long Running Queries</h1>
75
-
76
- <%= render partial: "queries_table", locals: {queries: @long_running_queries} %>
77
- </div>
78
- <% end %>
79
-
80
- <% if !@good_cache_rate %>
81
- <div class="content">
82
- <h1>Low Cache Hit Rate</h1>
83
-
84
- <p>
85
- Index Hit Rate: <%= (@index_hit_rate * 100).round(1) %>%
86
- <br />
87
- Table Hit Rate: <%= (@table_hit_rate * 100).round(1) %>%
88
- </p>
89
-
90
- <p>
91
- The cache hit rate <%= link_to "should be above 99%", "https://devcenter.heroku.com/articles/understanding-postgres-data-caching", target: "_blank" %> in most cases. You can often increase this by adding more memory.
92
- <!-- TODO better suggestions -->
93
- </p>
94
- </div>
95
- <% end %>
96
-
97
-
98
95
  <% if @missing_indexes.any? %>
99
96
  <div class="content">
100
97
  <h1>Missing Indexes</h1>
@@ -8,6 +8,13 @@ module PgHero
8
8
  establish_connection ENV["PGHERO_DATABASE_URL"] if ENV["PGHERO_DATABASE_URL"]
9
9
  end
10
10
 
11
+ class << self
12
+ attr_accessor :long_running_query_sec, :slow_query_ms, :slow_query_calls
13
+ end
14
+ self.long_running_query_sec = 60
15
+ self.slow_query_ms = 20
16
+ self.slow_query_calls = 100
17
+
11
18
  class << self
12
19
 
13
20
  def running_queries
@@ -47,7 +54,7 @@ module PgHero
47
54
  query <> '<insufficient privilege>'
48
55
  AND state <> 'idle'
49
56
  AND pid <> pg_backend_pid()
50
- AND now() - query_start > interval '1 minutes'
57
+ AND now() - query_start > interval '#{long_running_query_sec.to_i} seconds'
51
58
  ORDER BY
52
59
  query_start DESC
53
60
  }
@@ -244,8 +251,8 @@ module PgHero
244
251
  pg_database ON pg_database.oid = pg_stat_statements.dbid
245
252
  WHERE
246
253
  pg_database.datname = current_database()
247
- AND calls >= 100
248
- AND (total_time / calls) >= 20
254
+ AND calls >= #{slow_query_calls.to_i}
255
+ AND (total_time / calls) >= #{slow_query_ms.to_i}
249
256
  ORDER BY
250
257
  total_minutes DESC
251
258
  LIMIT 100
@@ -256,7 +263,7 @@ module PgHero
256
263
  end
257
264
 
258
265
  def query_stats_available?
259
- select_all("SELECT COUNT(*) AS count FROM pg_available_extensions WHERE name = 'pg_stat_statements'").first["count"].to_i > 0 && !rds?
266
+ select_all("SELECT COUNT(*) AS count FROM pg_available_extensions WHERE name = 'pg_stat_statements'").first["count"].to_i > 0
260
267
  end
261
268
 
262
269
  def query_stats_enabled?
@@ -393,11 +400,6 @@ module PgHero
393
400
  ENV["PGHERO_DB_INSTANCE_IDENTIFIER"]
394
401
  end
395
402
 
396
- # TODO better RDS check
397
- def rds?
398
- !!(Connection.connection_config[:host].to_s =~ /rds\.amazonaws\.com\z/)
399
- end
400
-
401
403
  def explain(sql)
402
404
  sql = squish(sql)
403
405
  explanation = nil
@@ -1,3 +1,3 @@
1
1
  module PgHero
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
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: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord