ruby-pg-extras 5.2.1 → 5.3.1

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: 20d04a4adbd7ca17e382e967960df93f1be7f6aba25d2ec6e72ac68a7dfdf190
4
- data.tar.gz: b2053fb9ae80ea5726c866eb61c1aaa8755ec45fb259e2763387496ba0d99cb0
3
+ metadata.gz: 79aedbc5d3b30aadde2362bceebac04fe7bc3d3a27e8fc47f1f6b6c0ae287616
4
+ data.tar.gz: ceea8978021edc90088a012a1fec34c0502da15f5ce60356074d741bcbc82682
5
5
  SHA512:
6
- metadata.gz: 03164aac5bb96d95a84bfd49cd1bd722f5e21fe00456bd3e27f835261e204c4217f88960834be870cd8380060a25b9c3cc5070ac3270662a06cc2bdd1f69ad57
7
- data.tar.gz: '0382f05ac851f45db8c11272334e49326448b1bd30ef2b68009965d88bf222a497c91c4c8c34d4891c9010a238ade3da9d071e9e8151e9241f21b37b46c385b6'
6
+ metadata.gz: 6cd117553f43c9b211cb07e313f2b83932992a38e5217bdee70dd9d3688e441919bc0dd5a3db32cd7dc20a5c35dddd7b61e34a26ba403f690f3a9d3531a16eb4
7
+ data.tar.gz: 484c04040d0d1579ce01e9874fd7f7df4dbc6209f3e262e55fc6b77246072c1315962e223f915b5311fe08a89268f7ac0193a04e50179307001ac37e5690f0e4
@@ -0,0 +1,128 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Run PostgreSQL 11
19
+ run: |
20
+ docker run --env POSTGRES_USER=postgres \
21
+ --env POSTGRES_DB=ruby-pg-extras-test \
22
+ --env POSTGRES_PASSWORD=secret \
23
+ -d -p 5432:5432 postgres:11.18-alpine \
24
+ postgres -c shared_preload_libraries=pg_stat_statements
25
+ - name: Run PostgreSQL 12
26
+ run: |
27
+ docker run --env POSTGRES_USER=postgres \
28
+ --env POSTGRES_DB=ruby-pg-extras-test \
29
+ --env POSTGRES_PASSWORD=secret \
30
+ -d -p 5433:5432 postgres:12.13-alpine \
31
+ postgres -c shared_preload_libraries=pg_stat_statements
32
+ - name: Run PostgreSQL 13
33
+ run: |
34
+ docker run --env POSTGRES_USER=postgres \
35
+ --env POSTGRES_DB=ruby-pg-extras-test \
36
+ --env POSTGRES_PASSWORD=secret \
37
+ -d -p 5434:5432 postgres:13.9-alpine \
38
+ postgres -c shared_preload_libraries=pg_stat_statements
39
+ - name: Run PostgreSQL 14
40
+ run: |
41
+ docker run --env POSTGRES_USER=postgres \
42
+ --env POSTGRES_DB=ruby-pg-extras-test \
43
+ --env POSTGRES_PASSWORD=secret \
44
+ -d -p 5435:5432 postgres:14.6-alpine \
45
+ postgres -c shared_preload_libraries=pg_stat_statements
46
+ - name: Run PostgreSQL 15
47
+ run: |
48
+ docker run --env POSTGRES_USER=postgres \
49
+ --env POSTGRES_DB=ruby-pg-extras-test \
50
+ --env POSTGRES_PASSWORD=secret \
51
+ -d -p 5436:5432 postgres:15.1-alpine \
52
+ postgres -c shared_preload_libraries=pg_stat_statements
53
+ sleep 15
54
+ - name: Set up Ruby ${{ matrix.ruby-version }}
55
+ uses: ruby/setup-ruby@v1
56
+ with:
57
+ ruby-version: ${{ matrix.ruby-version }}
58
+ - name: Setup dependencies
59
+ run: |
60
+ gem update --system
61
+ gem install bundler
62
+ sudo apt-get update --allow-releaseinfo-change
63
+ sudo apt install postgresql-client
64
+ sudo apt install libpq-dev
65
+ bundle config set --local path 'vendor/bundle'
66
+ bundle install
67
+ sleep 10
68
+ - name: Run tests for PG 11
69
+ env:
70
+ PG_VERSION: 11
71
+ POSTGRES_HOST: localhost
72
+ POSTGRES_USER: postgres
73
+ POSTGRES_DB: ruby-pg-extras-test
74
+ POSTGRES_PASSWORD: secret
75
+ DATABASE_URL: postgresql://postgres:secret@localhost:5432/ruby-pg-extras-test
76
+ run: |
77
+ bundle exec rspec spec/
78
+ - name: Run tests for PG 11
79
+ env:
80
+ PG_VERSION: 11
81
+ POSTGRES_HOST: localhost
82
+ POSTGRES_USER: postgres
83
+ POSTGRES_DB: ruby-pg-extras-test
84
+ POSTGRES_PASSWORD: secret
85
+ DATABASE_URL: postgresql://postgres:secret@localhost:5432/ruby-pg-extras-test
86
+ run: |
87
+ bundle exec rspec spec/
88
+ - name: Run tests for PG 12
89
+ env:
90
+ PG_VERSION: 12
91
+ POSTGRES_HOST: localhost
92
+ POSTGRES_USER: postgres
93
+ POSTGRES_DB: ruby-pg-extras-test
94
+ POSTGRES_PASSWORD: secret
95
+ DATABASE_URL: postgresql://postgres:secret@localhost:5433/ruby-pg-extras-test
96
+ run: |
97
+ bundle exec rspec spec/
98
+ - name: Run tests for PG 13
99
+ env:
100
+ PG_VERSION: 13
101
+ POSTGRES_HOST: localhost
102
+ POSTGRES_USER: postgres
103
+ POSTGRES_DB: ruby-pg-extras-test
104
+ POSTGRES_PASSWORD: secret
105
+ DATABASE_URL: postgresql://postgres:secret@localhost:5434/ruby-pg-extras-test
106
+ run: |
107
+ bundle exec rspec spec/
108
+ - name: Run tests for PG 14
109
+ env:
110
+ PG_VERSION: 14
111
+ POSTGRES_HOST: localhost
112
+ POSTGRES_USER: postgres
113
+ POSTGRES_DB: ruby-pg-extras-test
114
+ POSTGRES_PASSWORD: secret
115
+ DATABASE_URL: postgresql://postgres:secret@localhost:5435/ruby-pg-extras-test
116
+ run: |
117
+ bundle exec rspec spec/
118
+ - name: Run tests for PG 15
119
+ env:
120
+ PG_VERSION: 15
121
+ POSTGRES_HOST: localhost
122
+ POSTGRES_USER: postgres
123
+ POSTGRES_DB: ruby-pg-extras-test
124
+ POSTGRES_PASSWORD: secret
125
+ DATABASE_URL: postgresql://postgres:secret@localhost:5436/ruby-pg-extras-test
126
+ run: |
127
+ bundle exec rspec spec/
128
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ruby PG Extras [![Gem Version](https://badge.fury.io/rb/ruby-pg-extras.svg)](https://badge.fury.io/rb/ruby-pg-extras) [![CircleCI](https://circleci.com/gh/pawurb/ruby-pg-extras.svg?style=svg)](https://circleci.com/gh/pawurb/ruby-pg-extras)
1
+ # Ruby PG Extras [![Gem Version](https://badge.fury.io/rb/ruby-pg-extras.svg)](https://badge.fury.io/rb/ruby-pg-extras) [![GH Actions](https://github.com/pawurb/ruby-pg-extras/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/ruby-pg-extras/actions)
2
2
 
3
3
  Ruby port of [Heroku PG Extras](https://github.com/heroku/heroku-pg-extras) with several additions and improvements. The goal of this project is to provide powerful insights into the PostgreSQL database for Ruby apps that are not using the Heroku PostgreSQL plugin.
4
4
 
@@ -106,7 +106,7 @@ The simplest way to start using pg-extras is to execute a `diagnose` method. It
106
106
  RubyPgExtras.diagnose
107
107
  ```
108
108
 
109
- ![Diagnose report](https://github.com/pawurb/ruby-pg-extras/raw/master/ruby-pg-extras-diagnose.png)
109
+ ![Diagnose report](https://github.com/pawurb/ruby-pg-extras/raw/main/ruby-pg-extras-diagnose.png)
110
110
 
111
111
  Keep reading to learn about methods that `diagnose` uses under the hood.
112
112
 
@@ -362,18 +362,18 @@ This command displays the total size of all indexes on the database, in MB. It i
362
362
 
363
363
  RubyPgExtras.index_size
364
364
 
365
- name | size
366
- ---------------------------------------------------------------+---------
367
- idx_activity_attemptable_and_type_lesson_enrollment | 5196 MB
368
- index_enrollment_attemptables_by_attempt_and_last_in_group | 4045 MB
369
- index_attempts_on_student_id | 2611 MB
370
- enrollment_activity_attemptables_pkey | 2513 MB
371
- index_attempts_on_student_id_final_attemptable_type | 2466 MB
372
- attempts_pkey | 2466 MB
373
- index_attempts_on_response_id | 2404 MB
374
- index_attempts_on_enrollment_id | 1957 MB
375
- index_enrollment_attemptables_by_enrollment_activity_id | 1789 MB
376
- enrollment_activities_pkey | 458 MB
365
+ name | size | schema |
366
+ ---------------------------------------------------------------+-------------------
367
+ idx_activity_attemptable_and_type_lesson_enrollment | 5196 MB | public |
368
+ index_enrollment_attemptables_by_attempt_and_last_in_group | 4045 MB | public |
369
+ index_attempts_on_student_id | 2611 MB | custom |
370
+ enrollment_activity_attemptables_pkey | 2513 MB | custom |
371
+ index_attempts_on_student_id_final_attemptable_type | 2466 MB | custom |
372
+ attempts_pkey | 2466 MB | custom |
373
+ index_attempts_on_response_id | 2404 MB | public |
374
+ index_attempts_on_enrollment_id | 1957 MB | public |
375
+ index_enrollment_attemptables_by_enrollment_activity_id | 1789 MB | public |
376
+ enrollment_activities_pkey | 458 MB | public |
377
377
  (truncated results for brevity)
378
378
  ```
379
379
 
@@ -385,13 +385,13 @@ This command displays the size of each each index in the database, in MB. It is
385
385
 
386
386
  RubyPgExtras.table_size
387
387
 
388
- name | size
389
- ---------------------------------------------------------------+---------
390
- learning_coaches | 196 MB
391
- states | 145 MB
392
- grade_levels | 111 MB
393
- charities_customers | 73 MB
394
- charities | 66 MB
388
+ name | size | schema |
389
+ ---------------------------------------------------------------+-------------------
390
+ learning_coaches | 196 MB | public |
391
+ states | 145 MB | public |
392
+ grade_levels | 111 MB | custom |
393
+ charities_customers | 73 MB | public |
394
+ charities | 66 MB | public |
395
395
  (truncated results for brevity)
396
396
  ```
397
397
 
@@ -27,26 +27,29 @@ module RubyPgExtras
27
27
  buffercache_usage ssl_used connections
28
28
  )
29
29
 
30
+ DEFAULT_SCHEMA = ENV["PG_EXTRAS_SCHEMA"] || 'public'
31
+
30
32
  DEFAULT_ARGS = Hash.new({}).merge({
31
33
  calls: { limit: 10 },
32
34
  calls_legacy: { limit: 10 },
33
35
  long_running_queries: { threshold: "500 milliseconds" },
34
36
  locks: { limit: 20 },
37
+ blocking: { limit: 20 },
35
38
  outliers: { limit: 10 },
36
39
  outliers_legacy: { limit: 10 },
37
40
  buffercache_stats: { limit: 10 },
38
41
  buffercache_usage: { limit: 20 },
39
- unused_indexes: { max_scans: 50, schema: "public" },
42
+ unused_indexes: { max_scans: 50, schema: DEFAULT_SCHEMA },
40
43
  null_indexes: { min_relation_size_mb: 10 },
41
- index_usage: { schema: "public" },
42
- index_cache_hit: { schema: "public" },
43
- table_cache_hit: { schema: "public" },
44
- index_scans: { schema: "public" },
45
- cache_hit: { schema: "public" },
46
- seq_scans: { schema: "public" },
47
- table_index_scans: { schema: "public" },
48
- records_rank: { schema: "public" },
49
- tables: { schema: "public" },
44
+ index_usage: { schema: DEFAULT_SCHEMA },
45
+ index_cache_hit: { schema: DEFAULT_SCHEMA },
46
+ table_cache_hit: { schema: DEFAULT_SCHEMA },
47
+ index_scans: { schema: DEFAULT_SCHEMA },
48
+ cache_hit: { schema: DEFAULT_SCHEMA },
49
+ seq_scans: { schema: DEFAULT_SCHEMA },
50
+ table_index_scans: { schema: DEFAULT_SCHEMA },
51
+ records_rank: { schema: DEFAULT_SCHEMA },
52
+ tables: { schema: DEFAULT_SCHEMA },
50
53
  kill_pid: { pid: 0 }
51
54
  })
52
55
 
@@ -5,7 +5,9 @@ SELECT bl.pid AS blocked_pid,
5
5
  now() - ka.query_start AS blocking_duration,
6
6
  kl.pid AS blocking_pid,
7
7
  a.query AS blocked_statement,
8
- now() - a.query_start AS blocked_duration
8
+ now() - a.query_start AS blocked_duration,
9
+ a.application_name AS blocked_sql_app,
10
+ ka.application_name AS blocking_sql_app
9
11
  FROM pg_catalog.pg_locks bl
10
12
  JOIN pg_catalog.pg_stat_activity a
11
13
  ON bl.pid = a.pid
@@ -13,4 +15,6 @@ JOIN pg_catalog.pg_locks kl
13
15
  JOIN pg_catalog.pg_stat_activity ka
14
16
  ON kl.pid = ka.pid
15
17
  ON bl.transactionid = kl.transactionid AND bl.pid != kl.pid
16
- WHERE NOT bl.granted;
18
+ WHERE NOT bl.granted
19
+ ORDER BY blocked_duration DESC
20
+ LIMIT %{limit};
@@ -1,11 +1,12 @@
1
1
  /* The size of indexes, descending by size */
2
2
 
3
3
  SELECT c.relname AS name,
4
- pg_size_pretty(sum(c.relpages::bigint*8192)::bigint) AS size
4
+ pg_size_pretty(sum(c.relpages::bigint*8192)::bigint) AS size,
5
+ n.nspname as schema
5
6
  FROM pg_class c
6
7
  LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
7
8
  WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
8
9
  AND n.nspname !~ '^pg_toast'
9
10
  AND c.relkind='i'
10
- GROUP BY c.relname
11
+ GROUP BY c.relname, n.nspname
11
12
  ORDER BY sum(c.relpages) DESC;
@@ -6,17 +6,20 @@ SELECT
6
6
  pg_size_pretty(pg_relation_size(c.oid)) AS index_size,
7
7
  i.indisunique AS unique,
8
8
  a.attname AS indexed_column,
9
+ s.tablename AS table,
9
10
  CASE s.null_frac
10
11
  WHEN 0 THEN ''
11
12
  ELSE to_char(s.null_frac * 100, '999.00%%')
12
13
  END AS null_frac,
13
- pg_size_pretty((pg_relation_size(c.oid) * s.null_frac)::bigint) AS expected_saving
14
+ pg_size_pretty((pg_relation_size(c.oid) * s.null_frac)::bigint) AS expected_saving,
15
+ n.nspname as schema
14
16
  FROM
15
17
  pg_class c
16
18
  JOIN pg_index i ON i.indexrelid = c.oid
17
19
  JOIN pg_attribute a ON a.attrelid = c.oid
18
20
  JOIN pg_class c_table ON c_table.oid = i.indrelid
19
21
  JOIN pg_indexes ixs ON c.relname = ixs.indexname
22
+ LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
20
23
  LEFT JOIN pg_stats s ON s.tablename = c_table.relname AND a.attname = s.attname
21
24
  WHERE
22
25
  -- Primary key cannot be partial
@@ -1,7 +1,8 @@
1
1
  /* Size of the tables (excluding indexes), descending by size */
2
2
 
3
3
  SELECT c.relname AS name,
4
- pg_size_pretty(pg_table_size(c.oid)) AS size
4
+ pg_size_pretty(pg_table_size(c.oid)) AS size,
5
+ n.nspname as schema
5
6
  FROM pg_class c
6
7
  LEFT JOIN pg_namespace n ON (n.oid = c.relnamespace)
7
8
  WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPgExtras
4
- VERSION = "5.2.1"
4
+ VERSION = "5.3.1"
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: 5.2.1
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -75,7 +75,7 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - ".circleci/config.yml"
78
+ - ".github/workflows/ci.yml"
79
79
  - ".gitignore"
80
80
  - Gemfile
81
81
  - LICENSE.txt
@@ -144,7 +144,7 @@ licenses:
144
144
  - MIT
145
145
  metadata:
146
146
  rubygems_mfa_required: 'true'
147
- post_install_message:
147
+ post_install_message:
148
148
  rdoc_options: []
149
149
  require_paths:
150
150
  - lib
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.1.6
163
- signing_key:
162
+ rubygems_version: 3.3.7
163
+ signing_key:
164
164
  specification_version: 4
165
165
  summary: Ruby PostgreSQL performance database insights
166
166
  test_files:
data/.circleci/config.yml DELETED
@@ -1,71 +0,0 @@
1
- version: 2
2
- jobs:
3
- test:
4
- docker:
5
- - image: cimg/ruby:2.7.6
6
- environment:
7
- DATABASE_URL: postgresql://postgres:secret@localhost:5432/ruby-pg-extras-test
8
- - image: cimg/postgres:11.15
9
- command: postgres -c shared_preload_libraries=pg_stat_statements
10
- name: postgres11
11
- environment:
12
- POSTGRES_USER: postgres
13
- POSTGRES_DB: ruby-pg-extras-test
14
- POSTGRES_PASSWORD: secret
15
- - image: cimg/postgres:12.10
16
- command: postgres -c shared_preload_libraries=pg_stat_statements
17
- name: postgres12
18
- environment:
19
- POSTGRES_USER: postgres
20
- POSTGRES_DB: ruby-pg-extras-test
21
- POSTGRES_PASSWORD: secret
22
- - image: cimg/postgres:13.6
23
- command: postgres -c shared_preload_libraries=pg_stat_statements
24
- name: postgres13
25
- environment:
26
- POSTGRES_USER: postgres
27
- POSTGRES_DB: ruby-pg-extras-test
28
- POSTGRES_PASSWORD: secret
29
- - image: cimg/postgres:14.2
30
- command: postgres -c shared_preload_libraries=pg_stat_statements
31
- name: postgres14
32
- environment:
33
- POSTGRES_USER: postgres
34
- POSTGRES_DB: ruby-pg-extras-test
35
- POSTGRES_PASSWORD: secret
36
- parallelism: 1
37
- steps:
38
- - checkout
39
- - run: gem update --system
40
- - run: gem install bundler
41
- - run: sudo apt-get update --allow-releaseinfo-change
42
- - run: sudo apt install postgresql-client
43
- - run: sudo apt install libpq-dev
44
- - run: bundle config set --local path 'vendor/bundle'
45
- - run: bundle install
46
- - run: dockerize -wait tcp://postgres11:5432 -timeout 1m
47
- - run:
48
- name: Run specs for PG 11
49
- environment:
50
- DATABASE_URL: postgresql://postgres:secret@postgres11:5432/ruby-pg-extras-test
51
- command: bundle exec rspec spec/
52
- - run:
53
- name: Run specs for PG 12
54
- environment:
55
- DATABASE_URL: postgresql://postgres:secret@postgres12:5432/ruby-pg-extras-test
56
- command: bundle exec rspec spec/
57
- - run:
58
- name: Run specs for PG 13
59
- environment:
60
- DATABASE_URL: postgresql://postgres:secret@postgres13:5432/ruby-pg-extras-test
61
- command: bundle exec rspec spec/
62
- - run:
63
- name: Run specs for PG 14
64
- environment:
65
- DATABASE_URL: postgresql://postgres:secret@postgres14:5432/ruby-pg-extras-test
66
- command: bundle exec rspec spec/
67
- workflows:
68
- version: 2
69
- test:
70
- jobs:
71
- - test