rails-pg-extras 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a24a2db9fa47e0039fc8f53dfe5eebe2bedf1aad770f5806b7a5ffa55a9be04
4
- data.tar.gz: 7004a3d05e7754bfd724457827c80e79c2dccfd6dc60daf59b7ca9097f94ad1a
3
+ metadata.gz: 2a35eb696b77eb6560026bf34ecfcd2e5418beb0c4cee6b414be24510e095d3d
4
+ data.tar.gz: a3db0a5917706994eba4850f267c901988bec5b1a73d2b25e3dd168bbe40d0f9
5
5
  SHA512:
6
- metadata.gz: 66b274e7976f4f4bbf1e8db346ccaf7e44200d58d389ef2f2610ad9435add499fda69f1f7f6f8259d0c17f248d8ef9124e75d1d221a439a281f6be418ad25af2
7
- data.tar.gz: 8d1a2c78e21df1cffdd5cd99a550e2be5b9a44c7ad8f0daed95f92e969020e01ff92fafe183d974aad3ee0d177d0fcf88957cae542a706354d685c25ab2602db
6
+ metadata.gz: 8f506dfeb7e73d5e708e4fbdc3748de4e014882e75c8bf87d7ea1f12910abecbb44d84658b5ab998337552a3249a4b96ea2f42bfcff653e489339cc92737000b
7
+ data.tar.gz: d2c54f07b4f428da96f621a8593a321dac6e87575e82d849245c2403217b14b46fa87851bd2ac5ebdf52ca526e84f2bac125aabcd5c11f81b6102b099f8e42e7
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Rails PG Extras
1
+ # Rails PG Extras [![Gem Version](https://badge.fury.io/rb/rails-pg-extras.svg)](https://badge.fury.io/rb/rails-pg-extras)
2
2
 
3
- Inspired by (a shameless ripoff of) [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras). The goal of this project is to provide a powerful insights into PostgreSQL database for Ruby on Rails apps that are not using the default Heroku PostgreSQL plugin.
3
+ Rails port of [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras). The goal of this project is to provide a powerful insights into PostgreSQL database for Ruby on Rails apps that are not using the default Heroku PostgreSQL plugin.
4
4
 
5
5
  Included rake tasks and Ruby methods can be used to obtain information about a Postgres instance, that may be useful when analyzing performance issues. This includes information about locks, index usage, buffer cache hit ratios and vacuum statistics. Ruby API enables developers to easily integrate the tool into e.g. automatic monitoring tasks.
6
6
 
@@ -16,6 +16,43 @@ gem 'rails-pg-extras'
16
16
 
17
17
  Each command can be used as a rake task, or a directly from the Ruby code.
18
18
 
19
+ ```bash
20
+ rake pg_extras:cache_hit
21
+ ```
22
+
23
+ ```ruby
24
+ RailsPGExtras.cache_hit
25
+ ```
26
+ ```bash
27
+ +----------------+------------------------+
28
+ | Index and table hit rate |
29
+ +----------------+------------------------+
30
+ | name | ratio |
31
+ +----------------+------------------------+
32
+ | index hit rate | 0.97796610169491525424 |
33
+ | table hit rate | 0.96724294813466787989 |
34
+ +----------------+------------------------+
35
+ ```
36
+
37
+
38
+ By default the ASCII table is displayed, to change to format you need to specify the `in_format` parameter (`[:display_table, :hash, :array, :raw]` options are available):
39
+
40
+ ```ruby
41
+ RailsPGExtras.cache_hit(in_format: :hash) =>
42
+
43
+ [{"name"=>"index hit rate", "ratio"=>"0.97796610169491525424"}, {"name"=>"table hit rate", "ratio"=>"0.96724294813466787989"}]
44
+
45
+ RailsPGExtras.cache_hit(in_format: :array) =>
46
+
47
+ [["index hit rate", "0.97796610169491525424"], ["table hit rate", "0.96724294813466787989"]]
48
+
49
+ RailsPGExtras.cache_hit(in_format: :raw) =>
50
+
51
+ #<PG::Result:0x00007f75777f7328 status=PGRES_TUPLES_OK ntuples=2 nfields=2 cmd_tuples=2>
52
+ ```
53
+
54
+ ### Available methods
55
+
19
56
  #### `cache_hit`
20
57
 
21
58
  ```bash
@@ -62,7 +99,15 @@ $ rake pg_extras:locks
62
99
 
63
100
  This command displays queries that have taken out an exlusive lock on a relation. Exclusive locks typically prevent other operations on that relation from taking place, and can be a cause of "hung" queries that are waiting for a lock to be granted.
64
101
 
65
- ### `pg:outliers`
102
+ ### `all_locks`
103
+
104
+ ```
105
+ $ rake pg_extras:all_locks
106
+ ```
107
+
108
+ This command displays all the current locks, regardless of their type.
109
+
110
+ ### `outliers`
66
111
 
67
112
  ```
68
113
  $ rake pg_extras:outliers
@@ -309,7 +354,7 @@ $ rake pg_extras:vacuum_stats
309
354
 
310
355
  This command displays statistics related to vacuum operations for each table, including an estiamtion of dead rows, last autovacuum and the current autovacuum threshold. This command can be useful when determining if current vacuum thresholds require adjustments, and to determine when the table was last vacuumed.
311
356
 
312
- ### pg:mandelbrot
357
+ ### mandelbrot
313
358
 
314
359
  ```
315
360
  $ rake pg_extras:mandelbrot
@@ -322,3 +367,7 @@ This command outputs the Mandelbrot set, calculated through SQL.
322
367
  * Does is not violate the Heroku PG Extras license?
323
368
 
324
369
  The original plugin is [MIT based](https://github.com/heroku/heroku-pg-extras/blob/master/LICENSE) so it means that copying and redistribution in any format is permitted.
370
+
371
+ ## Disclaimer
372
+
373
+ This tool is in beta state.
@@ -6,7 +6,7 @@ module RailsPGExtras
6
6
  QUERIES = %i(
7
7
  bloat blocking cache_hit
8
8
  calls extensions
9
- index_size index_usage locks
9
+ index_size index_usage locks all_locks
10
10
  long_running_queries mandelbrot outliers
11
11
  records_rank seq_scans table_indexes_size
12
12
  table_size total_index_size total_table_size
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ def self.locks_description
5
+ "Queries with active locks"
6
+ end
7
+
8
+ def self.locks_sql
9
+ <<-EOS
10
+ SELECT
11
+ pg_stat_activity.pid,
12
+ pg_class.relname,
13
+ pg_locks.transactionid,
14
+ pg_locks.granted,
15
+ pg_locks.mode,
16
+ pg_stat_activity.query AS query_snippet,
17
+ age(now(),pg_stat_activity.query_start) AS "age"
18
+ FROM pg_stat_activity,pg_locks left
19
+ OUTER JOIN pg_class
20
+ ON (pg_locks.relation = pg_class.oid)
21
+ WHERE pg_stat_activity.query <> '<insufficient privilege>'
22
+ AND pg_locks.pid = pg_stat_activity.pid
23
+ AND pg_stat_activity.pid <> pg_backend_pid() order by query_start;
24
+ EOS
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsPGExtras
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-25 00:00:00.000000000 Z
11
+ date: 2019-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -51,10 +51,8 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
- - coverage/.last_run.json
55
- - coverage/.resultset.json
56
- - coverage/.resultset.json.lock
57
54
  - lib/rails-pg-extras.rb
55
+ - lib/rails-pg-extras/queries/all_locks.rb
58
56
  - lib/rails-pg-extras/queries/bloat.rb
59
57
  - lib/rails-pg-extras/queries/blocking.rb
60
58
  - lib/rails-pg-extras/queries/cache_hit.rb
@@ -1,5 +0,0 @@
1
- {
2
- "result": {
3
- "covered_percent": 95.19
4
- }
5
- }
@@ -1,587 +0,0 @@
1
- {
2
- "RSpec": {
3
- "coverage": {
4
- "/Users/pablo/Programming/Ruby/termit/lib/termit.rb": [
5
- 1,
6
- 1,
7
- 1,
8
- 1,
9
- 1,
10
- 1,
11
- 1,
12
- 1,
13
- 1,
14
- 1,
15
- 1,
16
- 1,
17
- 1,
18
- 1,
19
- null,
20
- 1,
21
- null
22
- ],
23
- "/Users/pablo/Programming/Ruby/termit/lib/termit/output_manager.rb": [
24
- null,
25
- 1,
26
- 1,
27
- 1,
28
- 2,
29
- 2,
30
- null,
31
- null,
32
- 1,
33
- 1,
34
- 1,
35
- null,
36
- 1,
37
- null,
38
- 0,
39
- null,
40
- 1,
41
- null,
42
- null,
43
- 1,
44
- 3,
45
- null,
46
- null,
47
- null,
48
- null,
49
- null,
50
- null,
51
- null,
52
- null,
53
- null,
54
- null,
55
- null,
56
- null,
57
- null,
58
- 3,
59
- null,
60
- null,
61
- null,
62
- 1,
63
- 2,
64
- 2,
65
- null,
66
- null,
67
- 1,
68
- 3,
69
- 3,
70
- null,
71
- null,
72
- 1,
73
- 0,
74
- 0,
75
- null,
76
- null,
77
- 1,
78
- 0,
79
- 0,
80
- null,
81
- null,
82
- null
83
- ],
84
- "/Users/pablo/Programming/Ruby/termit/lib/termit/can_output.rb": [
85
- 1,
86
- 1,
87
- 1,
88
- 4,
89
- null,
90
- null,
91
- 1,
92
- null,
93
- 1,
94
- 8,
95
- null,
96
- null,
97
- null
98
- ],
99
- "/Users/pablo/Programming/Ruby/termit/lib/termit/user_input_parser.rb": [
100
- null,
101
- 1,
102
- 1,
103
- 1,
104
- null,
105
- 1,
106
- null,
107
- 1,
108
- 7,
109
- 7,
110
- 4,
111
- null,
112
- 1,
113
- null,
114
- null,
115
- 1,
116
- 3,
117
- null,
118
- null,
119
- 1,
120
- null,
121
- 1,
122
- null,
123
- null,
124
- null,
125
- null,
126
- null,
127
- 3,
128
- null,
129
- null,
130
- 1,
131
- 3,
132
- 3,
133
- null,
134
- null,
135
- 1,
136
- 4,
137
- 4,
138
- 4,
139
- 8,
140
- null,
141
- null,
142
- null,
143
- 1,
144
- 7,
145
- 5,
146
- null,
147
- null,
148
- null
149
- ],
150
- "/Users/pablo/Programming/Ruby/termit/lib/termit/main.rb": [
151
- null,
152
- 1,
153
- 1,
154
- 1,
155
- 2,
156
- null,
157
- null,
158
- 1,
159
- 2,
160
- 2,
161
- 2,
162
- null,
163
- null,
164
- 1,
165
- null,
166
- 1,
167
- 1,
168
- 1,
169
- null,
170
- null,
171
- null
172
- ],
173
- "/Users/pablo/Programming/Ruby/termit/lib/termit/sound_response_handler.rb": [
174
- null,
175
- 1,
176
- null,
177
- 1,
178
- 1,
179
- 1,
180
- 1,
181
- null,
182
- null,
183
- 1,
184
- 1,
185
- 1,
186
- 1,
187
- 0,
188
- null,
189
- 1,
190
- null,
191
- null,
192
- 1,
193
- null,
194
- 1,
195
- 1,
196
- null,
197
- null,
198
- null
199
- ],
200
- "/Users/pablo/Programming/Ruby/termit/lib/termit/text_translator.rb": [
201
- null,
202
- 1,
203
- 1,
204
- 1,
205
- null,
206
- 1,
207
- 2,
208
- 2,
209
- null,
210
- null,
211
- 1,
212
- 2,
213
- 2,
214
- null,
215
- null,
216
- null
217
- ],
218
- "/Users/pablo/Programming/Ruby/termit/lib/termit/speech_synthesizer.rb": [
219
- null,
220
- 1,
221
- 1,
222
- 1,
223
- 1,
224
- null,
225
- 1,
226
- 2,
227
- 2,
228
- 2,
229
- null,
230
- null,
231
- 1,
232
- 2,
233
- 2,
234
- null,
235
- null,
236
- 1,
237
- null,
238
- 1,
239
- 1,
240
- 1,
241
- null,
242
- null,
243
- null,
244
- null
245
- ],
246
- "/Users/pablo/Programming/Ruby/termit/lib/termit/url_constructor.rb": [
247
- null,
248
- null,
249
- 1,
250
- 1,
251
- 1,
252
- null,
253
- 1,
254
- 6,
255
- null,
256
- null,
257
- 1,
258
- 6,
259
- null,
260
- null,
261
- 1,
262
- null,
263
- 1,
264
- 5,
265
- null,
266
- null,
267
- 1,
268
- 1,
269
- null,
270
- null,
271
- 1,
272
- 1,
273
- 0,
274
- 1,
275
- 0,
276
- 1,
277
- 0,
278
- null,
279
- 1,
280
- null,
281
- null,
282
- null,
283
- null
284
- ],
285
- "/Users/pablo/Programming/Ruby/termit/lib/termit/data_fetcher_base.rb": [
286
- null,
287
- 1,
288
- null,
289
- 1,
290
- 1,
291
- 1,
292
- 1,
293
- 1,
294
- null,
295
- 1,
296
- 2,
297
- 2,
298
- null,
299
- null,
300
- 1,
301
- 2,
302
- null,
303
- 0,
304
- 0,
305
- null,
306
- 0,
307
- 0,
308
- null,
309
- null,
310
- 1,
311
- null,
312
- 1,
313
- null,
314
- 1,
315
- null,
316
- null,
317
- null,
318
- null,
319
- null,
320
- null,
321
- 1,
322
- 1,
323
- 1,
324
- 1,
325
- null,
326
- 2,
327
- null,
328
- null,
329
- null
330
- ],
331
- "/Users/pablo/Programming/Ruby/termit/lib/termit/text_fetcher.rb": [
332
- null,
333
- null,
334
- 1,
335
- 1,
336
- 1,
337
- null,
338
- 1,
339
- 2,
340
- null,
341
- null,
342
- null,
343
- null,
344
- null,
345
- null,
346
- null,
347
- null,
348
- 1,
349
- 2,
350
- null,
351
- null,
352
- null
353
- ],
354
- "/Users/pablo/Programming/Ruby/termit/lib/termit/sound_fetcher.rb": [
355
- null,
356
- null,
357
- 1,
358
- 1,
359
- 1,
360
- null,
361
- 1,
362
- 0,
363
- null,
364
- null,
365
- null,
366
- null,
367
- null,
368
- null
369
- ],
370
- "/Users/pablo/Programming/Ruby/termit/lib/termit/text_response_handler.rb": [
371
- null,
372
- 1,
373
- null,
374
- 1,
375
- 1,
376
- 1,
377
- 1,
378
- null,
379
- 1,
380
- 3,
381
- null,
382
- null,
383
- 1,
384
- 3,
385
- 3,
386
- 3,
387
- null,
388
- null,
389
- 1,
390
- null,
391
- 1,
392
- 3,
393
- null,
394
- null,
395
- 1,
396
- 3,
397
- 3,
398
- 3,
399
- null,
400
- null,
401
- null
402
- ],
403
- "/Users/pablo/Programming/Ruby/termit/spec/termit/output_manager_spec.rb": [
404
- null,
405
- 1,
406
- null,
407
- 1,
408
- 1,
409
- 2,
410
- null,
411
- 1,
412
- 1,
413
- 1,
414
- 8,
415
- null,
416
- null,
417
- null,
418
- null
419
- ],
420
- "/Users/pablo/Programming/Ruby/termit/spec/termit/sound_response_handler_spec.rb": [
421
- null,
422
- 1,
423
- null,
424
- 1,
425
- 1,
426
- 2,
427
- 2,
428
- null,
429
- 1,
430
- 1,
431
- 1,
432
- 1,
433
- null,
434
- null,
435
- null
436
- ],
437
- "/Users/pablo/Programming/Ruby/termit/spec/termit/speech_synthesizer_spec.rb": [
438
- null,
439
- 1,
440
- null,
441
- 1,
442
- 1,
443
- 1,
444
- 2,
445
- 2,
446
- 2,
447
- 4,
448
- 4,
449
- null,
450
- null,
451
- 1,
452
- 1,
453
- 2,
454
- 1,
455
- 1,
456
- null,
457
- null,
458
- null,
459
- 1,
460
- 1,
461
- 2,
462
- null,
463
- 1,
464
- 1,
465
- 1,
466
- null,
467
- null,
468
- null,
469
- null
470
- ],
471
- "/Users/pablo/Programming/Ruby/termit/spec/termit/text_response_handler_spec.rb": [
472
- null,
473
- 1,
474
- null,
475
- 1,
476
- 1,
477
- 1,
478
- 1,
479
- 1,
480
- null,
481
- null,
482
- 1,
483
- 1,
484
- 1,
485
- null,
486
- null,
487
- null
488
- ],
489
- "/Users/pablo/Programming/Ruby/termit/spec/termit/text_translator_spec.rb": [
490
- null,
491
- 1,
492
- null,
493
- 1,
494
- 1,
495
- 1,
496
- 1,
497
- 1,
498
- 1,
499
- 1,
500
- null,
501
- null,
502
- null,
503
- null,
504
- 1,
505
- 1,
506
- 1,
507
- 1,
508
- 1,
509
- 1,
510
- null,
511
- null,
512
- null,
513
- null
514
- ],
515
- "/Users/pablo/Programming/Ruby/termit/spec/termit/url_constructor_spec.rb": [
516
- null,
517
- 1,
518
- null,
519
- 1,
520
- 1,
521
- 1,
522
- 1,
523
- 1,
524
- 1,
525
- null,
526
- 1,
527
- null,
528
- null,
529
- null,
530
- 1,
531
- 1,
532
- 1,
533
- 1,
534
- 1,
535
- null,
536
- null,
537
- null,
538
- null
539
- ],
540
- "/Users/pablo/Programming/Ruby/termit/spec/termit/user_input_parser_spec.rb": [
541
- null,
542
- 1,
543
- null,
544
- 1,
545
- 1,
546
- 1,
547
- 1,
548
- 2,
549
- null,
550
- null,
551
- null,
552
- 1,
553
- 1,
554
- 1,
555
- 1,
556
- null,
557
- null,
558
- 1,
559
- 2,
560
- null,
561
- null,
562
- 1,
563
- 2,
564
- null,
565
- null,
566
- null,
567
- 1,
568
- 1,
569
- 1,
570
- null,
571
- null,
572
- 1,
573
- 1,
574
- 1,
575
- null,
576
- null,
577
- 1,
578
- 2,
579
- null,
580
- null,
581
- null,
582
- null
583
- ]
584
- },
585
- "timestamp": 1495699232
586
- }
587
- }
File without changes