pghero 1.7.0 → 2.0.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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +31 -0
- data/README.md +2 -2
- data/app/assets/javascripts/pghero/Chart.bundle.js +7512 -5661
- data/app/assets/javascripts/pghero/application.js +9 -0
- data/app/assets/javascripts/pghero/highlight.pack.js +2 -0
- data/app/assets/stylesheets/pghero/application.css +54 -2
- data/app/assets/stylesheets/pghero/arduino-light.css +86 -0
- data/app/controllers/pg_hero/home_controller.rb +148 -52
- data/app/helpers/pg_hero/base_helper.rb +15 -0
- data/app/views/layouts/pg_hero/application.html.erb +1 -1
- data/app/views/pg_hero/home/_connections_table.html.erb +2 -2
- data/app/views/pg_hero/home/_live_queries_table.html.erb +11 -7
- 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 +2 -14
- data/app/views/pg_hero/home/explain.html.erb +1 -1
- data/app/views/pg_hero/home/index.html.erb +58 -22
- data/app/views/pg_hero/home/index_bloat.html.erb +69 -0
- data/app/views/pg_hero/home/maintenance.html.erb +7 -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/config/routes.rb +4 -2
- data/guides/Rails.md +28 -1
- data/guides/Suggested-Indexes.md +1 -1
- data/lib/pghero.rb +25 -36
- data/lib/pghero/database.rb +5 -1
- data/lib/pghero/methods/basic.rb +78 -13
- data/lib/pghero/methods/connections.rb +16 -56
- data/lib/pghero/methods/explain.rb +2 -6
- data/lib/pghero/methods/indexes.rb +173 -18
- data/lib/pghero/methods/kill.rb +2 -2
- data/lib/pghero/methods/maintenance.rb +23 -26
- data/lib/pghero/methods/queries.rb +1 -23
- data/lib/pghero/methods/query_stats.rb +95 -96
- data/lib/pghero/methods/{replica.rb → replication.rb} +17 -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 +14 -10
- data/lib/pghero/methods/tables.rb +8 -8
- data/lib/pghero/methods/users.rb +10 -12
- data/lib/pghero/version.rb +1 -1
- data/lib/tasks/pghero.rake +1 -1
- 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 +11 -6
- data/app/views/pg_hero/home/index_usage.html.erb +0 -27
- data/test/explain_test.rb +0 -18
data/lib/pghero/version.rb
CHANGED
data/lib/tasks/pghero.rake
CHANGED
data/test/basic_test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class BasicTest < 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
|
+
|
19
|
+
def test_analyze_tables
|
20
|
+
assert PgHero.analyze_tables
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_relation_sizes
|
24
|
+
assert PgHero.relation_sizes
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_transaction_id_danger
|
28
|
+
assert PgHero.transaction_id_danger(threshold: 10000000000)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_autovacuum_danger
|
32
|
+
assert PgHero.autovacuum_danger
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_databases
|
36
|
+
assert PgHero.databases[:primary].running_queries
|
37
|
+
end
|
38
|
+
end
|
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: 2017-
|
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
|
@@ -171,7 +176,7 @@ files:
|
|
171
176
|
- lib/pghero/methods/maintenance.rb
|
172
177
|
- lib/pghero/methods/queries.rb
|
173
178
|
- lib/pghero/methods/query_stats.rb
|
174
|
-
- lib/pghero/methods/
|
179
|
+
- lib/pghero/methods/replication.rb
|
175
180
|
- lib/pghero/methods/sequences.rb
|
176
181
|
- lib/pghero/methods/space.rb
|
177
182
|
- lib/pghero/methods/suggested_indexes.rb
|
@@ -182,8 +187,8 @@ files:
|
|
182
187
|
- lib/pghero/version.rb
|
183
188
|
- lib/tasks/pghero.rake
|
184
189
|
- pghero.gemspec
|
190
|
+
- test/basic_test.rb
|
185
191
|
- test/best_index_test.rb
|
186
|
-
- test/explain_test.rb
|
187
192
|
- test/gemfiles/activerecord41.gemfile
|
188
193
|
- test/gemfiles/activerecord42.gemfile
|
189
194
|
- test/suggested_indexes_test.rb
|
@@ -219,8 +224,8 @@ test_files:
|
|
219
224
|
- guides/Query-Stats.md
|
220
225
|
- guides/Rails.md
|
221
226
|
- guides/Suggested-Indexes.md
|
227
|
+
- test/basic_test.rb
|
222
228
|
- test/best_index_test.rb
|
223
|
-
- test/explain_test.rb
|
224
229
|
- test/gemfiles/activerecord41.gemfile
|
225
230
|
- test/gemfiles/activerecord42.gemfile
|
226
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
|