ruby-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31f7c01df2a34c5808c2b8453093e6ce9bf2d55511ac88375279fea78a8d46e9
4
- data.tar.gz: a1f285519deb70a92aeb1680a3babb4bca74e7b91ed7d55ff11f188200611046
3
+ metadata.gz: 390b7ac85682a6c91029781a9cf2e639993048c0c2b9b80a93e0b83ef52ba457
4
+ data.tar.gz: d84e02a04eaba3ef8d899cfd137139d5bb9d00310480fe0d7a2b70786538a14d
5
5
  SHA512:
6
- metadata.gz: cd2503652ba87050811d301fa47fff20614c0d3821aea52001c2acb6c6f22b4d1f2de7294408c57b48fe7c657fb8f65c26690f5459f8d0c8c1cd2a4003426c60
7
- data.tar.gz: ded972ab987058cbdc701e40a3046a02fa0ca70a315a83effa01a6925adfbb26418e42c1fa7c1413308b411ec73f6ff4179c8957dece6a427686d88c059c1c73
6
+ metadata.gz: e07b9007849b685743727d590ed095c68868c364a5090f2a030a50bafcfa25b15132f3954d3daa301506ec82210b4a2e2e78ddf21b92bfbcb8643bf8825f38e9
7
+ data.tar.gz: eda59a08e3ac273743897ab2460a1653ae4c33d1d4ec1b38e38f8a6f7cc44275f984f5231703435191b660181e23c5d75469d9fec498c73f67b3a9a70921ddad
data/README.md CHANGED
@@ -4,17 +4,40 @@ Ruby port of [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras) with
4
4
 
5
5
  Queries 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
- Are you riding on Rails? Check out the [Rails version](https://github.com/pawurb/rails-pg-extras).
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
- ### Installation
9
+ Alternative versions:
10
+
11
+ - [Ruby on Rails](https://github.com/pawurb/rails-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/python-pg-extras)
18
+
19
+ ## Installation
10
20
 
11
21
  In your Gemfile
12
22
 
13
23
  ```ruby
14
- gem 'ruby-pg-extras'
24
+ gem "ruby-pg-extras"
25
+ ```
26
+
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
+ RubyPGExtras.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 |
15
38
  ```
16
39
 
17
- ### Usage
40
+ ## Usage
18
41
 
19
42
  Gem expects the `ENV['DATABASE_URL']` value in the following format:
20
43
 
@@ -60,9 +83,9 @@ RubyPGExtras.cache_hit(in_format: :raw) =>
60
83
  #<PG::Result:0x00007f75777f7328 status=PGRES_TUPLES_OK ntuples=2 nfields=2 cmd_tuples=2>
61
84
  ```
62
85
 
63
- ### Available methods
86
+ ## Available methods
64
87
 
65
- #### `cache_hit`
88
+ ### `cache_hit`
66
89
 
67
90
  ```ruby
68
91
 
@@ -77,7 +100,7 @@ RubyPGExtras.cache_hit
77
100
 
78
101
  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.
79
102
 
80
- #### `index_cache_hit`
103
+ ### `index_cache_hit`
81
104
 
82
105
  ```ruby
83
106
 
@@ -93,7 +116,7 @@ RubyPGExtras.index_cache_hit
93
116
 
94
117
  The same as `cache_hit` with each table's indexes cache hit info displayed seperately.
95
118
 
96
- #### `table_cache_hit`
119
+ ### `table_cache_hit`
97
120
 
98
121
  ```ruby
99
122
 
@@ -109,7 +132,7 @@ RubyPGExtras.table_cache_hit
109
132
 
110
133
  The same as `cache_hit` with each table's cache hit info displayed seperately.
111
134
 
112
- #### `index_usage`
135
+ ### `index_usage`
113
136
 
114
137
  ```ruby
115
138
 
@@ -212,7 +235,7 @@ RubyPGExtras.blocking
212
235
 
213
236
  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.
214
237
 
215
- #### `total_index_size`
238
+ ### `total_index_size`
216
239
 
217
240
  ```ruby
218
241
 
@@ -265,7 +288,7 @@ RubyPGExtras.table_size
265
288
  (truncated results for brevity)
266
289
  ```
267
290
 
268
- 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.
291
+ 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.
269
292
 
270
293
  ### `table_indexes_size`
271
294
 
@@ -283,7 +306,7 @@ RubyPGExtras.table_indexes_size
283
306
  (truncated results for brevity)
284
307
  ```
285
308
 
286
- 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()`.
309
+ 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()`.
287
310
 
288
311
  ### `total_table_size`
289
312
 
@@ -301,7 +324,7 @@ RubyPGExtras.total_table_size
301
324
  (truncated results for brevity)
302
325
  ```
303
326
 
304
- 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.
327
+ 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.
305
328
 
306
329
  ### `unused_indexes`
307
330
 
@@ -341,7 +364,7 @@ RubyPGExtras.seq_scans
341
364
 
342
365
  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.
343
366
 
344
- ### long_running_queries
367
+ ### `long_running_queries`
345
368
 
346
369
  ```ruby
347
370
 
@@ -358,7 +381,7 @@ RubyPGExtras.long_running_queries
358
381
 
359
382
  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`.
360
383
 
361
- ### records_rank
384
+ ### `records_rank`
362
385
 
363
386
  ```ruby
364
387
 
@@ -377,7 +400,7 @@ RubyPGExtras.records_rank
377
400
 
378
401
  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.
379
402
 
380
- ### bloat
403
+ ### `bloat`
381
404
 
382
405
  ```ruby
383
406
 
@@ -396,7 +419,7 @@ RubyPGExtras.bloat
396
419
 
397
420
  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.
398
421
 
399
- ### vacuum_stats
422
+ ### `vacuum_stats`
400
423
 
401
424
  ```ruby
402
425
 
@@ -414,22 +437,32 @@ RubyPGExtras.vacuum_stats
414
437
 
415
438
  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.
416
439
 
417
- ### mandelbrot
440
+ ### `kill_all`
418
441
 
419
442
  ```ruby
420
443
 
421
- RubyPGExtras.mandelbrot
444
+ RubyPGExtras.kill_all
422
445
 
423
446
  ```
424
447
 
425
- This command outputs the Mandelbrot set, calculated through SQL.
448
+ 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.
426
449
 
427
- ## FAQ
450
+ ### `extensions`
428
451
 
429
- * Does is not violate the Heroku PG Extras license?
452
+ ```ruby
430
453
 
431
- The original plugin is MIT based so it means that copying and redistribution in any format is permitted.
454
+ RubyPGExtras.extensions
432
455
 
433
- ## Disclaimer
456
+ ```
434
457
 
435
- This tool is in beta state.
458
+ This command lists all the currently installed and available PostgreSQL extensions.
459
+
460
+ ### `mandelbrot`
461
+
462
+ ```ruby
463
+
464
+ RubyPGExtras.mandelbrot
465
+
466
+ ```
467
+
468
+ This command outputs the Mandelbrot set, calculated through SQL.
@@ -14,7 +14,7 @@ module RubyPGExtras
14
14
  long_running_queries mandelbrot outliers
15
15
  records_rank seq_scans table_indexes_size
16
16
  table_size total_index_size total_table_size
17
- unused_indexes vacuum_stats
17
+ unused_indexes vacuum_stats kill_all
18
18
  )
19
19
 
20
20
  QUERIES.each do |query_name|
@@ -0,0 +1,6 @@
1
+ /* Kill all the active database connections */
2
+
3
+ SELECT pg_terminate_backend(pid) FROM pg_stat_activity
4
+ WHERE pid <> pg_backend_pid()
5
+ AND query <> '<insufficient privilege>'
6
+ AND datname = current_database();
@@ -6,5 +6,5 @@ FROM pg_class c
6
6
  LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
7
7
  WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
8
8
  AND n.nspname !~ '^pg_toast'
9
- AND c.relkind='r'
9
+ AND c.relkind IN ('r', 'm')
10
10
  ORDER BY pg_indexes_size(c.oid) DESC;
@@ -6,5 +6,5 @@ FROM pg_class c
6
6
  LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
7
7
  WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
8
8
  AND n.nspname !~ '^pg_toast'
9
- AND c.relkind='r'
9
+ AND c.relkind IN ('r', 'm')
10
10
  ORDER BY pg_table_size(c.oid) DESC;
@@ -6,5 +6,5 @@ FROM pg_class c
6
6
  LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
7
7
  WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
8
8
  AND n.nspname !~ '^pg_toast'
9
- AND c.relkind='r'
9
+ AND c.relkind IN ('r', 'm')
10
10
  ORDER BY pg_total_relation_size(c.oid) DESC;
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RubyPGExtras
2
- VERSION = "1.0.0"
4
+ VERSION = "1.2.3"
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
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-01-18 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -92,6 +92,7 @@ files:
92
92
  - lib/ruby-pg-extras/queries/index_cache_hit.sql
93
93
  - lib/ruby-pg-extras/queries/index_size.sql
94
94
  - lib/ruby-pg-extras/queries/index_usage.sql
95
+ - lib/ruby-pg-extras/queries/kill_all.sql
95
96
  - lib/ruby-pg-extras/queries/locks.sql
96
97
  - lib/ruby-pg-extras/queries/long_running_queries.sql
97
98
  - lib/ruby-pg-extras/queries/mandelbrot.sql
@@ -113,7 +114,7 @@ homepage: http://github.com/pawurb/ruby-pg-extras
113
114
  licenses:
114
115
  - MIT
115
116
  metadata: {}
116
- post_install_message:
117
+ post_install_message:
117
118
  rdoc_options: []
118
119
  require_paths:
119
120
  - lib
@@ -128,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
- rubygems_version: 3.0.6
132
- signing_key:
132
+ rubygems_version: 3.1.2
133
+ signing_key:
133
134
  specification_version: 4
134
135
  summary: Ruby PostgreSQL performance database insights
135
136
  test_files: