rails-pg-extras 2.1.0 → 3.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 +2 -1
- data/README.md +45 -2
- data/lib/rails-pg-extras/diagnose_data.rb +12 -0
- data/lib/rails-pg-extras/diagnose_print.rb +12 -0
- data/lib/rails-pg-extras/tasks/all.rake +5 -0
- data/lib/rails-pg-extras/version.rb +1 -1
- data/lib/rails-pg-extras.rb +14 -0
- data/rails-pg-extras-diagnose.png +0 -0
- data/rails-pg-extras-web.png +0 -0
- data/spec/smoke_spec.rb +0 -5
- data/spec/spec_helper.rb +3 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72d0aaefc019490d3c298c7114d34fc55cc0f0b236f5edf8710a4bed290d96a5
|
4
|
+
data.tar.gz: bdcce61d6e4436aa74ca098c44d5e480c9a010aa246a375cf57be514e4c10c73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3004a52e1219060a9f82e7a84028a1ee042fa95b9ef3320f9f093bf1fc3909586ac1fc0f33fb75c417df1ddec6bbef6f31d2a1ebfd6fe71d99d7d8f2ff09e266
|
7
|
+
data.tar.gz: 48cc602df378555e04ec157afdb447d702c8dfc26efb155dba6c35da221ca38c079c226997bf0fe1ea471c819d56e4612adddf410e0cdeaf48169ac828273a1d
|
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
|
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
|
-
|
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,6 +193,20 @@ 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
|
|
196
|
+
### `ssl_used`
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
|
200
|
+
RailsPGExtras.ssl_used
|
201
|
+
|
202
|
+
| ssl_is_used |
|
203
|
+
+---------------------------------+
|
204
|
+
| t |
|
205
|
+
|
206
|
+
```
|
207
|
+
|
208
|
+
Returns boolean indicating if an encrypted SSL is currently used. Connecting to the database via an unencrypted connection is a critical security risk.
|
209
|
+
|
176
210
|
### `index_usage`
|
177
211
|
|
178
212
|
```ruby
|
@@ -384,7 +418,7 @@ This command displays the total size of each table and materialized view in the
|
|
384
418
|
### `unused_indexes`
|
385
419
|
|
386
420
|
```ruby
|
387
|
-
RailsPGExtras.unused_indexes(args: {
|
421
|
+
RailsPGExtras.unused_indexes(args: { max_scans: 20 })
|
388
422
|
|
389
423
|
$ rake pg_extras:unused_indexes
|
390
424
|
|
@@ -543,6 +577,14 @@ RailsPGExtras.kill_all
|
|
543
577
|
|
544
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.
|
545
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
|
+
|
546
588
|
### `buffercache_stats`
|
547
589
|
|
548
590
|
```ruby
|
@@ -597,3 +639,4 @@ rake test_all
|
|
597
639
|
- [https://github.com/heroku/heroku-pg-extras](https://github.com/heroku/heroku-pg-extras)
|
598
640
|
- [https://hakibenita.com/postgresql-unused-index-size](https://hakibenita.com/postgresql-unused-index-size)
|
599
641
|
- [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)
|
642
|
+
- [https://wiki.postgresql.org/wiki/Index_Maintenance](https://wiki.postgresql.org/wiki/Index_Maintenance)
|
data/lib/rails-pg-extras.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
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'
|
5
7
|
|
6
8
|
module RailsPGExtras
|
7
9
|
QUERIES = RubyPGExtras::QUERIES
|
@@ -44,6 +46,18 @@ module RailsPGExtras
|
|
44
46
|
)
|
45
47
|
end
|
46
48
|
|
49
|
+
def self.diagnose(in_format: :display_table)
|
50
|
+
data = RailsPGExtras::DiagnoseData.call
|
51
|
+
|
52
|
+
if in_format == :display_table
|
53
|
+
RailsPGExtras::DiagnosePrint.call(data)
|
54
|
+
elsif in_format == :hash
|
55
|
+
data
|
56
|
+
else
|
57
|
+
raise "Invalid 'in_format' argument!"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
47
61
|
def self.connection
|
48
62
|
ActiveRecord::Base.connection
|
49
63
|
end
|
Binary file
|
data/rails-pg-extras-web.png
CHANGED
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
|
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:
|
4
|
+
version: 3.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-10-
|
11
|
+
date: 2021-10-29 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:
|
19
|
+
version: 3.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:
|
26
|
+
version: 3.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,9 +83,12 @@ 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
|
86
88
|
- lib/rails-pg-extras/railtie.rb
|
87
89
|
- lib/rails-pg-extras/tasks/all.rake
|
88
90
|
- lib/rails-pg-extras/version.rb
|
91
|
+
- rails-pg-extras-diagnose.png
|
89
92
|
- rails-pg-extras-web.png
|
90
93
|
- rails-pg-extras.gemspec
|
91
94
|
- spec/smoke_spec.rb
|