rails-pg-extras 1.2.0 → 1.3.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: e9d6f8bc147f14fc0aa89bdb07e0f781e18b38c5abc01fe7d44e910ae08a326b
4
- data.tar.gz: 123eed80a930a20d69abcbbab8968ced75fcc046165b70637b1b39ee3cbdadbd
3
+ metadata.gz: bb4905b231d556cd0a389c53a77b59e74f6d11faf45d6e3fa9e17b456cd0349a
4
+ data.tar.gz: 94e5c6c7ba1d48f403b069b5f7b7d24ae25e20f072166cf59d54fa891bf4662a
5
5
  SHA512:
6
- metadata.gz: 49890c367f5f4998d63876cade207260e20dfab9ca0b6dd54fc8f764b234fecb7b152c630435e445f3b3c7f0a744b4d29f3c70acd3670b50f4381078dfab12ad
7
- data.tar.gz: 5b832ab6911073cb95024e26d698ee98acec40c1eb14976cda51e00adb9fb24c576e26f7a9cb6be932ba2abba640f1d504a0a7e1d1c66ff6249c37fba1cad46c
6
+ metadata.gz: 3c41ba2e65e0d892690469fb232d09e58e02aa138ee17155014795963fc86a9be94d4c1d6482ca6e3564ab14a8b9263e1f7828c18ab7173cc3d0f16190ad4e12
7
+ data.tar.gz: 1aa1554a5c26f89501e59462ed4af2efc90b7d3c16b07922d71a3c7d2140096ffac47c19584edda2b4af0bc45261ea8c35f48431c94451ba86d900b51dd5a705
@@ -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
@@ -4,7 +4,19 @@ 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
- Not using Rails? Check out the core dependency [pure Ruby version](https://github.com/pawurb/ruby-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
+
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
+ - [Haskell](https://github.com/pawurb/haskell-pg-extras)
8
20
 
9
21
  ## Installation
10
22
 
@@ -14,6 +26,19 @@ In your Gemfile
14
26
  gem "rails-pg-extras"
15
27
  ```
16
28
 
29
+ Some of the queries (e.g., `calls` and `outliers`) require [pg_stat_statements](https://www.postgresql.org/docs/current/pgstatstatements.html) extension enabled.
30
+
31
+ You can check if it is enabled in your database by running:
32
+
33
+ ```ruby
34
+ RailsPGExtras.extensions
35
+ ```
36
+ You should see the similar line in the output:
37
+
38
+ ```bash
39
+ | pg_stat_statements | 1.7 | 1.7 | track execution statistics of all SQL statements executed |
40
+ ```
41
+
17
42
  ## Usage
18
43
 
19
44
  Each command can be used as a rake task, or a directly from the Ruby code.
@@ -83,7 +108,7 @@ $ rake pg_extras:index_cache_hit
83
108
  (truncated results for brevity)
84
109
  ```
85
110
 
86
- The same as `cache_hit` with each table's indexes cache hit info displayed seperately.
111
+ The same as `cache_hit` with each table's indexes cache hit info displayed separately.
87
112
 
88
113
  ### `table_cache_hit`
89
114
 
@@ -134,7 +159,7 @@ $ rake pg_extras:locks
134
159
  (4 rows)
135
160
  ```
136
161
 
137
- 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.
162
+ 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.
138
163
 
139
164
  ### `all_locks`
140
165
 
@@ -160,7 +185,7 @@ $ rake pg_extras:outliers
160
185
  (truncated results for brevity)
161
186
  ```
162
187
 
163
- 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).
188
+ 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).
164
189
 
165
190
  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.
166
191
 
@@ -248,7 +273,7 @@ This command displays the size of each table and materialized view in the databa
248
273
  ### `table_indexes_size`
249
274
 
250
275
  ```
251
- $ rake pg_extras:table-indexes-size
276
+ $ rake pg_extras:table_indexes_size
252
277
 
253
278
  table | indexes_size
254
279
  ---------------------------------------------------------------+--------------
@@ -260,7 +285,7 @@ $ rake pg_extras:table-indexes-size
260
285
  (truncated results for brevity)
261
286
  ```
262
287
 
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()`.
288
+ 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()`.
264
289
 
265
290
  ### `total_table_size`
266
291
 
@@ -277,7 +302,7 @@ $ rake pg_extras:total_table_size
277
302
  (truncated results for brevity)
278
303
  ```
279
304
 
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.
305
+ 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
306
 
282
307
  ### `unused_indexes`
283
308
 
@@ -320,7 +345,7 @@ $ rake pg_extras:seq_scans
320
345
  (truncated results for brevity)
321
346
  ```
322
347
 
323
- 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.
348
+ 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.
324
349
 
325
350
  ### `long_running_queries`
326
351
 
@@ -386,7 +411,7 @@ $ rake pg_extras:vacuum_stats
386
411
  (truncated results for brevity)
387
412
  ```
388
413
 
389
- 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.
414
+ 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.
390
415
 
391
416
  ### `kill_all`
392
417
 
@@ -398,6 +423,16 @@ RailsPGExtras.kill_all
398
423
 
399
424
  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.
400
425
 
426
+ ### `extensions`
427
+
428
+ ```ruby
429
+
430
+ RailsPGExtras.extensions
431
+
432
+ ```
433
+
434
+ This command lists all the currently installed and available PostgreSQL extensions.
435
+
401
436
  ### mandelbrot
402
437
 
403
438
  ```
@@ -405,9 +440,3 @@ $ rake pg_extras:mandelbrot
405
440
  ```
406
441
 
407
442
  This command outputs the Mandelbrot set, calculated through SQL.
408
-
409
- ## FAQ
410
-
411
- * Does is not violate the Heroku PG Extras license?
412
-
413
- The original plugin is MIT based so it means that copying and redistribution in any format is permitted.
@@ -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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsPGExtras
2
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
3
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.0
4
+ version: 1.3.0
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-05-13 00:00:00.000000000 Z
11
+ date: 2021-01-22 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.0
19
+ version: 1.3.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.0
26
+ version: 1.3.0
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.0.6
112
- signing_key:
111
+ rubygems_version: 3.1.4
112
+ signing_key:
113
113
  specification_version: 4
114
114
  summary: Rails PostgreSQL performance database insights
115
115
  test_files: