ruby-pg-extras 1.2.4 → 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: c1a8fb671f27484df51d29cc3e1a0be5eec628ae9146be825983b533ab88de05
4
- data.tar.gz: e5b0857287abe7efd8049d0977f5091f96c73f3dd1684910883c9c3f2f0f3c39
3
+ metadata.gz: 5d6fbc5ab6b75d6afab360ce585c6b99da6f7c7622da5c7d41ef5c9a352cf1d0
4
+ data.tar.gz: d6065e2b079138d523ea47dd5855793e6c53d45d7d0f59f6035a3f0cc22e97d1
5
5
  SHA512:
6
- metadata.gz: c54949bfff9d743bf9024b2b0c9a125cd714e7a1513ca61a3258c2ae5ee28019bbf83c94ceb4f7a0261fdf6ac7c72a720736e6010358d6d110324cd3ca1c2fb5
7
- data.tar.gz: 1a7b95e8e1e8b4a38775f3f9b483c6061bcb0d423c42e839c6a78cd398b47b6f692e4b881c99f8644510baa027f3270722573fa6d2c300402ae7a88506fe66c2
6
+ metadata.gz: 06235baa16b1433f94c6df83cdd764792ab85217ea0dae0880fedf981f84e7e4a12748e267462bc99a69096dd7706cf6893680d24f7b1e7da5fc8c502e4bc9fb
7
+ data.tar.gz: 0cce03aa9d5e05cc826c4d4835fc4fc8c3d50f3d062dfbdd7deec85d4b51366de68e264d3e3023f509464144ab80ae983975cecb50aaf3d333b1a8e0962df878
@@ -16,7 +16,8 @@ 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 install postgresql-client
19
+ - run: sudo apt-get update
20
+ - run: sudo apt install postgresql-client-11
20
21
  - run: dockerize -wait tcp://localhost:5432 -timeout 1m
21
22
  - run:
22
23
  name: Run specs
data/README.md CHANGED
@@ -16,6 +16,8 @@ Alternative versions:
16
16
 
17
17
  - [Python](https://github.com/pawurb/python-pg-extras)
18
18
 
19
+ - [Haskell](https://github.com/pawurb/haskell-pg-extras)
20
+
19
21
  ## Installation
20
22
 
21
23
  In your Gemfile
@@ -114,7 +116,7 @@ RubyPGExtras.index_cache_hit
114
116
  (truncated results for brevity)
115
117
  ```
116
118
 
117
- The same as `cache_hit` with each table's indexes cache hit info displayed seperately.
119
+ The same as `cache_hit` with each table's indexes cache hit info displayed separately.
118
120
 
119
121
  ### `table_cache_hit`
120
122
 
@@ -167,7 +169,7 @@ RubyPGExtras.locks
167
169
  (4 rows)
168
170
  ```
169
171
 
170
- 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.
172
+ 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.
171
173
 
172
174
  ### `all_locks`
173
175
 
@@ -197,7 +199,7 @@ RubyPGExtras.outliers
197
199
  (truncated results for brevity)
198
200
  ```
199
201
 
200
- 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).
202
+ 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).
201
203
 
202
204
  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.
203
205
 
@@ -306,7 +308,7 @@ RubyPGExtras.table_indexes_size
306
308
  (truncated results for brevity)
307
309
  ```
308
310
 
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()`.
311
+ 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()`.
310
312
 
311
313
  ### `total_table_size`
312
314
 
@@ -362,7 +364,7 @@ RubyPGExtras.seq_scans
362
364
  (truncated results for brevity)
363
365
  ```
364
366
 
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.
367
+ 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.
366
368
 
367
369
  ### `long_running_queries`
368
370
 
@@ -435,7 +437,7 @@ RubyPGExtras.vacuum_stats
435
437
  (truncated results for brevity)
436
438
  ```
437
439
 
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.
440
+ 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.
439
441
 
440
442
  ### `kill_all`
441
443
 
@@ -17,19 +17,30 @@ module RubyPGExtras
17
17
  unused_indexes vacuum_stats kill_all
18
18
  )
19
19
 
20
+ DEFAULT_ARGS = Hash.new({}).merge({
21
+ calls: { limit: 10 },
22
+ long_running_queries: { interval: '5 seconds' },
23
+ outliers: { limit: 10 },
24
+ unused_indexes: { min_scans: 50 }
25
+ })
26
+
20
27
  QUERIES.each do |query_name|
21
- define_singleton_method query_name do |options = { in_format: :display_table }|
28
+ define_singleton_method query_name do |options = {}|
22
29
  run_query(
23
30
  query_name: query_name,
24
- in_format: options.fetch(:in_format)
31
+ in_format: options.fetch(:in_format, :display_table),
32
+ args: options.fetch(:args, {})
25
33
  )
26
34
  end
27
35
  end
28
36
 
29
- def self.run_query(query_name:, in_format:)
30
- result = connection.exec(
37
+ def self.run_query(query_name:, in_format:, args: {})
38
+ sql = if (custom_args = DEFAULT_ARGS[query_name].merge(args)) != {}
39
+ sql_for(query_name: query_name) % custom_args
40
+ else
31
41
  sql_for(query_name: query_name)
32
- )
42
+ end
43
+ result = connection.exec(sql)
33
44
 
34
45
  display_result(
35
46
  result,
@@ -1,9 +1,9 @@
1
- /* 10 queries that have highest frequency of execution */
1
+ /* Queries that have highest frequency of execution */
2
2
 
3
3
  SELECT query AS qry,
4
4
  interval '1 millisecond' * total_time AS exec_time,
5
- to_char((total_time/sum(total_time) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
5
+ to_char((total_time/sum(total_time) OVER()) * 100, 'FM90D0') || '%%' AS prop_exec_time,
6
6
  to_char(calls, 'FM999G999G990') AS ncalls,
7
7
  interval '1 millisecond' * (blk_read_time + blk_write_time) AS sync_io_time
8
8
  FROM pg_stat_statements WHERE userid = (SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1)
9
- ORDER BY calls DESC LIMIT 10;
9
+ ORDER BY calls DESC LIMIT %{limit};
@@ -9,6 +9,6 @@ FROM
9
9
  WHERE
10
10
  pg_stat_activity.query <> ''::text
11
11
  AND state <> 'idle'
12
- AND now() - pg_stat_activity.query_start > interval '5 minutes'
12
+ AND now() - pg_stat_activity.query_start > interval '%{interval}'
13
13
  ORDER BY
14
14
  now() - pg_stat_activity.query_start DESC;
@@ -1,10 +1,10 @@
1
- /* 10 queries that have longest execution time in aggregate */
1
+ /* Queries that have longest execution time in aggregate */
2
2
 
3
3
  SELECT interval '1 millisecond' * total_time AS total_exec_time,
4
- to_char((total_time/sum(total_time) OVER()) * 100, 'FM90D0') || '%' AS prop_exec_time,
4
+ to_char((total_time/sum(total_time) OVER()) * 100, 'FM90D0') || '%%' AS prop_exec_time,
5
5
  to_char(calls, 'FM999G999G999G990') AS ncalls,
6
6
  interval '1 millisecond' * (blk_read_time + blk_write_time) AS sync_io_time,
7
7
  query AS query
8
8
  FROM pg_stat_statements WHERE userid = (SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1)
9
9
  ORDER BY total_time DESC
10
- LIMIT 10;
10
+ LIMIT %{limit};
@@ -11,6 +11,6 @@ SELECT
11
11
  idx_scan as index_scans
12
12
  FROM pg_stat_user_indexes ui
13
13
  JOIN pg_index i ON ui.indexrelid = i.indexrelid
14
- WHERE NOT indisunique AND idx_scan < 50 AND pg_relation_size(relid) > 5 * 8192
14
+ WHERE NOT indisunique AND idx_scan < %{min_scans} AND pg_relation_size(relid) > 5 * 8192
15
15
  ORDER BY pg_relation_size(i.indexrelid) / nullif(idx_scan, 0) DESC NULLS FIRST,
16
16
  pg_relation_size(i.indexrelid) DESC;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPGExtras
4
- VERSION = "1.2.4"
4
+ VERSION = "1.3.0"
5
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.2.4
4
+ version: 1.3.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-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: pg
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.1.2
132
+ rubygems_version: 3.1.4
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Ruby PostgreSQL performance database insights