rails-pg-extras 1.4.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +153 -30
- data/lib/rails-pg-extras/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b44baf89a4349ef720b371a8a83a8397e0e848794b1bf248398cfd19c5f606d5
|
4
|
+
data.tar.gz: ebdabe9d275ed5ef7132ce604f894a42520226db0b1dc5d50acd092a0aed6dd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b9e1505835974df1959e620385461f7c5c92838efadd18abb57a5656d1b942d8f097f7c70389e815a96a5dcb239b67b16cee430188e0532ccef57eb2a6ff50
|
7
|
+
data.tar.gz: 269a9b8bb29c5114c43885d61f849b3ed73664cb7c5e9e772c85281cacebbce641b224fe0e246bda5a7ab5426210ee3a75a0ac0a36c6555abb64988d7b66b733
|
data/README.md
CHANGED
@@ -89,7 +89,9 @@ RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
|
|
89
89
|
|
90
90
|
### `cache_hit`
|
91
91
|
|
92
|
-
```
|
92
|
+
```ruby
|
93
|
+
RailsPGExtras.cache_hit
|
94
|
+
|
93
95
|
$ rake pg_extras:cache_hit
|
94
96
|
|
95
97
|
name | ratio
|
@@ -101,9 +103,13 @@ $ rake pg_extras:cache_hit
|
|
101
103
|
|
102
104
|
This command provides information on the efficiency of the buffer cache, for both index reads (`index hit rate`) as well as table reads (`table hit rate`). A low buffer cache hit ratio can be a sign that the Postgres instance is too small for the workload.
|
103
105
|
|
106
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
107
|
+
|
104
108
|
### `index_cache_hit`
|
105
109
|
|
106
|
-
```
|
110
|
+
```ruby
|
111
|
+
|
112
|
+
RailsPGExtras.index_cache_hit
|
107
113
|
|
108
114
|
$ rake pg_extras:index_cache_hit
|
109
115
|
|
@@ -117,9 +123,13 @@ $ rake pg_extras:index_cache_hit
|
|
117
123
|
|
118
124
|
The same as `cache_hit` with each table's indexes cache hit info displayed separately.
|
119
125
|
|
126
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
127
|
+
|
120
128
|
### `table_cache_hit`
|
121
129
|
|
122
|
-
```
|
130
|
+
```ruby
|
131
|
+
|
132
|
+
RailsPGExtras.table_cache_hit
|
123
133
|
|
124
134
|
$ rake pg_extras:table_cache_hit
|
125
135
|
|
@@ -133,9 +143,35 @@ $ rake pg_extras:table_cache_hit
|
|
133
143
|
|
134
144
|
The same as `cache_hit` with each table's cache hit info displayed seperately.
|
135
145
|
|
136
|
-
|
146
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
147
|
+
|
148
|
+
### `db_settings`
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
|
152
|
+
RailsPGExtras.db_settings
|
153
|
+
|
154
|
+
$ rake pg_extras:db_settings
|
155
|
+
|
156
|
+
name | setting | unit |
|
157
|
+
------------------------------+---------+------+
|
158
|
+
checkpoint_completion_target | 0.7 | |
|
159
|
+
default_statistics_target | 100 | |
|
160
|
+
effective_cache_size | 1350000 | 8kB |
|
161
|
+
effective_io_concurrency | 1 | |
|
162
|
+
(truncated results for brevity)
|
137
163
|
|
138
164
|
```
|
165
|
+
|
166
|
+
This method displays values for selected PostgreSQL settings. You can compare them with settings recommended by [PGTune](https://pgtune.leopard.in.ua/#/) and tweak values to improve performance.
|
167
|
+
|
168
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
169
|
+
|
170
|
+
### `index_usage`
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
RailsPGExtras.index_usage
|
174
|
+
|
139
175
|
$ rake pg_extras:index_usage
|
140
176
|
|
141
177
|
relname | percent_of_times_index_used | rows_in_table
|
@@ -152,7 +188,9 @@ This command provides information on the efficiency of indexes, represented as w
|
|
152
188
|
|
153
189
|
### `locks`
|
154
190
|
|
155
|
-
```
|
191
|
+
```ruby
|
192
|
+
RailsPGExtras.locks
|
193
|
+
|
156
194
|
$ rake pg_extras:locks
|
157
195
|
|
158
196
|
procpid | relname | transactionid | granted | query_snippet | mode | age
|
@@ -168,9 +206,13 @@ $ rake pg_extras:locks
|
|
168
206
|
|
169
207
|
This command displays queries that have taken out an exclusive 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.
|
170
208
|
|
209
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#deadlocks)
|
210
|
+
|
171
211
|
### `all_locks`
|
172
212
|
|
173
|
-
```
|
213
|
+
```ruby
|
214
|
+
RailsPGExtras.all_locks
|
215
|
+
|
174
216
|
$ rake pg_extras:all_locks
|
175
217
|
```
|
176
218
|
|
@@ -178,7 +220,9 @@ This command displays all the current locks, regardless of their type.
|
|
178
220
|
|
179
221
|
### `outliers`
|
180
222
|
|
181
|
-
```
|
223
|
+
```ruby
|
224
|
+
RailsPGExtras.outliers(args: { limit: 20 })
|
225
|
+
|
182
226
|
$ rake pg_extras:outliers
|
183
227
|
|
184
228
|
qry | exec_time | prop_exec_time | ncalls | sync_io_time
|
@@ -196,9 +240,13 @@ This command displays statements, obtained from `pg_stat_statements`, ordered by
|
|
196
240
|
|
197
241
|
Typically, an efficient query will have an appropriate ratio of calls to total execution time, with as little time spent on I/O as possible. Queries that have a high total execution time but low call count should be investigated to improve their performance. Queries that have a high proportion of execution time being spent on synchronous I/O should also be investigated.
|
198
242
|
|
243
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
244
|
+
|
199
245
|
### `calls`
|
200
246
|
|
201
|
-
```
|
247
|
+
```ruby
|
248
|
+
RailsPGExtras.calls(args: { limit: 10 })
|
249
|
+
|
202
250
|
$ rake pg_extras:calls
|
203
251
|
|
204
252
|
qry | exec_time | prop_exec_time | ncalls | sync_io_time
|
@@ -213,9 +261,13 @@ $ rake pg_extras:calls
|
|
213
261
|
|
214
262
|
This command is much like `pg:outliers`, but ordered by the number of times a statement has been called.
|
215
263
|
|
264
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
265
|
+
|
216
266
|
### `blocking`
|
217
267
|
|
218
|
-
```
|
268
|
+
```ruby
|
269
|
+
RailsPGExtras.blocking
|
270
|
+
|
219
271
|
$ rake pg_extras:blocking
|
220
272
|
|
221
273
|
blocked_pid | blocking_statement | blocking_duration | blocking_pid | blocked_statement | blocked_duration
|
@@ -226,9 +278,13 @@ $ rake pg_extras:blocking
|
|
226
278
|
|
227
279
|
This command displays statements that are currently holding locks that other statements are waiting to be released. This can be used in conjunction with `pg:locks` to determine which statements need to be terminated in order to resolve lock contention.
|
228
280
|
|
229
|
-
|
281
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#deadlocks)
|
282
|
+
|
283
|
+
### `total_index_size`
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
RailsPGExtras.total_index_size
|
230
287
|
|
231
|
-
```
|
232
288
|
$ rake pg_extras:total_index_size
|
233
289
|
|
234
290
|
size
|
@@ -241,7 +297,9 @@ This command displays the total size of all indexes on the database, in MB. It i
|
|
241
297
|
|
242
298
|
### `index_size`
|
243
299
|
|
244
|
-
```
|
300
|
+
```ruby
|
301
|
+
RailsPGExtras.index_size
|
302
|
+
|
245
303
|
$ rake pg_extras:index_size
|
246
304
|
name | size
|
247
305
|
---------------------------------------------------------------+---------
|
@@ -262,7 +320,9 @@ This command displays the size of each each index in the database, in MB. It is
|
|
262
320
|
|
263
321
|
### `table_size`
|
264
322
|
|
265
|
-
```
|
323
|
+
```ruby
|
324
|
+
RailsPGExtras.table_size
|
325
|
+
|
266
326
|
$ rake pg_extras:table_size
|
267
327
|
|
268
328
|
name | size
|
@@ -279,7 +339,9 @@ This command displays the size of each table and materialized view in the databa
|
|
279
339
|
|
280
340
|
### `table_indexes_size`
|
281
341
|
|
282
|
-
```
|
342
|
+
```ruby
|
343
|
+
RailsPGExtras.table_indexes_size
|
344
|
+
|
283
345
|
$ rake pg_extras:table_indexes_size
|
284
346
|
|
285
347
|
table | indexes_size
|
@@ -296,7 +358,9 @@ This command displays the total size of indexes for each table and materialized
|
|
296
358
|
|
297
359
|
### `total_table_size`
|
298
360
|
|
299
|
-
```
|
361
|
+
```ruby
|
362
|
+
RailsPGExtras.total_table_size
|
363
|
+
|
300
364
|
$ rake pg_extras:total_table_size
|
301
365
|
|
302
366
|
name | size
|
@@ -313,7 +377,9 @@ This command displays the total size of each table and materialized view in the
|
|
313
377
|
|
314
378
|
### `unused_indexes`
|
315
379
|
|
316
|
-
```
|
380
|
+
```ruby
|
381
|
+
RailsPGExtras.unused_indexes(args: { min_scans: 20 })
|
382
|
+
|
317
383
|
$ rake pg_extras:unused_indexes
|
318
384
|
|
319
385
|
table | index | index_size | index_scans
|
@@ -326,9 +392,33 @@ $ rake pg_extras:unused_indexes
|
|
326
392
|
|
327
393
|
This command displays indexes that have < 50 scans recorded against them, and are greater than 5 pages in size, ordered by size relative to the number of index scans. This command is generally useful for eliminating indexes that are unused, which can impact write performance, as well as read performance should they occupy space in memory.
|
328
394
|
|
329
|
-
|
395
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#unused-indexes)
|
396
|
+
|
397
|
+
### `null_indexes`
|
398
|
+
|
399
|
+
```ruby
|
400
|
+
|
401
|
+
RailsPGExtras.null_indexes(args: { min_relation_size_mb: 10 })
|
402
|
+
|
403
|
+
$ rake pg_extras:null_indexes
|
404
|
+
|
405
|
+
oid | index | index_size | unique | indexed_column | null_frac | expected_saving
|
406
|
+
---------+--------------------+------------+--------+----------------+-----------+-----------------
|
407
|
+
183764 | users_reset_token | 1445 MB | t | reset_token | 97.00% | 1401 MB
|
408
|
+
88732 | plan_cancelled_at | 539 MB | f | cancelled_at | 8.30% | 44 MB
|
409
|
+
9827345 | users_email | 18 MB | t | email | 28.67% | 5160 kB
|
330
410
|
|
331
411
|
```
|
412
|
+
|
413
|
+
This command displays indexes that contain `NULL` values. A high ratio of `NULL` values means that using a partial index excluding them will be beneficial in case they are not used for searching.
|
414
|
+
|
415
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#null-indexes)
|
416
|
+
|
417
|
+
### `seq_scans`
|
418
|
+
|
419
|
+
```ruby
|
420
|
+
RailsPGExtras.seq_scans
|
421
|
+
|
332
422
|
$ rake pg_extras:seq_scans
|
333
423
|
|
334
424
|
name | count
|
@@ -341,22 +431,18 @@ $ rake pg_extras:seq_scans
|
|
341
431
|
messages | 3922247
|
342
432
|
contests_customers | 2915972
|
343
433
|
classroom_goals | 2142014
|
344
|
-
contests | 1370267
|
345
|
-
goals | 1112659
|
346
|
-
districts | 158995
|
347
|
-
rollup_reports | 115942
|
348
|
-
customers | 93847
|
349
|
-
schools | 92984
|
350
|
-
classrooms | 92982
|
351
|
-
customer_settings | 91226
|
352
434
|
(truncated results for brevity)
|
353
435
|
```
|
354
436
|
|
355
437
|
This command displays the number of sequential scans recorded against all tables, descending by count of sequential scans. Tables that have very high numbers of sequential scans may be under-indexed, and it may be worth investigating queries that read from these tables.
|
356
438
|
|
439
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
440
|
+
|
357
441
|
### `long_running_queries`
|
358
442
|
|
359
|
-
```
|
443
|
+
```ruby
|
444
|
+
RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
|
445
|
+
|
360
446
|
$ rake pg_extras:long_running_queries
|
361
447
|
|
362
448
|
pid | duration | query
|
@@ -371,7 +457,9 @@ This command displays currently running queries, that have been running for long
|
|
371
457
|
|
372
458
|
### `records_rank`
|
373
459
|
|
374
|
-
```
|
460
|
+
```ruby
|
461
|
+
RailsPGExtras.records_rank
|
462
|
+
|
375
463
|
$ rake pg_extras:records_rank
|
376
464
|
|
377
465
|
name | estimated_count
|
@@ -389,7 +477,9 @@ This command displays an estimated count of rows per table, descending by estima
|
|
389
477
|
|
390
478
|
### `bloat`
|
391
479
|
|
392
|
-
```
|
480
|
+
```ruby
|
481
|
+
RailsPGExtras.bloat
|
482
|
+
|
393
483
|
$ rake pg_extras:bloat
|
394
484
|
|
395
485
|
type | schemaname | object_name | bloat | waste
|
@@ -404,9 +494,13 @@ $ rake pg_extras:bloat
|
|
404
494
|
|
405
495
|
This command displays an estimation of table "bloat" – space allocated to a relation that is full of dead tuples, that has yet to be reclaimed. Tables that have a high bloat ratio, typically 10 or greater, should be investigated to see if vacuuming is aggressive enough, and can be a sign of high table churn.
|
406
496
|
|
497
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#bloat)
|
498
|
+
|
407
499
|
### `vacuum_stats`
|
408
500
|
|
409
|
-
```
|
501
|
+
```ruby
|
502
|
+
RailsPGExtras.vacuum_stats
|
503
|
+
|
410
504
|
$ rake pg_extras:vacuum_stats
|
411
505
|
|
412
506
|
schema | table | last_vacuum | last_autovacuum | rowcount | dead_rowcount | autovacuum_threshold | expect_autovacuum
|
@@ -430,20 +524,49 @@ RailsPGExtras.kill_all
|
|
430
524
|
|
431
525
|
This commands kills all the currently active connections to the database. It can be useful as a last resort when your database is stuck in a deadlock.
|
432
526
|
|
527
|
+
### `buffercache_stats`
|
528
|
+
|
529
|
+
This command shows the relations buffered in database share buffer, ordered by percentage taken. It also shows that how much of the whole relation is buffered.
|
530
|
+
|
531
|
+
```ruby
|
532
|
+
RailsPGExtras.buffercache_stats(args: { limit: 10 })
|
533
|
+
```
|
534
|
+
|
535
|
+
### `buffercache_usage`
|
536
|
+
|
537
|
+
This command calculates how many blocks from which table are currently cached.
|
538
|
+
|
539
|
+
```ruby
|
540
|
+
RailsPGExtras.buffercache_usage(args: { limit: 20 })
|
541
|
+
```
|
542
|
+
|
433
543
|
### `extensions`
|
434
544
|
|
435
545
|
```ruby
|
436
546
|
|
437
547
|
RailsPGExtras.extensions
|
438
548
|
|
549
|
+
$ rake pg_extras:extensions
|
550
|
+
|
551
|
+
| pg_stat_statements | 1.7 | 1.7 | track execution statistics of all SQL statements executed
|
552
|
+
(truncated results for brevity)
|
553
|
+
|
439
554
|
```
|
440
555
|
|
441
556
|
This command lists all the currently installed and available PostgreSQL extensions.
|
442
557
|
|
443
558
|
### mandelbrot
|
444
559
|
|
445
|
-
```
|
560
|
+
```ruby
|
561
|
+
RailsPGExtras.mandelbrot
|
562
|
+
|
446
563
|
$ rake pg_extras:mandelbrot
|
447
564
|
```
|
448
565
|
|
449
566
|
This command outputs the Mandelbrot set, calculated through SQL.
|
567
|
+
|
568
|
+
## Query sources
|
569
|
+
|
570
|
+
- [https://github.com/heroku/heroku-pg-extras](https://github.com/heroku/heroku-pg-extras)
|
571
|
+
- [https://hakibenita.com/postgresql-unused-index-size](https://hakibenita.com/postgresql-unused-index-size)
|
572
|
+
- [https://sites.google.com/site/itmyshare/database-tips-and-examples/postgres/useful-sqls-to-check-contents-of-postgresql-shared_buffer](https://sites.google.com/site/itmyshare/database-tips-and-examples/postgres/useful-sqls-to-check-contents-of-postgresql-shared_buffer)
|
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: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-pg-extras
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|