rails-pg-extras 1.5.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +32 -5
- data/README.md +132 -47
- data/Rakefile +5 -0
- data/docker-compose.yml.sample +20 -2
- data/lib/rails-pg-extras/version.rb +1 -1
- data/lib/rails-pg-extras.rb +11 -2
- data/rails-pg-extras-web.png +0 -0
- data/spec/smoke_spec.rb +5 -2
- data/spec/spec_helper.rb +13 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91474e6c121e4a84110dd1b7fb9724012627696625d08ce73c38eb27b0398636
|
4
|
+
data.tar.gz: 50971a690cc8b350d1caf20d43776c7ff6b1927d394e55316a2203e9a00b1d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3880fcea5eed8f047dcbfc733836b8f93f220b139a96a6b20f64e11f90de338fa0489b7644fc632df2b6947332692c4a78ec17f35124a7eb4f5a7931cfb2dab6
|
7
|
+
data.tar.gz: 148f28f307696d2d08acb81d4c61b8ed75bfc31823670bcd669b12a9eb37593d1081a0fe8959a6f11622426f3a4021b0226d99728f61be751915a6f7a7b57ad2
|
data/.circleci/config.yml
CHANGED
@@ -6,6 +6,22 @@ jobs:
|
|
6
6
|
environment:
|
7
7
|
DATABASE_URL: postgresql://postgres:secret@localhost:5432/rails-pg-extras-test
|
8
8
|
- image: circleci/postgres:11.5
|
9
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
10
|
+
name: postgres11
|
11
|
+
environment:
|
12
|
+
POSTGRES_USER: postgres
|
13
|
+
POSTGRES_DB: rails-pg-extras-test
|
14
|
+
POSTGRES_PASSWORD: secret
|
15
|
+
- image: circleci/postgres:12.7
|
16
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
17
|
+
name: postgres12
|
18
|
+
environment:
|
19
|
+
POSTGRES_USER: postgres
|
20
|
+
POSTGRES_DB: rails-pg-extras-test
|
21
|
+
POSTGRES_PASSWORD: secret
|
22
|
+
- image: circleci/postgres:13.3
|
23
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
24
|
+
name: postgres13
|
9
25
|
environment:
|
10
26
|
POSTGRES_USER: postgres
|
11
27
|
POSTGRES_DB: rails-pg-extras-test
|
@@ -16,13 +32,24 @@ jobs:
|
|
16
32
|
- run: gem update --system
|
17
33
|
- run: gem install bundler
|
18
34
|
- run: bundle install --path vendor/bundle
|
19
|
-
- run: sudo apt-get update
|
35
|
+
- run: sudo apt-get update --allow-releaseinfo-change
|
20
36
|
- run: sudo apt install postgresql-client
|
21
|
-
- run: dockerize -wait tcp://
|
37
|
+
- run: dockerize -wait tcp://postgres11:5432 -timeout 1m
|
38
|
+
- run:
|
39
|
+
name: Run specs for PG 11
|
40
|
+
environment:
|
41
|
+
DATABASE_URL: postgresql://postgres:secret@postgres11:5432/rails-pg-extras-test
|
42
|
+
command: bundle exec rspec spec/
|
43
|
+
- run:
|
44
|
+
name: Run specs for PG 12
|
45
|
+
environment:
|
46
|
+
DATABASE_URL: postgresql://postgres:secret@postgres12:5432/rails-pg-extras-test
|
47
|
+
command: bundle exec rspec spec/
|
22
48
|
- run:
|
23
|
-
name: Run specs
|
24
|
-
|
25
|
-
|
49
|
+
name: Run specs for PG 13
|
50
|
+
environment:
|
51
|
+
DATABASE_URL: postgresql://postgres:secret@postgres13:5432/rails-pg-extras-test
|
52
|
+
command: bundle exec rspec spec/
|
26
53
|
workflows:
|
27
54
|
version: 2
|
28
55
|
test:
|
data/README.md
CHANGED
@@ -4,7 +4,13 @@ Rails port of [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras) wit
|
|
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
|
|
7
|
-
You can
|
7
|
+
You can read this blog post for detailed step by step tutorial on how to [optimize PostgreSQL using PG Extras library](https://pawelurbanek.com/postgresql-fix-performance).
|
8
|
+
|
9
|
+
**Shameless plug:** rails-pg-extras is one of the tools that I use when conducting Rails performance audits. [Check out my offer](https://pawelurbanek.com/#rails-performance-tuning) if you need help with fine-tuning your app.
|
10
|
+
|
11
|
+
Use [rails-pg-extras-web](https://github.com/defkode/rails-pg-extras-web) if you want to see SQL metrics in the UI instead of a command line interface.
|
12
|
+
|
13
|
+
![Web interface](https://github.com/pawurb/rails-pg-extras/raw/master/rails-pg-extras-web.png)
|
8
14
|
|
9
15
|
Alternative versions:
|
10
16
|
|
@@ -89,7 +95,7 @@ RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
|
|
89
95
|
|
90
96
|
### `cache_hit`
|
91
97
|
|
92
|
-
```
|
98
|
+
```ruby
|
93
99
|
RailsPGExtras.cache_hit
|
94
100
|
|
95
101
|
$ rake pg_extras:cache_hit
|
@@ -103,9 +109,11 @@ $ rake pg_extras:cache_hit
|
|
103
109
|
|
104
110
|
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.
|
105
111
|
|
112
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
113
|
+
|
106
114
|
### `index_cache_hit`
|
107
115
|
|
108
|
-
```
|
116
|
+
```ruby
|
109
117
|
|
110
118
|
RailsPGExtras.index_cache_hit
|
111
119
|
|
@@ -121,9 +129,11 @@ $ rake pg_extras:index_cache_hit
|
|
121
129
|
|
122
130
|
The same as `cache_hit` with each table's indexes cache hit info displayed separately.
|
123
131
|
|
132
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
133
|
+
|
124
134
|
### `table_cache_hit`
|
125
135
|
|
126
|
-
```
|
136
|
+
```ruby
|
127
137
|
|
128
138
|
RailsPGExtras.table_cache_hit
|
129
139
|
|
@@ -139,9 +149,33 @@ $ rake pg_extras:table_cache_hit
|
|
139
149
|
|
140
150
|
The same as `cache_hit` with each table's cache hit info displayed seperately.
|
141
151
|
|
142
|
-
|
152
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
153
|
+
|
154
|
+
### `db_settings`
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
|
158
|
+
RailsPGExtras.db_settings
|
159
|
+
|
160
|
+
$ rake pg_extras:db_settings
|
161
|
+
|
162
|
+
name | setting | unit |
|
163
|
+
------------------------------+---------+------+
|
164
|
+
checkpoint_completion_target | 0.7 | |
|
165
|
+
default_statistics_target | 100 | |
|
166
|
+
effective_cache_size | 1350000 | 8kB |
|
167
|
+
effective_io_concurrency | 1 | |
|
168
|
+
(truncated results for brevity)
|
143
169
|
|
144
170
|
```
|
171
|
+
|
172
|
+
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.
|
173
|
+
|
174
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
|
175
|
+
|
176
|
+
### `index_usage`
|
177
|
+
|
178
|
+
```ruby
|
145
179
|
RailsPGExtras.index_usage
|
146
180
|
|
147
181
|
$ rake pg_extras:index_usage
|
@@ -160,7 +194,7 @@ This command provides information on the efficiency of indexes, represented as w
|
|
160
194
|
|
161
195
|
### `locks`
|
162
196
|
|
163
|
-
```
|
197
|
+
```ruby
|
164
198
|
RailsPGExtras.locks
|
165
199
|
|
166
200
|
$ rake pg_extras:locks
|
@@ -178,9 +212,11 @@ $ rake pg_extras:locks
|
|
178
212
|
|
179
213
|
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.
|
180
214
|
|
215
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#deadlocks)
|
216
|
+
|
181
217
|
### `all_locks`
|
182
218
|
|
183
|
-
```
|
219
|
+
```ruby
|
184
220
|
RailsPGExtras.all_locks
|
185
221
|
|
186
222
|
$ rake pg_extras:all_locks
|
@@ -190,8 +226,8 @@ This command displays all the current locks, regardless of their type.
|
|
190
226
|
|
191
227
|
### `outliers`
|
192
228
|
|
193
|
-
```
|
194
|
-
|
229
|
+
```ruby
|
230
|
+
RailsPGExtras.outliers(args: { limit: 20 })
|
195
231
|
|
196
232
|
$ rake pg_extras:outliers
|
197
233
|
|
@@ -210,10 +246,12 @@ This command displays statements, obtained from `pg_stat_statements`, ordered by
|
|
210
246
|
|
211
247
|
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.
|
212
248
|
|
249
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
250
|
+
|
213
251
|
### `calls`
|
214
252
|
|
215
|
-
```
|
216
|
-
|
253
|
+
```ruby
|
254
|
+
RailsPGExtras.calls(args: { limit: 10 })
|
217
255
|
|
218
256
|
$ rake pg_extras:calls
|
219
257
|
|
@@ -229,10 +267,12 @@ $ rake pg_extras:calls
|
|
229
267
|
|
230
268
|
This command is much like `pg:outliers`, but ordered by the number of times a statement has been called.
|
231
269
|
|
270
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
271
|
+
|
232
272
|
### `blocking`
|
233
273
|
|
234
|
-
```
|
235
|
-
|
274
|
+
```ruby
|
275
|
+
RailsPGExtras.blocking
|
236
276
|
|
237
277
|
$ rake pg_extras:blocking
|
238
278
|
|
@@ -244,10 +284,12 @@ $ rake pg_extras:blocking
|
|
244
284
|
|
245
285
|
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.
|
246
286
|
|
247
|
-
|
287
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#deadlocks)
|
248
288
|
|
249
|
-
|
250
|
-
|
289
|
+
### `total_index_size`
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
RailsPGExtras.total_index_size
|
251
293
|
|
252
294
|
$ rake pg_extras:total_index_size
|
253
295
|
|
@@ -261,8 +303,8 @@ This command displays the total size of all indexes on the database, in MB. It i
|
|
261
303
|
|
262
304
|
### `index_size`
|
263
305
|
|
264
|
-
```
|
265
|
-
|
306
|
+
```ruby
|
307
|
+
RailsPGExtras.index_size
|
266
308
|
|
267
309
|
$ rake pg_extras:index_size
|
268
310
|
name | size
|
@@ -284,8 +326,8 @@ This command displays the size of each each index in the database, in MB. It is
|
|
284
326
|
|
285
327
|
### `table_size`
|
286
328
|
|
287
|
-
```
|
288
|
-
|
329
|
+
```ruby
|
330
|
+
RailsPGExtras.table_size
|
289
331
|
|
290
332
|
$ rake pg_extras:table_size
|
291
333
|
|
@@ -303,8 +345,8 @@ This command displays the size of each table and materialized view in the databa
|
|
303
345
|
|
304
346
|
### `table_indexes_size`
|
305
347
|
|
306
|
-
```
|
307
|
-
|
348
|
+
```ruby
|
349
|
+
RailsPGExtras.table_indexes_size
|
308
350
|
|
309
351
|
$ rake pg_extras:table_indexes_size
|
310
352
|
|
@@ -322,8 +364,8 @@ This command displays the total size of indexes for each table and materialized
|
|
322
364
|
|
323
365
|
### `total_table_size`
|
324
366
|
|
325
|
-
```
|
326
|
-
|
367
|
+
```ruby
|
368
|
+
RailsPGExtras.total_table_size
|
327
369
|
|
328
370
|
$ rake pg_extras:total_table_size
|
329
371
|
|
@@ -341,8 +383,8 @@ This command displays the total size of each table and materialized view in the
|
|
341
383
|
|
342
384
|
### `unused_indexes`
|
343
385
|
|
344
|
-
```
|
345
|
-
|
386
|
+
```ruby
|
387
|
+
RailsPGExtras.unused_indexes(args: { min_scans: 20 })
|
346
388
|
|
347
389
|
$ rake pg_extras:unused_indexes
|
348
390
|
|
@@ -356,6 +398,21 @@ $ rake pg_extras:unused_indexes
|
|
356
398
|
|
357
399
|
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.
|
358
400
|
|
401
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#unused-indexes)
|
402
|
+
|
403
|
+
### `duplicate_indexes`
|
404
|
+
|
405
|
+
```ruby
|
406
|
+
|
407
|
+
RailsPGExtras.duplicate_indexes
|
408
|
+
|
409
|
+
| size | idx1 | idx2 | idx3 | idx4 |
|
410
|
+
+------------+--------------+----------------+----------+-----------+
|
411
|
+
| 128 k | users_pkey | index_users_id | | |
|
412
|
+
```
|
413
|
+
|
414
|
+
This command displays multiple indexes that have the same set of columns, same opclass, expression and predicate - which make them equivalent. Usually it's safe to drop one of them.
|
415
|
+
|
359
416
|
### `null_indexes`
|
360
417
|
|
361
418
|
```ruby
|
@@ -372,12 +429,14 @@ $ rake pg_extras:null_indexes
|
|
372
429
|
|
373
430
|
```
|
374
431
|
|
375
|
-
This
|
432
|
+
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.
|
433
|
+
|
434
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#null-indexes)
|
376
435
|
|
377
436
|
### `seq_scans`
|
378
437
|
|
379
|
-
```
|
380
|
-
|
438
|
+
```ruby
|
439
|
+
RailsPGExtras.seq_scans
|
381
440
|
|
382
441
|
$ rake pg_extras:seq_scans
|
383
442
|
|
@@ -391,23 +450,17 @@ $ rake pg_extras:seq_scans
|
|
391
450
|
messages | 3922247
|
392
451
|
contests_customers | 2915972
|
393
452
|
classroom_goals | 2142014
|
394
|
-
contests | 1370267
|
395
|
-
goals | 1112659
|
396
|
-
districts | 158995
|
397
|
-
rollup_reports | 115942
|
398
|
-
customers | 93847
|
399
|
-
schools | 92984
|
400
|
-
classrooms | 92982
|
401
|
-
customer_settings | 91226
|
402
453
|
(truncated results for brevity)
|
403
454
|
```
|
404
455
|
|
405
456
|
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.
|
406
457
|
|
458
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#missing-indexes)
|
459
|
+
|
407
460
|
### `long_running_queries`
|
408
461
|
|
409
|
-
```
|
410
|
-
|
462
|
+
```ruby
|
463
|
+
RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
|
411
464
|
|
412
465
|
$ rake pg_extras:long_running_queries
|
413
466
|
|
@@ -423,8 +476,8 @@ This command displays currently running queries, that have been running for long
|
|
423
476
|
|
424
477
|
### `records_rank`
|
425
478
|
|
426
|
-
```
|
427
|
-
|
479
|
+
```ruby
|
480
|
+
RailsPGExtras.records_rank
|
428
481
|
|
429
482
|
$ rake pg_extras:records_rank
|
430
483
|
|
@@ -443,8 +496,8 @@ This command displays an estimated count of rows per table, descending by estima
|
|
443
496
|
|
444
497
|
### `bloat`
|
445
498
|
|
446
|
-
```
|
447
|
-
|
499
|
+
```ruby
|
500
|
+
RailsPGExtras.bloat
|
448
501
|
|
449
502
|
$ rake pg_extras:bloat
|
450
503
|
|
@@ -460,10 +513,12 @@ $ rake pg_extras:bloat
|
|
460
513
|
|
461
514
|
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.
|
462
515
|
|
516
|
+
[More info](https://pawelurbanek.com/postgresql-fix-performance#bloat)
|
517
|
+
|
463
518
|
### `vacuum_stats`
|
464
519
|
|
465
|
-
```
|
466
|
-
|
520
|
+
```ruby
|
521
|
+
RailsPGExtras.vacuum_stats
|
467
522
|
|
468
523
|
$ rake pg_extras:vacuum_stats
|
469
524
|
|
@@ -488,10 +543,26 @@ RailsPGExtras.kill_all
|
|
488
543
|
|
489
544
|
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.
|
490
545
|
|
491
|
-
### `
|
546
|
+
### `buffercache_stats`
|
547
|
+
|
548
|
+
```ruby
|
549
|
+
RailsPGExtras.buffercache_stats(args: { limit: 10 })
|
550
|
+
```
|
551
|
+
|
552
|
+
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.
|
553
|
+
|
554
|
+
### `buffercache_usage`
|
492
555
|
|
556
|
+
```ruby
|
557
|
+
RailsPGExtras.buffercache_usage(args: { limit: 20 })
|
493
558
|
```
|
494
559
|
|
560
|
+
This command calculates how many blocks from which table are currently cached.
|
561
|
+
|
562
|
+
### `extensions`
|
563
|
+
|
564
|
+
```ruby
|
565
|
+
|
495
566
|
RailsPGExtras.extensions
|
496
567
|
|
497
568
|
$ rake pg_extras:extensions
|
@@ -505,10 +576,24 @@ This command lists all the currently installed and available PostgreSQL extensio
|
|
505
576
|
|
506
577
|
### mandelbrot
|
507
578
|
|
508
|
-
```
|
579
|
+
```ruby
|
509
580
|
RailsPGExtras.mandelbrot
|
510
581
|
|
511
582
|
$ rake pg_extras:mandelbrot
|
512
583
|
```
|
513
584
|
|
514
585
|
This command outputs the Mandelbrot set, calculated through SQL.
|
586
|
+
|
587
|
+
## Testing
|
588
|
+
|
589
|
+
```bash
|
590
|
+
cp docker-compose.yml.sample docker-compose.yml
|
591
|
+
docker compose up -d
|
592
|
+
rake test_all
|
593
|
+
```
|
594
|
+
|
595
|
+
## Query sources
|
596
|
+
|
597
|
+
- [https://github.com/heroku/heroku-pg-extras](https://github.com/heroku/heroku-pg-extras)
|
598
|
+
- [https://hakibenita.com/postgresql-unused-index-size](https://hakibenita.com/postgresql-unused-index-size)
|
599
|
+
- [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)
|
data/Rakefile
CHANGED
data/docker-compose.yml.sample
CHANGED
@@ -1,12 +1,30 @@
|
|
1
1
|
version: '3'
|
2
2
|
|
3
3
|
services:
|
4
|
-
|
4
|
+
postgres11:
|
5
5
|
image: postgres:11.5-alpine
|
6
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
6
7
|
environment:
|
7
8
|
POSTGRES_USER: postgres
|
8
9
|
POSTGRES_DB: rails-pg-extras-test
|
9
10
|
POSTGRES_PASSWORD: secret
|
10
11
|
ports:
|
11
12
|
- '5432:5432'
|
12
|
-
|
13
|
+
postgres12:
|
14
|
+
image: postgres:12.7-alpine
|
15
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
16
|
+
environment:
|
17
|
+
POSTGRES_USER: postgres
|
18
|
+
POSTGRES_DB: rails-pg-extras-test
|
19
|
+
POSTGRES_PASSWORD: secret
|
20
|
+
ports:
|
21
|
+
- '5433:5432'
|
22
|
+
postgres13:
|
23
|
+
image: postgres:13.3-alpine
|
24
|
+
command: postgres -c shared_preload_libraries=pg_stat_statements
|
25
|
+
environment:
|
26
|
+
POSTGRES_USER: postgres
|
27
|
+
POSTGRES_DB: rails-pg-extras-test
|
28
|
+
POSTGRES_PASSWORD: secret
|
29
|
+
ports:
|
30
|
+
- '5434:5432'
|
data/lib/rails-pg-extras.rb
CHANGED
@@ -6,6 +6,7 @@ require 'ruby-pg-extras'
|
|
6
6
|
module RailsPGExtras
|
7
7
|
QUERIES = RubyPGExtras::QUERIES
|
8
8
|
DEFAULT_ARGS = RubyPGExtras::DEFAULT_ARGS
|
9
|
+
NEW_PG_STAT_STATEMENTS = RubyPGExtras::NEW_PG_STAT_STATEMENTS
|
9
10
|
|
10
11
|
QUERIES.each do |query_name|
|
11
12
|
define_singleton_method query_name do |options = {}|
|
@@ -18,6 +19,16 @@ module RailsPGExtras
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.run_query(query_name:, in_format:, args: {})
|
22
|
+
if %i(calls outliers).include?(query_name)
|
23
|
+
pg_stat_statements_ver = RailsPGExtras.connection.execute("select installed_version from pg_available_extensions where name='pg_stat_statements'")
|
24
|
+
.to_a[0].fetch("installed_version", nil)
|
25
|
+
if pg_stat_statements_ver != nil
|
26
|
+
if Gem::Version.new(pg_stat_statements_ver) < Gem::Version.new(NEW_PG_STAT_STATEMENTS)
|
27
|
+
query_name = "#{query_name}_legacy".to_sym
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
21
32
|
sql = if (custom_args = DEFAULT_ARGS[query_name].merge(args)) != {}
|
22
33
|
RubyPGExtras.sql_for(query_name: query_name) % custom_args
|
23
34
|
else
|
@@ -36,8 +47,6 @@ module RailsPGExtras
|
|
36
47
|
def self.connection
|
37
48
|
ActiveRecord::Base.connection
|
38
49
|
end
|
39
|
-
|
40
|
-
private_class_method :connection
|
41
50
|
end
|
42
51
|
|
43
52
|
require 'rails-pg-extras/railtie' if defined?(Rails)
|
Binary file
|
data/spec/smoke_spec.rb
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe RailsPGExtras do
|
6
|
-
|
6
|
+
before(:all) do
|
7
|
+
RailsPGExtras.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_buffercache;")
|
8
|
+
RubyPGExtras.connection.exec("CREATE EXTENSION IF NOT EXISTS pg_stat_statements;")
|
9
|
+
end
|
7
10
|
|
8
|
-
|
11
|
+
RailsPGExtras::QUERIES.each do |query_name|
|
9
12
|
it "#{query_name} query can be executed" do
|
10
13
|
expect do
|
11
14
|
RailsPGExtras.run_query(
|
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,19 @@ require 'bundler/setup'
|
|
5
5
|
require 'active_record'
|
6
6
|
require_relative '../lib/rails-pg-extras'
|
7
7
|
|
8
|
-
ENV["
|
8
|
+
pg_version = ENV["PG_VERSION"]
|
9
|
+
|
10
|
+
port = if pg_version == "11"
|
11
|
+
"5432"
|
12
|
+
elsif pg_version == "12"
|
13
|
+
"5433"
|
14
|
+
elsif pg_version == "13"
|
15
|
+
"5434"
|
16
|
+
else
|
17
|
+
"5432"
|
18
|
+
end
|
19
|
+
|
20
|
+
ENV["DATABASE_URL"] ||= "postgresql://postgres:secret@localhost:#{port}/rails-pg-extras-test"
|
9
21
|
|
10
22
|
RSpec.configure do |config|
|
11
23
|
config.before :suite do
|
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: 2.1.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-10-15 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: 2.1.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: 2.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/rails-pg-extras/railtie.rb
|
87
87
|
- lib/rails-pg-extras/tasks/all.rake
|
88
88
|
- lib/rails-pg-extras/version.rb
|
89
|
+
- rails-pg-extras-web.png
|
89
90
|
- rails-pg-extras.gemspec
|
90
91
|
- spec/smoke_spec.rb
|
91
92
|
- spec/spec_helper.rb
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
|
-
rubygems_version: 3.1.
|
112
|
+
rubygems_version: 3.1.6
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Rails PostgreSQL performance database insights
|