pghero 2.1.1 → 2.2.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.

Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/CONTRIBUTING.md +9 -7
  4. data/README.md +6 -4
  5. data/app/controllers/pg_hero/home_controller.rb +10 -2
  6. data/app/views/pg_hero/home/explain.html.erb +1 -1
  7. data/app/views/pg_hero/home/index.html.erb +16 -6
  8. data/lib/generators/pghero/templates/{config.yml → config.yml.tt} +3 -3
  9. data/lib/generators/pghero/templates/{query_stats.rb → query_stats.rb.tt} +0 -0
  10. data/lib/generators/pghero/templates/{space_stats.rb → space_stats.rb.tt} +0 -0
  11. data/lib/pghero.rb +2 -2
  12. data/lib/pghero/methods/connections.rb +16 -0
  13. data/lib/pghero/methods/indexes.rb +32 -26
  14. data/lib/pghero/methods/maintenance.rb +1 -1
  15. data/lib/pghero/methods/query_stats.rb +2 -2
  16. data/lib/pghero/methods/replication.rb +1 -1
  17. data/lib/pghero/methods/sequences.rb +6 -2
  18. data/lib/pghero/methods/suggested_indexes.rb +1 -5
  19. data/lib/pghero/version.rb +1 -1
  20. metadata +9 -45
  21. data/.gitattributes +0 -1
  22. data/.github/ISSUE_TEMPLATE.md +0 -7
  23. data/.gitignore +0 -22
  24. data/.travis.yml +0 -16
  25. data/Gemfile +0 -6
  26. data/Rakefile +0 -8
  27. data/guides/Contributing.md +0 -16
  28. data/guides/Docker.md +0 -89
  29. data/guides/Heroku.md +0 -102
  30. data/guides/Linux.md +0 -296
  31. data/guides/Permissions.md +0 -57
  32. data/guides/Query-Stats.md +0 -60
  33. data/guides/Rails.md +0 -339
  34. data/guides/Suggested-Indexes.md +0 -19
  35. data/pghero.gemspec +0 -35
  36. data/test/basic_test.rb +0 -38
  37. data/test/best_index_test.rb +0 -180
  38. data/test/gemfiles/activerecord41.gemfile +0 -6
  39. data/test/gemfiles/activerecord42.gemfile +0 -6
  40. data/test/suggested_indexes_test.rb +0 -18
  41. data/test/test_helper.rb +0 -66
@@ -1 +0,0 @@
1
- app/assets/* linguist-vendored
@@ -1,7 +0,0 @@
1
- Hi,
2
-
3
- Before creating an issue, please check out the Contributing Guide:
4
-
5
- https://github.com/ankane/pghero/blob/master/CONTRIBUTING.md
6
-
7
- Thanks!
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- *.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
@@ -1,16 +0,0 @@
1
- language: ruby
2
- rvm: 2.4.4
3
- cache: bundler
4
- sudo: false
5
- script: TRAVIS_CI=1 bundle exec rake test
6
- addons:
7
- postgresql: "9.4"
8
- before_install:
9
- - gem update --system
10
- - gem install bundler
11
- before_script:
12
- - psql -c 'create database pghero_test;' -U postgres
13
- notifications:
14
- email:
15
- on_success: never
16
- on_failure: change
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in pghero.gemspec
4
- gemspec
5
-
6
- gem "activerecord", "~> 5.2.0"
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- task default: :test
5
- Rake::TestTask.new do |t|
6
- t.libs << "test"
7
- t.pattern = "test/**/*_test.rb"
8
- end
@@ -1,16 +0,0 @@
1
- # Contributing
2
-
3
- ```sh
4
- git clone https://github.com/ankane/pghero.git
5
- git clone https://github.com/pghero/pghero.git pghero-dev
6
- cd pghero-dev
7
- git checkout dev
8
- createdb pghero_dev
9
- export DATABASE_URL=postgres:///pghero_dev
10
- bundle exec rails generate pghero:query_stats
11
- bundle exec rails generate pghero:space_stats
12
- bundle exec rake db:migrate
13
- foreman start
14
- ```
15
-
16
- And visit [http://localhost:5000](http://localhost:5000)
@@ -1,89 +0,0 @@
1
- # PgHero for Docker
2
-
3
- PgHero is available as a [Docker image](https://hub.docker.com/r/ankane/pghero/).
4
-
5
- ```sh
6
- docker run -ti -e DATABASE_URL=postgres://user:password@hostname:5432/dbname -p 8080:8080 ankane/pghero
7
- ```
8
-
9
- And visit [http://localhost:8080](http://localhost:8080).
10
-
11
- ## Query Stats
12
-
13
- Query stats can be enabled from the dashboard. If you run into issues, [view the guide](Query-Stats.md).
14
-
15
- ## Historical Query Stats
16
-
17
- To track query stats over time, create a table to store them.
18
-
19
- ```sql
20
- CREATE TABLE "pghero_query_stats" (
21
- "id" serial primary key,
22
- "database" text,
23
- "user" text,
24
- "query" text,
25
- "query_hash" bigint,
26
- "total_time" float,
27
- "calls" bigint,
28
- "captured_at" timestamp
29
- );
30
- CREATE INDEX ON "pghero_query_stats" ("database", "captured_at");
31
- ```
32
-
33
- Schedule the task below to run every 5 minutes.
34
-
35
- ```sh
36
- docker run -ti -e DATABASE_URL=... ankane/pghero bin/rake pghero:capture_query_stats
37
- ```
38
-
39
- After this, a time range slider will appear on the Queries tab.
40
-
41
- ## Historical Space Stats
42
-
43
- To track space stats over time, create a table to store them.
44
-
45
- ```sql
46
- CREATE TABLE "pghero_space_stats" (
47
- "id" serial primary key,
48
- "database" text,
49
- "schema" text,
50
- "relation" text,
51
- "size" bigint,
52
- "captured_at" timestamp
53
- );
54
- CREATE INDEX ON "pghero_space_stats" ("database", "captured_at");
55
- ```
56
-
57
- Schedule the task below to run once a day.
58
-
59
- ```sh
60
- docker run -ti -e DATABASE_URL=... ankane/pghero bin/rake pghero:capture_space_stats
61
- ```
62
-
63
- ## Multiple Databases
64
-
65
- Create a file at `/app/config/pghero.yml` with:
66
-
67
- ```yml
68
- databases:
69
- primary:
70
- url: postgres://...
71
- replica:
72
- url: postgres://...
73
- ```
74
-
75
- ## Permissions
76
-
77
- We recommend [setting up a dedicated user](Permissions.md) for PgHero.
78
-
79
- ## Security
80
-
81
- And basic authentication with:
82
-
83
- ```sh
84
- docker run -e PGHERO_USERNAME=link -e PGHERO_PASSWORD=hyrule ...
85
- ```
86
-
87
- ## Credits
88
-
89
- Thanks to [Brian Morton](https://github.com/bmorton) for the [original Docker image](https://github.com/bmorton/pghero_solo).
@@ -1,102 +0,0 @@
1
- # PgHero for Heroku
2
-
3
- One click deployment
4
-
5
- [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/pghero/pghero)
6
-
7
- ## Authentication
8
-
9
- Set the following variables in your environment.
10
-
11
- ```sh
12
- heroku config:set PGHERO_USERNAME=link
13
- heroku config:set PGHERO_PASSWORD=hyrule
14
- ```
15
-
16
- ## Query Stats
17
-
18
- Query stats are enabled by default for Heroku databases - there’s nothing to do :tada:
19
-
20
- For databases outside of Heroku, query stats can be enabled from the dashboard.
21
-
22
- If you run into issues, [view the guide](Query-Stats.md).
23
-
24
- ## Historical Query Stats
25
-
26
- To track query stats over time, create a table to store them.
27
-
28
- ```sql
29
- CREATE TABLE "pghero_query_stats" (
30
- "id" serial primary key,
31
- "database" text,
32
- "user" text,
33
- "query" text,
34
- "query_hash" bigint,
35
- "total_time" float,
36
- "calls" bigint,
37
- "captured_at" timestamp
38
- )
39
- CREATE INDEX ON "pghero_query_stats" ("database", "captured_at")
40
- ```
41
-
42
- This table can be in the current database or another database. If another database, run:
43
-
44
- ```sh
45
- heroku config:set PGHERO_STATS_DATABASE_URL=...
46
- ```
47
-
48
- Schedule the task below to run every 5 minutes.
49
-
50
- ```sh
51
- rake pghero:capture_query_stats
52
- ```
53
-
54
- Or with a scheduler like Clockwork, use:
55
-
56
- ```ruby
57
- PgHero.capture_query_stats
58
- ```
59
-
60
- After this, a time range slider will appear on the Queries tab.
61
-
62
- ## System Stats
63
-
64
- CPU usage is available for Amazon RDS. Add these variables to your environment:
65
-
66
- ```sh
67
- heroku config:set PGHERO_ACCESS_KEY_ID=accesskey123
68
- heroku config:set PGHERO_SECRET_ACCESS_KEY=secret123
69
- heroku config:set PGHERO_DB_INSTANCE_IDENTIFIER=epona
70
- ```
71
-
72
- ## Customize
73
-
74
- Minimum time for long running queries
75
-
76
- ```sh
77
- heroku config:set PGHERO_LONG_RUNNING_QUERY_SEC=60 # default
78
- ```
79
-
80
- Minimum average time for slow queries
81
-
82
- ```sh
83
- heroku config:set PGHERO_SLOW_QUERY_MS=20 # default
84
- ```
85
-
86
- Minimum calls for slow queries
87
-
88
- ```sh
89
- heroku config:set PGHERO_SLOW_QUERY_CALLS=100 # default
90
- ```
91
-
92
- Minimum connections for high connections warning
93
-
94
- ```sh
95
- heroku config:set PGHERO_TOTAL_CONNECTIONS_THRESHOLD=100 # default
96
- ```
97
-
98
- Statement timeout for explain
99
-
100
- ```sh
101
- heroku config:set PGHERO_EXPLAIN_TIMEOUT_SEC=10 # default
102
- ````
@@ -1,296 +0,0 @@
1
- # PgHero for Linux
2
-
3
- Distributions
4
-
5
- - [Ubuntu 16.04 (Xenial)](#ubuntu-1604-xenial)
6
- - [Ubuntu 14.04 (Trusty)](#ubuntu-1404-trusty)
7
- - [Debian 9 (Stretch)](#debian-9-stretch)
8
- - [Debian 8 (Jesse)](#debian-8-jesse)
9
- - [Debian 7 (Wheezy)](#debian-7-wheezy)
10
- - [CentOS / RHEL 7](#centos--rhel-7)
11
- - [SUSE Linux Enterprise Server 12](#suse-linux-enterprise-server-12)
12
-
13
- 64-bit only
14
-
15
- ## Installation
16
-
17
- ### Ubuntu 16.04 (Xenial)
18
-
19
- ```sh
20
- wget -qO- https://dl.packager.io/srv/pghero/pghero/key | sudo apt-key add -
21
- sudo wget -O /etc/apt/sources.list.d/pghero.list \
22
- https://dl.packager.io/srv/pghero/pghero/master/installer/ubuntu/16.04.repo
23
- sudo apt-get update
24
- sudo apt-get -y install pghero
25
- ```
26
-
27
- ### Ubuntu 14.04 (Trusty)
28
-
29
- ```sh
30
- wget -qO- https://dl.packager.io/srv/pghero/pghero/key | sudo apt-key add -
31
- sudo wget -O /etc/apt/sources.list.d/pghero.list \
32
- https://dl.packager.io/srv/pghero/pghero/master/installer/ubuntu/14.04.repo
33
- sudo apt-get update
34
- sudo apt-get -y install pghero
35
- ```
36
-
37
- ### Debian 9 (Stretch)
38
-
39
- ```sh
40
- sudo apt-get -y install apt-transport-https
41
- wget -qO- https://dl.packager.io/srv/pghero/pghero/key | sudo apt-key add -
42
- sudo wget -O /etc/apt/sources.list.d/pghero.list \
43
- https://dl.packager.io/srv/pghero/pghero/master/installer/debian/9.repo
44
- sudo apt-get update
45
- sudo apt-get -y install pghero
46
- ```
47
-
48
- ### Debian 8 (Jesse)
49
-
50
- ```sh
51
- sudo apt-get -y install apt-transport-https
52
- wget -qO- https://dl.packager.io/srv/pghero/pghero/key | sudo apt-key add -
53
- sudo wget -O /etc/apt/sources.list.d/pghero.list \
54
- https://dl.packager.io/srv/pghero/pghero/master/installer/debian/8.repo
55
- sudo apt-get update
56
- sudo apt-get -y install pghero
57
- ```
58
-
59
- ### Debian 7 (Wheezy)
60
-
61
- ```sh
62
- sudo apt-get -y install apt-transport-https
63
- wget -qO- https://dl.packager.io/srv/pghero/pghero/key | sudo apt-key add -
64
- sudo wget -O /etc/apt/sources.list.d/pghero.list \
65
- https://dl.packager.io/srv/pghero/pghero/master/installer/debian/7.repo
66
- sudo apt-get update
67
- sudo apt-get -y install pghero
68
- ```
69
-
70
- ### CentOS / RHEL 7
71
-
72
- ```sh
73
- sudo wget -O /etc/yum.repos.d/pghero.repo \
74
- https://dl.packager.io/srv/pghero/pghero/master/installer/el/7.repo
75
- sudo yum -y install pghero
76
- ```
77
-
78
- ### SUSE Linux Enterprise Server 12
79
-
80
- ```sh
81
- sudo wget -O /etc/zypp/repos.d/pghero.repo \
82
- https://dl.packager.io/srv/pghero/pghero/master/installer/sles/12.repo
83
- sudo zypper install pghero
84
- ```
85
-
86
- ## Setup
87
-
88
- Add your database.
89
-
90
- ```sh
91
- sudo pghero config:set DATABASE_URL=postgres://user:password@hostname:5432/dbname
92
- ```
93
-
94
- And optional authentication.
95
-
96
- ```sh
97
- sudo pghero config:set PGHERO_USERNAME=link
98
- sudo pghero config:set PGHERO_PASSWORD=hyrule
99
- ```
100
-
101
- Start the server
102
-
103
- ```sh
104
- sudo pghero config:set PORT=3001
105
- sudo pghero config:set RAILS_LOG_TO_STDOUT=disabled
106
- sudo pghero scale web=1
107
- ```
108
-
109
- Confirm it’s running with:
110
-
111
- ```sh
112
- curl -v http://localhost:3001/
113
- ```
114
-
115
- To open to the outside world, add a proxy. Here’s how to do it with Nginx on Ubuntu.
116
-
117
- ```sh
118
- sudo apt-get install -y nginx
119
- cat | sudo tee /etc/nginx/sites-available/default <<EOF
120
- server {
121
- listen 80;
122
- server_name "";
123
- location / {
124
- proxy_pass http://localhost:3001;
125
- }
126
- }
127
- EOF
128
- sudo service nginx restart
129
- ```
130
-
131
- ## Management
132
-
133
- ```sh
134
- sudo service pghero status
135
- sudo service pghero start
136
- sudo service pghero stop
137
- sudo service pghero restart
138
- ```
139
-
140
- View logs
141
-
142
- ```sh
143
- sudo pghero logs
144
- ```
145
-
146
- ## Query Stats
147
-
148
- Query stats can be enabled from the dashboard. If you run into issues, [view the guide](Query-Stats.md).
149
-
150
- ## Historical Query Stats
151
-
152
- To track query stats over time, create a table to store them.
153
-
154
- ```sql
155
- CREATE TABLE "pghero_query_stats" (
156
- "id" serial primary key,
157
- "database" text,
158
- "user" text,
159
- "query" text,
160
- "query_hash" bigint,
161
- "total_time" float,
162
- "calls" bigint,
163
- "captured_at" timestamp
164
- );
165
- CREATE INDEX ON "pghero_query_stats" ("database", "captured_at");
166
- ```
167
-
168
- This table can be in the current database or another database. If another database, run:
169
-
170
- ```sh
171
- sudo pghero config:set PGHERO_STATS_DATABASE_URL=...
172
- ```
173
-
174
- Schedule the task below to run every 5 minutes.
175
-
176
- ```sh
177
- sudo pghero run rake pghero:capture_query_stats
178
- ```
179
-
180
- After this, a time range slider will appear on the Queries tab.
181
-
182
- ## Historical Space Stats
183
-
184
- To track space stats over time, create a table to store them.
185
-
186
- ```sql
187
- CREATE TABLE "pghero_space_stats" (
188
- "id" serial primary key,
189
- "database" text,
190
- "schema" text,
191
- "relation" text,
192
- "size" bigint,
193
- "captured_at" timestamp
194
- );
195
- CREATE INDEX ON "pghero_space_stats" ("database", "captured_at");
196
- ```
197
-
198
- Schedule the task below to run once a day.
199
-
200
- ```sh
201
- sudo pghero run rake pghero:capture_space_stats
202
- ```
203
-
204
- ## System Stats
205
-
206
- CPU usage is available for Amazon RDS. Add these variables to your environment:
207
-
208
- ```sh
209
- sudo pghero config:set PGHERO_ACCESS_KEY_ID=accesskey123
210
- sudo pghero config:set PGHERO_SECRET_ACCESS_KEY=secret123
211
- sudo pghero config:set PGHERO_DB_INSTANCE_IDENTIFIER=epona
212
- ```
213
-
214
- ## Multiple Databases
215
-
216
- Create a `pghero.yml` with:
217
-
218
- ```yml
219
- databases:
220
- primary:
221
- url: postgres://...
222
- replica:
223
- url: postgres://...
224
- ```
225
-
226
- And run:
227
-
228
- ```sh
229
- cat pghero.yml | sudo pghero run sh -c "cat > config/pghero.yml"
230
- sudo service pghero restart
231
- ```
232
-
233
- ## Permissions
234
-
235
- We recommend [setting up a dedicated user](Permissions.md) for PgHero.
236
-
237
- ## Customize
238
-
239
- Minimum time for long running queries
240
-
241
- ```sh
242
- sudo pghero config:set PGHERO_LONG_RUNNING_QUERY_SEC=60 # default
243
- ```
244
-
245
- Minimum average time for slow queries
246
-
247
- ```sh
248
- sudo pghero config:set PGHERO_SLOW_QUERY_MS=20 # default
249
- ```
250
-
251
- Minimum calls for slow queries
252
-
253
- ```sh
254
- sudo pghero config:set PGHERO_SLOW_QUERY_CALLS=100 # default
255
- ```
256
-
257
- Minimum connections for high connections warning
258
-
259
- ```sh
260
- sudo pghero config:set PGHERO_TOTAL_CONNECTIONS_THRESHOLD=100 # default
261
- ```
262
-
263
- Statement timeout for explain
264
-
265
- ```sh
266
- sudo pghero config:set PGHERO_EXPLAIN_TIMEOUT_SEC=10 # default
267
- ````
268
-
269
- ## Upgrading
270
-
271
- Ubuntu and Debian
272
-
273
- ```sh
274
- sudo apt-get update
275
- sudo apt-get install --only-upgrade pghero
276
- sudo service pghero restart
277
- ```
278
-
279
- CentOS and RHEL
280
-
281
- ```sh
282
- sudo yum update
283
- sudo yum install pghero
284
- sudo service pghero restart
285
- ```
286
-
287
- SUSE
288
-
289
- ```sh
290
- sudo zypper update pghero
291
- sudo service pghero restart
292
- ```
293
-
294
- ## Credits
295
-
296
- :heart: Made possible by [Packager](https://packager.io/)