pghero 1.5.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +75 -0
- data/Gemfile +1 -1
- data/README.md +8 -14
- data/app/assets/javascripts/pghero/Chart.bundle.js +7512 -5661
- data/app/assets/javascripts/pghero/application.js +9 -0
- data/app/assets/javascripts/pghero/chartkick.js +511 -152
- data/app/assets/javascripts/pghero/highlight.pack.js +2 -0
- data/app/assets/stylesheets/pghero/application.css +66 -2
- data/app/assets/stylesheets/pghero/arduino-light.css +86 -0
- data/app/controllers/pg_hero/home_controller.rb +166 -63
- data/app/helpers/pg_hero/base_helper.rb +15 -0
- data/app/views/layouts/pg_hero/application.html.erb +4 -3
- data/app/views/pg_hero/home/_connections_table.html.erb +2 -9
- data/app/views/pg_hero/home/_live_queries_table.html.erb +11 -8
- data/app/views/pg_hero/home/_queries_table.html.erb +21 -10
- data/app/views/pg_hero/home/_suggested_index.html.erb +1 -1
- data/app/views/pg_hero/home/connections.html.erb +19 -1
- data/app/views/pg_hero/home/explain.html.erb +1 -1
- data/app/views/pg_hero/home/index.html.erb +125 -66
- data/app/views/pg_hero/home/index_bloat.html.erb +69 -0
- data/app/views/pg_hero/home/live_queries.html.erb +3 -1
- data/app/views/pg_hero/home/maintenance.html.erb +11 -7
- data/app/views/pg_hero/home/queries.html.erb +10 -0
- data/app/views/pg_hero/home/relation_space.html.erb +9 -0
- data/app/views/pg_hero/home/show_query.html.erb +107 -0
- data/app/views/pg_hero/home/space.html.erb +64 -10
- data/app/views/pg_hero/home/system.html.erb +16 -4
- data/config/routes.rb +4 -2
- data/guides/Linux.md +20 -0
- data/guides/Rails.md +30 -4
- data/guides/Suggested-Indexes.md +1 -1
- data/lib/generators/pghero/config_generator.rb +13 -0
- data/lib/generators/pghero/query_stats_generator.rb +7 -1
- data/lib/generators/pghero/space_stats_generator.rb +7 -1
- data/lib/generators/pghero/templates/config.yml +23 -0
- data/lib/generators/pghero/templates/query_stats.rb +1 -1
- data/lib/generators/pghero/templates/space_stats.rb +1 -1
- data/lib/pghero/database.rb +6 -2
- data/lib/pghero/engine.rb +10 -7
- data/lib/pghero/methods/basic.rb +83 -11
- data/lib/pghero/methods/connections.rb +16 -56
- data/lib/pghero/methods/explain.rb +3 -5
- data/lib/pghero/methods/indexes.rb +179 -21
- data/lib/pghero/methods/kill.rb +2 -2
- data/lib/pghero/methods/maintenance.rb +34 -20
- data/lib/pghero/methods/queries.rb +28 -45
- data/lib/pghero/methods/query_stats.rb +97 -91
- data/lib/pghero/methods/{replica.rb → replication.rb} +20 -4
- data/lib/pghero/methods/sequences.rb +4 -5
- data/lib/pghero/methods/space.rb +101 -8
- data/lib/pghero/methods/suggested_indexes.rb +49 -108
- data/lib/pghero/methods/system.rb +23 -13
- data/lib/pghero/methods/tables.rb +9 -9
- data/lib/pghero/methods/users.rb +10 -12
- data/lib/pghero/version.rb +1 -1
- data/lib/pghero.rb +34 -36
- data/lib/tasks/pghero.rake +5 -0
- data/test/basic_test.rb +38 -0
- data/test/best_index_test.rb +3 -3
- data/test/suggested_indexes_test.rb +0 -2
- data/test/test_helper.rb +38 -40
- metadata +14 -7
- data/app/views/pg_hero/home/index_usage.html.erb +0 -27
- data/test/explain_test.rb +0 -18
data/test/best_index_test.rb
CHANGED
|
@@ -11,9 +11,9 @@ class BestIndexTest < Minitest::Test
|
|
|
11
11
|
found: true,
|
|
12
12
|
structure: {table: "users", where: [{column: "login_attempts", op: "="}], sort: [{column: "created_at", direction: "asc"}]},
|
|
13
13
|
index: {table: "users", columns: ["login_attempts", "created_at"]},
|
|
14
|
-
rows:
|
|
15
|
-
row_estimates: {"login_attempts (=)" =>
|
|
16
|
-
row_progression: [
|
|
14
|
+
rows: 5000,
|
|
15
|
+
row_estimates: {"login_attempts (=)" => 167, "created_at (sort)" => 1},
|
|
16
|
+
row_progression: [5000, 167, 0]
|
|
17
17
|
}
|
|
18
18
|
assert_equal expected, index
|
|
19
19
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -10,10 +10,27 @@ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
|
|
|
10
10
|
|
|
11
11
|
ActiveRecord::Base.establish_connection adapter: "postgresql", database: "pghero_test"
|
|
12
12
|
|
|
13
|
+
ActiveRecord::Migration.enable_extension "pg_stat_statements"
|
|
14
|
+
|
|
13
15
|
ActiveRecord::Migration.create_table :cities, force: true do |t|
|
|
14
16
|
t.string :name
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
ActiveRecord::Migration.create_table :states, force: true do |t|
|
|
20
|
+
t.string :name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
ActiveRecord::Migration.create_table :users, force: true do |t|
|
|
24
|
+
t.integer :city_id
|
|
25
|
+
t.integer :login_attempts
|
|
26
|
+
t.string :email
|
|
27
|
+
t.string :zip_code
|
|
28
|
+
t.boolean :active
|
|
29
|
+
t.timestamp :created_at
|
|
30
|
+
t.timestamp :updated_at
|
|
31
|
+
end
|
|
32
|
+
ActiveRecord::Migration.add_index :users, :updated_at
|
|
33
|
+
|
|
17
34
|
class City < ActiveRecord::Base
|
|
18
35
|
end
|
|
19
36
|
|
|
@@ -23,46 +40,27 @@ end
|
|
|
23
40
|
class User < ActiveRecord::Base
|
|
24
41
|
end
|
|
25
42
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
t.string :zip_code
|
|
32
|
-
t.boolean :active
|
|
33
|
-
t.timestamp :created_at
|
|
34
|
-
t.timestamp :updated_at
|
|
43
|
+
states =
|
|
44
|
+
50.times.map do |i|
|
|
45
|
+
{
|
|
46
|
+
name: "State #{i}"
|
|
47
|
+
}
|
|
35
48
|
end
|
|
36
|
-
|
|
49
|
+
State.import states, validate: false
|
|
50
|
+
ActiveRecord::Base.connection.execute("ANALYZE states")
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
end
|
|
52
|
-
User.import users, validate: false
|
|
52
|
+
users =
|
|
53
|
+
5000.times.map do |i|
|
|
54
|
+
city_id = i % 100
|
|
55
|
+
{
|
|
56
|
+
city_id: city_id,
|
|
57
|
+
email: "person#{i}@example.org",
|
|
58
|
+
login_attempts: rand(30),
|
|
59
|
+
zip_code: i % 40 == 0 ? nil : "12345",
|
|
60
|
+
active: true,
|
|
61
|
+
created_at: Time.now - rand(50).days,
|
|
62
|
+
updated_at: Time.now - rand(50).days
|
|
63
|
+
}
|
|
53
64
|
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
ActiveRecord::Migration.create_table :states, force: true do |t|
|
|
57
|
-
t.string :name
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
State.transaction do
|
|
61
|
-
states =
|
|
62
|
-
50.times.map do |i|
|
|
63
|
-
State.new(name: "State #{i}")
|
|
64
|
-
end
|
|
65
|
-
State.import states, validate: false
|
|
66
|
-
end
|
|
67
|
-
ActiveRecord::Base.connection.execute("VACUUM ANALYZE states")
|
|
68
|
-
end
|
|
65
|
+
User.import users, validate: false
|
|
66
|
+
ActiveRecord::Base.connection.execute("ANALYZE users")
|
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:
|
|
4
|
+
version: 2.0.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:
|
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -125,11 +125,14 @@ files:
|
|
|
125
125
|
- app/assets/javascripts/pghero/Chart.bundle.js
|
|
126
126
|
- app/assets/javascripts/pghero/application.js
|
|
127
127
|
- app/assets/javascripts/pghero/chartkick.js
|
|
128
|
+
- app/assets/javascripts/pghero/highlight.pack.js
|
|
128
129
|
- app/assets/javascripts/pghero/jquery.js
|
|
129
130
|
- app/assets/javascripts/pghero/jquery.nouislider.min.js
|
|
130
131
|
- app/assets/stylesheets/pghero/application.css
|
|
132
|
+
- app/assets/stylesheets/pghero/arduino-light.css
|
|
131
133
|
- app/assets/stylesheets/pghero/jquery.nouislider.css
|
|
132
134
|
- app/controllers/pg_hero/home_controller.rb
|
|
135
|
+
- app/helpers/pg_hero/base_helper.rb
|
|
133
136
|
- app/views/layouts/pg_hero/application.html.erb
|
|
134
137
|
- app/views/pg_hero/home/_connections_table.html.erb
|
|
135
138
|
- app/views/pg_hero/home/_live_queries_table.html.erb
|
|
@@ -139,10 +142,12 @@ files:
|
|
|
139
142
|
- app/views/pg_hero/home/connections.html.erb
|
|
140
143
|
- app/views/pg_hero/home/explain.html.erb
|
|
141
144
|
- app/views/pg_hero/home/index.html.erb
|
|
142
|
-
- app/views/pg_hero/home/
|
|
145
|
+
- app/views/pg_hero/home/index_bloat.html.erb
|
|
143
146
|
- app/views/pg_hero/home/live_queries.html.erb
|
|
144
147
|
- app/views/pg_hero/home/maintenance.html.erb
|
|
145
148
|
- app/views/pg_hero/home/queries.html.erb
|
|
149
|
+
- app/views/pg_hero/home/relation_space.html.erb
|
|
150
|
+
- app/views/pg_hero/home/show_query.html.erb
|
|
146
151
|
- app/views/pg_hero/home/space.html.erb
|
|
147
152
|
- app/views/pg_hero/home/system.html.erb
|
|
148
153
|
- app/views/pg_hero/home/tune.html.erb
|
|
@@ -153,8 +158,10 @@ files:
|
|
|
153
158
|
- guides/Query-Stats.md
|
|
154
159
|
- guides/Rails.md
|
|
155
160
|
- guides/Suggested-Indexes.md
|
|
161
|
+
- lib/generators/pghero/config_generator.rb
|
|
156
162
|
- lib/generators/pghero/query_stats_generator.rb
|
|
157
163
|
- lib/generators/pghero/space_stats_generator.rb
|
|
164
|
+
- lib/generators/pghero/templates/config.yml
|
|
158
165
|
- lib/generators/pghero/templates/query_stats.rb
|
|
159
166
|
- lib/generators/pghero/templates/space_stats.rb
|
|
160
167
|
- lib/pghero.rb
|
|
@@ -169,7 +176,7 @@ files:
|
|
|
169
176
|
- lib/pghero/methods/maintenance.rb
|
|
170
177
|
- lib/pghero/methods/queries.rb
|
|
171
178
|
- lib/pghero/methods/query_stats.rb
|
|
172
|
-
- lib/pghero/methods/
|
|
179
|
+
- lib/pghero/methods/replication.rb
|
|
173
180
|
- lib/pghero/methods/sequences.rb
|
|
174
181
|
- lib/pghero/methods/space.rb
|
|
175
182
|
- lib/pghero/methods/suggested_indexes.rb
|
|
@@ -180,8 +187,8 @@ files:
|
|
|
180
187
|
- lib/pghero/version.rb
|
|
181
188
|
- lib/tasks/pghero.rake
|
|
182
189
|
- pghero.gemspec
|
|
190
|
+
- test/basic_test.rb
|
|
183
191
|
- test/best_index_test.rb
|
|
184
|
-
- test/explain_test.rb
|
|
185
192
|
- test/gemfiles/activerecord41.gemfile
|
|
186
193
|
- test/gemfiles/activerecord42.gemfile
|
|
187
194
|
- test/suggested_indexes_test.rb
|
|
@@ -206,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
206
213
|
version: '0'
|
|
207
214
|
requirements: []
|
|
208
215
|
rubyforge_project:
|
|
209
|
-
rubygems_version: 2.
|
|
216
|
+
rubygems_version: 2.6.11
|
|
210
217
|
signing_key:
|
|
211
218
|
specification_version: 4
|
|
212
219
|
summary: A performance dashboard for Postgres
|
|
@@ -217,8 +224,8 @@ test_files:
|
|
|
217
224
|
- guides/Query-Stats.md
|
|
218
225
|
- guides/Rails.md
|
|
219
226
|
- guides/Suggested-Indexes.md
|
|
227
|
+
- test/basic_test.rb
|
|
220
228
|
- test/best_index_test.rb
|
|
221
|
-
- test/explain_test.rb
|
|
222
229
|
- test/gemfiles/activerecord41.gemfile
|
|
223
230
|
- test/gemfiles/activerecord42.gemfile
|
|
224
231
|
- test/suggested_indexes_test.rb
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<div class="content">
|
|
2
|
-
<h1>Index Usage</h1>
|
|
3
|
-
|
|
4
|
-
<table class="table">
|
|
5
|
-
<thead>
|
|
6
|
-
<tr>
|
|
7
|
-
<th>Table</th>
|
|
8
|
-
<th style="width: 30%;">% of Time Index Used</th>
|
|
9
|
-
<th style="width: 20%;">Rows</th>
|
|
10
|
-
</tr>
|
|
11
|
-
</thead>
|
|
12
|
-
<tbody>
|
|
13
|
-
<% @index_usage.each do |query| %>
|
|
14
|
-
<tr>
|
|
15
|
-
<td>
|
|
16
|
-
<%= query["table"] %>
|
|
17
|
-
<% if query["schema"] != "public" %>
|
|
18
|
-
<span class="text-muted"><%= query["schema"] %></span>
|
|
19
|
-
<% end %>
|
|
20
|
-
</td>
|
|
21
|
-
<td><%= query["percent_of_times_index_used"] %></td>
|
|
22
|
-
<td><%= number_with_delimiter(query["rows_in_table"]) %></td>
|
|
23
|
-
</tr>
|
|
24
|
-
<% end %>
|
|
25
|
-
</tbody>
|
|
26
|
-
</table>
|
|
27
|
-
</div>
|
data/test/explain_test.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require_relative "test_helper"
|
|
2
|
-
|
|
3
|
-
class ExplainTest < Minitest::Test
|
|
4
|
-
def setup
|
|
5
|
-
City.delete_all
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def test_explain
|
|
9
|
-
City.create!
|
|
10
|
-
PgHero.explain("ANALYZE DELETE FROM cities")
|
|
11
|
-
assert_equal 1, City.count
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_explain_multiple_statements
|
|
15
|
-
City.create!
|
|
16
|
-
assert_raises(ActiveRecord::StatementInvalid) { PgHero.explain("ANALYZE DELETE FROM cities; DELETE FROM cities; COMMIT") }
|
|
17
|
-
end
|
|
18
|
-
end
|