rails-pg-extras 2.2.0 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50ec4785963ebe2582c746a07b4837bc7111057bfb968d97d55b9ffeaeba5fd5
4
- data.tar.gz: c5468e40d1ffcebe54d9993a85fa5197a54c1e23fc6a103d47475571c21fb311
3
+ metadata.gz: e274fc39b73b8bdaf1b0f0f2a92fed8024e99b2796b208967f87d796ae9edbd2
4
+ data.tar.gz: 34cdb4362d0fd7240c4eac857cfd24d342a4e99eed7cda2eb20791bd8bce6c86
5
5
  SHA512:
6
- metadata.gz: 1fd7ea62b34b1c9a3fcc090bcfb6f5df17223f5208b10bd848ad4bc04e0a2ef8772467edc16cff15dd070a63e5cd23466b334bec9b877efcb033ebe19dec2a77
7
- data.tar.gz: 6cbf078dd0a56f9a9cdfac8bac27557b2192f29df9f491807f6e66e994e256fe710df061500198efffcb6bb1f847899a11bd166b73f643b73a55cda7b8675dac
6
+ metadata.gz: d9045c9281c65bb9648898102d534e0cecc05a675949cd394900e8b7c821fb46b69e93e4fbb6243d470a77568858ce3295f61c95ce86737e604f7b687cbf05bd
7
+ data.tar.gz: fa66c8f4f06f233a2a2a8288d69c5e4fb257c1c2801f4c7f8c90bac722a4d82cce439759c2fe893986043ba3a30816ccd31e155ed6ab8e1666717d34a549cb5f
data/.circleci/config.yml CHANGED
@@ -31,7 +31,8 @@ jobs:
31
31
  - checkout
32
32
  - run: gem update --system
33
33
  - run: gem install bundler
34
- - run: bundle install --path vendor/bundle
34
+ - run: bundle config set --local path 'vendor/bundle'
35
+ - run: bundle install
35
36
  - run: sudo apt-get update --allow-releaseinfo-change
36
37
  - run: sudo apt install postgresql-client
37
38
  - run: dockerize -wait tcp://postgres11:5432 -timeout 1m
data/README.md CHANGED
@@ -32,7 +32,7 @@ In your Gemfile
32
32
  gem "rails-pg-extras"
33
33
  ```
34
34
 
35
- Some of the queries (e.g., `calls` and `outliers`) require [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension enabled.
35
+ `calls` and `outliers` queries require [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension.
36
36
 
37
37
  You can check if it is enabled in your database by running:
38
38
 
@@ -45,6 +45,12 @@ You should see the similar line in the output:
45
45
  | pg_stat_statements | 1.7 | 1.7 | track execution statistics of all SQL statements executed |
46
46
  ```
47
47
 
48
+ `ssl_used` requires `sslinfo` extension, and `buffercache_usage`/`buffercache_usage` queries need `pg_buffercache`. You can enable them all by running:
49
+
50
+ ```ruby
51
+ RailsPGExtras.add_extensions
52
+ ```
53
+
48
54
  ## Usage
49
55
 
50
56
  Each command can be used as a rake task, or a directly from the Ruby code.
@@ -91,6 +97,20 @@ RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
91
97
 
92
98
  ```
93
99
 
100
+ ## Diagnose report
101
+
102
+ The simplest way to start using pg-extras is to execute a `diagnose` method. It runs a set of checks and prints out a report highlighting areas that may require additional investigation:
103
+
104
+ ```ruby
105
+ RailsPGExtras.diagnose
106
+
107
+ $ rake pg_extras:diagnose
108
+ ```
109
+
110
+ ![Diagnose report](https://github.com/pawurb/rails-pg-extras/raw/master/rails-pg-extras-diagnose.png)
111
+
112
+ Keep reading to learn about methods that `diagnose` uses under the hood.
113
+
94
114
  ## Available methods
95
115
 
96
116
  ### `cache_hit`
@@ -173,7 +193,7 @@ This method displays values for selected PostgreSQL settings. You can compare th
173
193
 
174
194
  [More info](https://pawelurbanek.com/postgresql-fix-performance#cache-hit)
175
195
 
176
- ### 'ssl_used'
196
+ ### `ssl_used`
177
197
 
178
198
  ```ruby
179
199
 
@@ -398,7 +418,7 @@ This command displays the total size of each table and materialized view in the
398
418
  ### `unused_indexes`
399
419
 
400
420
  ```ruby
401
- RailsPGExtras.unused_indexes(args: { min_scans: 20 })
421
+ RailsPGExtras.unused_indexes(args: { max_scans: 20 })
402
422
 
403
423
  $ rake pg_extras:unused_indexes
404
424
 
@@ -557,6 +577,14 @@ RailsPGExtras.kill_all
557
577
 
558
578
  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.
559
579
 
580
+ ### `pg_stat_statements_reset`
581
+
582
+ ```ruby
583
+ RailsPGExtras.pg_stat_statements_reset
584
+ ```
585
+
586
+ This command discards all statistics gathered so far by pg_stat_statements.
587
+
560
588
  ### `buffercache_stats`
561
589
 
562
590
  ```ruby
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class DiagnoseData < RubyPGExtras::DiagnoseData
5
+
6
+ private
7
+
8
+ def query_module
9
+ RailsPGExtras
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class DiagnosePrint < RubyPGExtras::DiagnosePrint
5
+
6
+ private
7
+
8
+ def title
9
+ "rails-pg-extras - diagnose report"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class IndexInfo < RubyPGExtras::IndexInfo
5
+ private
6
+
7
+ def query_module
8
+ RailsPGExtras
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class IndexInfoPrint < RubyPGExtras::IndexInfoPrint
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class TableInfo < RubyPGExtras::TableInfo
5
+ private
6
+
7
+ def query_module
8
+ RailsPGExtras
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsPGExtras
4
+ class TableInfoPrint < RubyPGExtras::TableInfoPrint
5
+ end
6
+ end
@@ -19,4 +19,9 @@ namespace :pg_extras do
19
19
  RailsPGExtras.public_send(query_name)
20
20
  end
21
21
  end
22
+
23
+ desc "Generate a PostgreSQL healthcheck report"
24
+ task diagnose: :establish_connection do
25
+ RailsPGExtras.diagnose
26
+ end
22
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPGExtras
4
- VERSION = "2.2.0"
4
+ VERSION = "3.2.2"
5
5
  end
@@ -2,6 +2,12 @@
2
2
 
3
3
  require 'terminal-table'
4
4
  require 'ruby-pg-extras'
5
+ require 'rails-pg-extras/diagnose_data'
6
+ require 'rails-pg-extras/diagnose_print'
7
+ require 'rails-pg-extras/index_info'
8
+ require 'rails-pg-extras/index_info_print'
9
+ require 'rails-pg-extras/table_info'
10
+ require 'rails-pg-extras/table_info_print'
5
11
 
6
12
  module RailsPGExtras
7
13
  QUERIES = RubyPGExtras::QUERIES
@@ -44,6 +50,46 @@ module RailsPGExtras
44
50
  )
45
51
  end
46
52
 
53
+ def self.diagnose(in_format: :display_table)
54
+ data = RailsPGExtras::DiagnoseData.call
55
+
56
+ if in_format == :display_table
57
+ RailsPGExtras::DiagnosePrint.call(data)
58
+ elsif in_format == :hash
59
+ data
60
+ else
61
+ raise "Invalid 'in_format' argument!"
62
+ end
63
+ end
64
+
65
+ def self.index_info(args: {}, in_format: :display_table)
66
+ data = RailsPGExtras::IndexInfo.call(args[:table_name])
67
+
68
+ if in_format == :display_table
69
+ RailsPGExtras::IndexInfoPrint.call(data)
70
+ elsif in_format == :hash
71
+ data
72
+ elsif in_format == :array
73
+ data.map(&:values)
74
+ else
75
+ raise "Invalid 'in_format' argument!"
76
+ end
77
+ end
78
+
79
+ def self.table_info(args: {}, in_format: :display_table)
80
+ data = RailsPGExtras::TableInfo.call(args[:table_name])
81
+
82
+ if in_format == :display_table
83
+ RailsPGExtras::TableInfoPrint.call(data)
84
+ elsif in_format == :hash
85
+ data
86
+ elsif in_format == :array
87
+ data.map(&:values)
88
+ else
89
+ raise "Invalid 'in_format' argument!"
90
+ end
91
+ end
92
+
47
93
  def self.connection
48
94
  ActiveRecord::Base.connection
49
95
  end
Binary file
Binary file
data/spec/smoke_spec.rb CHANGED
@@ -3,11 +3,6 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe RailsPGExtras do
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
10
-
11
6
  RailsPGExtras::QUERIES.each do |query_name|
12
7
  it "#{query_name} query can be executed" do
13
8
  expect do
@@ -18,4 +13,18 @@ describe RailsPGExtras do
18
13
  end.not_to raise_error
19
14
  end
20
15
  end
16
+
17
+ it "runs the custom methods" do
18
+ expect do
19
+ RailsPGExtras.diagnose(in_format: :hash)
20
+ end.not_to raise_error
21
+
22
+ expect do
23
+ RailsPGExtras.index_info(in_format: :hash)
24
+ end.not_to raise_error
25
+
26
+ expect do
27
+ RailsPGExtras.table_info(in_format: :hash)
28
+ end.not_to raise_error
29
+ end
21
30
  end
data/spec/spec_helper.rb CHANGED
@@ -24,6 +24,9 @@ RSpec.configure do |config|
24
24
  ActiveRecord::Base.establish_connection(
25
25
  ENV.fetch("DATABASE_URL")
26
26
  )
27
+ RailsPGExtras.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_stat_statements;")
28
+ RailsPGExtras.connection.execute("CREATE EXTENSION IF NOT EXISTS pg_buffercache;")
29
+ RailsPGExtras.connection.execute("CREATE EXTENSION IF NOT EXISTS sslinfo;")
27
30
  end
28
31
 
29
32
  config.after :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: 2.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-26 00:00:00.000000000 Z
11
+ date: 2021-12-18 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: 2.2.0
19
+ version: 3.2.2
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: 2.2.0
26
+ version: 3.2.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -83,9 +83,16 @@ files:
83
83
  - Rakefile
84
84
  - docker-compose.yml.sample
85
85
  - lib/rails-pg-extras.rb
86
+ - lib/rails-pg-extras/diagnose_data.rb
87
+ - lib/rails-pg-extras/diagnose_print.rb
88
+ - lib/rails-pg-extras/index_info.rb
89
+ - lib/rails-pg-extras/index_info_print.rb
86
90
  - lib/rails-pg-extras/railtie.rb
91
+ - lib/rails-pg-extras/table_info.rb
92
+ - lib/rails-pg-extras/table_info_print.rb
87
93
  - lib/rails-pg-extras/tasks/all.rake
88
94
  - lib/rails-pg-extras/version.rb
95
+ - rails-pg-extras-diagnose.png
89
96
  - rails-pg-extras-web.png
90
97
  - rails-pg-extras.gemspec
91
98
  - spec/smoke_spec.rb
@@ -109,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
116
  - !ruby/object:Gem::Version
110
117
  version: '0'
111
118
  requirements: []
112
- rubygems_version: 3.1.6
119
+ rubygems_version: 3.0.3
113
120
  signing_key:
114
121
  specification_version: 4
115
122
  summary: Rails PostgreSQL performance database insights