rails-pg-extras 1.2.3 → 1.5.0

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: 96b32211012cd93252e2fd58f870713a4717f57eaed8071b6fd3c32aeac31264
4
- data.tar.gz: e4001940a894b757284e650c50400357f3d01e2e0273841fdf243099e88a8042
3
+ metadata.gz: 897f027634b0313e42a13d864678eac7f0280c00a9a39ca5d668cabbba970b02
4
+ data.tar.gz: d23efda1f8afcbd989278b9362baacb4882796115d7e70263a812787f95de340
5
5
  SHA512:
6
- metadata.gz: 6ccc4603aa90aba0229aa0c2c7ac76c9377e90e8e8704a107d52588472b5c4e05b8d3aeb8acb7ba2a6ff4a5fc9003c17c797932c6baaa337270314fb70ff47db
7
- data.tar.gz: c73c394b1d2c5692eafa973f0daf6751e6e72b33b7baba67d69bc7385a60d058ada88a1d6ff6e52812daab647b6e5109bacef1cb4fd1cea23049fe1a2f9ca2c0
6
+ metadata.gz: 612408e64b97f03c70dcab7525cce2be8cafa4b9cf5eca27dd88013b5d74ffd08c5e68532599158c697d8754b9fa1ee534bbb698a9603df489d7394b1d036dab
7
+ data.tar.gz: f9c66eb8837a6720de96132e0941364aa3e83f627d52a04221efbbe2d361c1c9f2a24635057868c631ecee54fe42a9aa599b9a354f82341f84cd7a0ff2a524b2
data/.circleci/config.yml CHANGED
@@ -16,6 +16,7 @@ jobs:
16
16
  - run: gem update --system
17
17
  - run: gem install bundler
18
18
  - run: bundle install --path vendor/bundle
19
+ - run: sudo apt-get update
19
20
  - run: sudo apt install postgresql-client
20
21
  - run: dockerize -wait tcp://localhost:5432 -timeout 1m
21
22
  - run:
data/README.md CHANGED
@@ -16,6 +16,8 @@ Alternative versions:
16
16
 
17
17
  - [Python](https://github.com/pawurb/ecto_psql_extras)
18
18
 
19
+ - [Haskell](https://github.com/pawurb/haskell-pg-extras)
20
+
19
21
  ## Installation
20
22
 
21
23
  In your Gemfile
@@ -76,6 +78,13 @@ RailsPGExtras.cache_hit(in_format: :raw) =>
76
78
  #<PG::Result:0x00007f75777f7328 status=PGRES_TUPLES_OK ntuples=2 nfields=2 cmd_tuples=2>
77
79
  ```
78
80
 
81
+ Some methods accept an optional `args` param allowing you to customize queries:
82
+
83
+ ```ruby
84
+ RailsPGExtras.long_running_queries(args: { threshold: "200 milliseconds" })
85
+
86
+ ```
87
+
79
88
  ## Available methods
80
89
 
81
90
  ### `cache_hit`
@@ -106,7 +115,7 @@ $ rake pg_extras:index_cache_hit
106
115
  (truncated results for brevity)
107
116
  ```
108
117
 
109
- The same as `cache_hit` with each table's indexes cache hit info displayed seperately.
118
+ The same as `cache_hit` with each table's indexes cache hit info displayed separately.
110
119
 
111
120
  ### `table_cache_hit`
112
121
 
@@ -157,7 +166,7 @@ $ rake pg_extras:locks
157
166
  (4 rows)
158
167
  ```
159
168
 
160
- This command displays queries that have taken out an exlusive 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.
169
+ 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.
161
170
 
162
171
  ### `all_locks`
163
172
 
@@ -183,7 +192,7 @@ $ rake pg_extras:outliers
183
192
  (truncated results for brevity)
184
193
  ```
185
194
 
186
- This command displays statements, obtained from `pg_stat_statements`, ordered by the amount of time to execute in aggregate. This includes the statement itself, the total execution time for that statement, the proportion of total execution time for all statements that statement has taken up, the number of times that statement has been called, and the amount of time that statement spent on synchronous I/O (reading/writing from the filesystem).
195
+ This command displays statements, obtained from `pg_stat_statements`, ordered by the amount of time to execute in aggregate. This includes the statement itself, the total execution time for that statement, the proportion of total execution time for all statements that statement has taken up, the number of times that statement has been called, and the amount of time that statement spent on synchronous I/O (reading/writing from the file system).
187
196
 
188
197
  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.
189
198
 
@@ -283,7 +292,7 @@ $ rake pg_extras:table_indexes_size
283
292
  (truncated results for brevity)
284
293
  ```
285
294
 
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()`.
295
+ This command displays the total size of indexes for each table and materialized view, in MB. It is calculated by using the system administration function `pg_indexes_size()`.
287
296
 
288
297
  ### `total_table_size`
289
298
 
@@ -317,6 +326,22 @@ $ rake pg_extras:unused_indexes
317
326
 
318
327
  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.
319
328
 
329
+ ### `null_indexes`
330
+
331
+ ```ruby
332
+
333
+ $ rake pg_extras:null_indexes
334
+
335
+ oid | index | index_size | unique | indexed_column | null_frac | expected_saving
336
+ ---------+--------------------+------------+--------+----------------+-----------+-----------------
337
+ 183764 | users_reset_token | 1445 MB | t | reset_token | 97.00% | 1401 MB
338
+ 88732 | plan_cancelled_at | 539 MB | f | cancelled_at | 8.30% | 44 MB
339
+ 9827345 | users_email | 18 MB | t | email | 28.67% | 5160 kB
340
+
341
+ ```
342
+
343
+ This commands 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. [Source and more info](https://hakibenita.com/postgresql-unused-index-size).
344
+
320
345
  ### `seq_scans`
321
346
 
322
347
  ```
@@ -343,7 +368,7 @@ $ rake pg_extras:seq_scans
343
368
  (truncated results for brevity)
344
369
  ```
345
370
 
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.
371
+ 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.
347
372
 
348
373
  ### `long_running_queries`
349
374
 
@@ -409,7 +434,7 @@ $ rake pg_extras:vacuum_stats
409
434
  (truncated results for brevity)
410
435
  ```
411
436
 
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.
437
+ This command displays statistics related to vacuum operations for each table, including an estimation 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.
413
438
 
414
439
  ### `kill_all`
415
440
 
@@ -5,20 +5,26 @@ require 'ruby-pg-extras'
5
5
 
6
6
  module RailsPGExtras
7
7
  QUERIES = RubyPGExtras::QUERIES
8
+ DEFAULT_ARGS = RubyPGExtras::DEFAULT_ARGS
8
9
 
9
10
  QUERIES.each do |query_name|
10
- define_singleton_method query_name do |options = { in_format: :display_table }|
11
+ define_singleton_method query_name do |options = {}|
11
12
  run_query(
12
13
  query_name: query_name,
13
- in_format: options.fetch(:in_format)
14
+ in_format: options.fetch(:in_format, :display_table),
15
+ args: options.fetch(:args, {})
14
16
  )
15
17
  end
16
18
  end
17
19
 
18
- def self.run_query(query_name:, in_format:)
19
- result = connection.execute(
20
+ def self.run_query(query_name:, in_format:, args: {})
21
+ sql = if (custom_args = DEFAULT_ARGS[query_name].merge(args)) != {}
22
+ RubyPGExtras.sql_for(query_name: query_name) % custom_args
23
+ else
20
24
  RubyPGExtras.sql_for(query_name: query_name)
21
- )
25
+ end
26
+
27
+ result = connection.execute(sql)
22
28
 
23
29
  RubyPGExtras.display_result(
24
30
  result,
@@ -3,9 +3,19 @@
3
3
  require 'rails-pg-extras'
4
4
 
5
5
  namespace :pg_extras do
6
+ task :establish_connection do
7
+ if ENV['DATABASE_URL'].present?
8
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
9
+ else
10
+ db_config_file = File.read('config/database.yml')
11
+ db_config = YAML::load(ERB.new(db_config_file).result)
12
+ ActiveRecord::Base.establish_connection(db_config[Rails.env])
13
+ end
14
+ end
15
+
6
16
  RailsPGExtras::QUERIES.each do |query_name|
7
17
  desc RubyPGExtras.description_for(query_name: query_name)
8
- task query_name.to_sym => :environment do
18
+ task query_name.to_sym => :establish_connection do
9
19
  RailsPGExtras.public_send(query_name)
10
20
  end
11
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPGExtras
4
- VERSION = "1.2.3"
4
+ VERSION = "1.5.0"
5
5
  end
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.2.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2021-02-13 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.2.3
19
+ version: 1.5.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.2.3
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.1.2
111
+ rubygems_version: 3.1.4
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Rails PostgreSQL performance database insights