rails-pg-extras 1.0.0 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -26
- data/lib/rails-pg-extras/version.rb +3 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b32211012cd93252e2fd58f870713a4717f57eaed8071b6fd3c32aeac31264
|
4
|
+
data.tar.gz: e4001940a894b757284e650c50400357f3d01e2e0273841fdf243099e88a8042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ccc4603aa90aba0229aa0c2c7ac76c9377e90e8e8704a107d52588472b5c4e05b8d3aeb8acb7ba2a6ff4a5fc9003c17c797932c6baaa337270314fb70ff47db
|
7
|
+
data.tar.gz: c73c394b1d2c5692eafa973f0daf6751e6e72b33b7baba67d69bc7385a60d058ada88a1d6ff6e52812daab647b6e5109bacef1cb4fd1cea23049fe1a2f9ca2c0
|
data/README.md
CHANGED
@@ -4,17 +4,40 @@ 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
|
-
|
7
|
+
You can check out 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
8
|
|
9
|
-
|
9
|
+
Alternative versions:
|
10
|
+
|
11
|
+
- Core dependency - [Ruby](https://github.com/pawurb/ruby-pg-extras)
|
12
|
+
|
13
|
+
- [NodeJS](https://github.com/pawurb/node-postgres-extras)
|
14
|
+
|
15
|
+
- [Elixir](https://github.com/pawurb/ecto_psql_extras)
|
16
|
+
|
17
|
+
- [Python](https://github.com/pawurb/ecto_psql_extras)
|
18
|
+
|
19
|
+
## Installation
|
10
20
|
|
11
21
|
In your Gemfile
|
12
22
|
|
13
23
|
```ruby
|
14
|
-
gem
|
24
|
+
gem "rails-pg-extras"
|
15
25
|
```
|
16
26
|
|
17
|
-
|
27
|
+
Some of the queries (e.g., `calls` and `outliers`) require [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension enabled.
|
28
|
+
|
29
|
+
You can check if it is enabled in your database by running:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
RailsPGExtras.extensions
|
33
|
+
```
|
34
|
+
You should see the similar line in the output:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
| pg_stat_statements | 1.7 | 1.7 | track execution statistics of all SQL statements executed |
|
38
|
+
```
|
39
|
+
|
40
|
+
## Usage
|
18
41
|
|
19
42
|
Each command can be used as a rake task, or a directly from the Ruby code.
|
20
43
|
|
@@ -53,9 +76,9 @@ RailsPGExtras.cache_hit(in_format: :raw) =>
|
|
53
76
|
#<PG::Result:0x00007f75777f7328 status=PGRES_TUPLES_OK ntuples=2 nfields=2 cmd_tuples=2>
|
54
77
|
```
|
55
78
|
|
56
|
-
|
79
|
+
## Available methods
|
57
80
|
|
58
|
-
|
81
|
+
### `cache_hit`
|
59
82
|
|
60
83
|
```
|
61
84
|
$ rake pg_extras:cache_hit
|
@@ -69,7 +92,7 @@ $ rake pg_extras:cache_hit
|
|
69
92
|
|
70
93
|
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.
|
71
94
|
|
72
|
-
|
95
|
+
### `index_cache_hit`
|
73
96
|
|
74
97
|
```
|
75
98
|
|
@@ -85,7 +108,7 @@ $ rake pg_extras:index_cache_hit
|
|
85
108
|
|
86
109
|
The same as `cache_hit` with each table's indexes cache hit info displayed seperately.
|
87
110
|
|
88
|
-
|
111
|
+
### `table_cache_hit`
|
89
112
|
|
90
113
|
```
|
91
114
|
|
@@ -101,7 +124,7 @@ $ rake pg_extras:table_cache_hit
|
|
101
124
|
|
102
125
|
The same as `cache_hit` with each table's cache hit info displayed seperately.
|
103
126
|
|
104
|
-
|
127
|
+
### `index_usage`
|
105
128
|
|
106
129
|
```
|
107
130
|
$ rake pg_extras:index_usage
|
@@ -243,12 +266,12 @@ $ rake pg_extras:table_size
|
|
243
266
|
(truncated results for brevity)
|
244
267
|
```
|
245
268
|
|
246
|
-
This command displays the size of each table in the database, in MB. It is calculated by using the system administration function `pg_table_size()`, which includes the size of the main data fork, free space map, visibility map and TOAST data.
|
269
|
+
This command displays the size of each table and materialized view in the database, in MB. It is calculated by using the system administration function `pg_table_size()`, which includes the size of the main data fork, free space map, visibility map and TOAST data.
|
247
270
|
|
248
271
|
### `table_indexes_size`
|
249
272
|
|
250
273
|
```
|
251
|
-
$ rake pg_extras:
|
274
|
+
$ rake pg_extras:table_indexes_size
|
252
275
|
|
253
276
|
table | indexes_size
|
254
277
|
---------------------------------------------------------------+--------------
|
@@ -260,7 +283,7 @@ $ rake pg_extras:table-indexes-size
|
|
260
283
|
(truncated results for brevity)
|
261
284
|
```
|
262
285
|
|
263
|
-
This command displays the total size of indexes for each table, in MB. It is calcualtes by using the system administration function `pg_indexes_size()`.
|
286
|
+
This command displays the total size of indexes for each table and materialized view, in MB. It is calcualtes by using the system administration function `pg_indexes_size()`.
|
264
287
|
|
265
288
|
### `total_table_size`
|
266
289
|
|
@@ -277,7 +300,7 @@ $ rake pg_extras:total_table_size
|
|
277
300
|
(truncated results for brevity)
|
278
301
|
```
|
279
302
|
|
280
|
-
This command displays the total size of each table in the database, in MB. It is calculated by using the system administration function `pg_total_relation_size()`, which includes table size, total index size and TOAST data.
|
303
|
+
This command displays the total size of each table and materialized view in the database, in MB. It is calculated by using the system administration function `pg_total_relation_size()`, which includes table size, total index size and TOAST data.
|
281
304
|
|
282
305
|
### `unused_indexes`
|
283
306
|
|
@@ -322,7 +345,7 @@ $ rake pg_extras:seq_scans
|
|
322
345
|
|
323
346
|
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 underindexed, and it may be worth investigating queries that read from these tables.
|
324
347
|
|
325
|
-
### long_running_queries
|
348
|
+
### `long_running_queries`
|
326
349
|
|
327
350
|
```
|
328
351
|
$ rake pg_extras:long_running_queries
|
@@ -337,7 +360,7 @@ $ rake pg_extras:long_running_queries
|
|
337
360
|
|
338
361
|
This command displays currently running queries, that have been running for longer than 5 minutes, descending by duration. Very long running queries can be a source of multiple issues, such as preventing DDL statements completing or vacuum being unable to update `relfrozenxid`.
|
339
362
|
|
340
|
-
### records_rank
|
363
|
+
### `records_rank`
|
341
364
|
|
342
365
|
```
|
343
366
|
$ rake pg_extras:records_rank
|
@@ -355,7 +378,7 @@ $ rake pg_extras:records_rank
|
|
355
378
|
|
356
379
|
This command displays an estimated count of rows per table, descending by estimated count. The estimated count is derived from `n_live_tup`, which is updated by vacuum operations. Due to the way `n_live_tup` is populated, sparse vs. dense pages can result in estimations that are significantly out from the real count of rows.
|
357
380
|
|
358
|
-
### bloat
|
381
|
+
### `bloat`
|
359
382
|
|
360
383
|
```
|
361
384
|
$ rake pg_extras:bloat
|
@@ -372,7 +395,7 @@ $ rake pg_extras:bloat
|
|
372
395
|
|
373
396
|
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.
|
374
397
|
|
375
|
-
### vacuum_stats
|
398
|
+
### `vacuum_stats`
|
376
399
|
|
377
400
|
```
|
378
401
|
$ rake pg_extras:vacuum_stats
|
@@ -388,20 +411,30 @@ $ rake pg_extras:vacuum_stats
|
|
388
411
|
|
389
412
|
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.
|
390
413
|
|
391
|
-
###
|
414
|
+
### `kill_all`
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
|
418
|
+
RailsPGExtras.kill_all
|
392
419
|
|
393
|
-
```
|
394
|
-
$ rake pg_extras:mandelbrot
|
395
420
|
```
|
396
421
|
|
397
|
-
This
|
422
|
+
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.
|
423
|
+
|
424
|
+
### `extensions`
|
398
425
|
|
399
|
-
|
426
|
+
```ruby
|
400
427
|
|
401
|
-
|
428
|
+
RailsPGExtras.extensions
|
402
429
|
|
403
|
-
|
430
|
+
```
|
404
431
|
|
405
|
-
|
432
|
+
This command lists all the currently installed and available PostgreSQL extensions.
|
406
433
|
|
407
|
-
|
434
|
+
### mandelbrot
|
435
|
+
|
436
|
+
```
|
437
|
+
$ rake pg_extras:mandelbrot
|
438
|
+
```
|
439
|
+
|
440
|
+
This command outputs the Mandelbrot set, calculated through SQL.
|
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.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-08 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.2.3
|
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.2.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +93,7 @@ homepage: http://github.com/pawurb/rails-pg-extras
|
|
93
93
|
licenses:
|
94
94
|
- MIT
|
95
95
|
metadata: {}
|
96
|
-
post_install_message:
|
96
|
+
post_install_message:
|
97
97
|
rdoc_options: []
|
98
98
|
require_paths:
|
99
99
|
- lib
|
@@ -108,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.
|
112
|
-
signing_key:
|
111
|
+
rubygems_version: 3.1.2
|
112
|
+
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Rails PostgreSQL performance database insights
|
115
115
|
test_files:
|