ruby-pg-extras 2.0.0 → 2.1.0

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: d71c264c67135e083a2072dfa8248ff46210ae386c813f23417b70c6084d01c2
4
- data.tar.gz: 8749efb98e35fb17443f16a1e9a06cd8ce4e70d87f32aef4a20f21b22bfd56b9
3
+ metadata.gz: a88ff7e79fc4b77781012f9ee52afeee2462dcc46177d6bec8d24885c9822526
4
+ data.tar.gz: 9befdd7dd6f98195391fe323f5fabf0d74a6bb9bb0d717f7cf74c30219f91462
5
5
  SHA512:
6
- metadata.gz: f31780c4436d533a80fd1b73c4470a09276330ef6a07b8e453807a4b12c4595c05c0dce82ef85d400d4615e9d384b6df25f4f84442007e40d187212e52b33618
7
- data.tar.gz: 4de7b1452cea8ef0df3d9f6d3c4c71de7476c6cf2cedb43bdbdff8e4d5f5732890b3251938ab9a811f74e64d4b24c4d325b32a4d5511b072fe152b1b836e98ca
6
+ metadata.gz: 0c5df44798b60ae20ad1d8bb395cce56d92e89ddde8912d0a747fcf7e695c74ea3f9a58fa71b7d570a956d908ef3261bfc776c8feb23b21a7f61c595bc3a0855
7
+ data.tar.gz: d8d2ddcc09c7127ff75b8897bbef5a4ad98f057c80e836bcf8849833c0580914bfd1fd3a435cce34ef4124458dcf0fb12b3dcdb1d78b6932bd629f0ddb90a2f5
data/.circleci/config.yml CHANGED
@@ -6,7 +6,22 @@ jobs:
6
6
  environment:
7
7
  DATABASE_URL: postgresql://postgres:secret@localhost:5432/ruby-pg-extras-test
8
8
  - image: circleci/postgres:11.5
9
- command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
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: circleci/postgres:12.7
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: circleci/postgres:13.3
23
+ command: postgres -c shared_preload_libraries=pg_stat_statements
24
+ name: postgres13
10
25
  environment:
11
26
  POSTGRES_USER: postgres
12
27
  POSTGRES_DB: ruby-pg-extras-test
@@ -17,13 +32,24 @@ jobs:
17
32
  - run: gem update --system
18
33
  - run: gem install bundler
19
34
  - run: bundle install --path vendor/bundle
20
- - run: sudo apt-get update
35
+ - run: sudo apt-get update --allow-releaseinfo-change
21
36
  - run: sudo apt install postgresql-client-11
22
- - run: dockerize -wait tcp://localhost:5432 -timeout 1m
37
+ - run: dockerize -wait tcp://postgres11:5432 -timeout 1m
38
+ - run:
39
+ name: Run specs for PG 11
40
+ environment:
41
+ DATABASE_URL: postgresql://postgres:secret@postgres11:5432/ruby-pg-extras-test
42
+ command: bundle exec rspec spec/
43
+ - run:
44
+ name: Run specs for PG 12
45
+ environment:
46
+ DATABASE_URL: postgresql://postgres:secret@postgres12:5432/ruby-pg-extras-test
47
+ command: bundle exec rspec spec/
23
48
  - run:
24
- name: Run specs
25
- command: |
26
- bundle exec rspec spec/
49
+ name: Run specs for PG 13
50
+ environment:
51
+ DATABASE_URL: postgresql://postgres:secret@postgres13:5432/ruby-pg-extras-test
52
+ command: bundle exec rspec spec/
27
53
  workflows:
28
54
  version: 2
29
55
  test:
data/README.md CHANGED
@@ -387,6 +387,19 @@ This command displays indexes that have < 50 scans recorded against them, and ar
387
387
 
388
388
  [More info](https://pawelurbanek.com/postgresql-fix-performance#unused-indexes)
389
389
 
390
+ ### `duplicate_indexes`
391
+
392
+ ```ruby
393
+
394
+ RubyPGExtras.duplicate_indexes
395
+
396
+ | size | idx1 | idx2 | idx3 | idx4 |
397
+ +------------+--------------+----------------+----------+-----------+
398
+ | 128 k | users_pkey | index_users_id | | |
399
+ ```
400
+
401
+ This command displays multiple indexes that have the same set of columns, same opclass, expression and predicate - which make them equivalent. Usually it's safe to drop one of them.
402
+
390
403
  ### `null_indexes`
391
404
 
392
405
  ```ruby
@@ -550,8 +563,17 @@ RubyPGExtras.mandelbrot
550
563
 
551
564
  This command outputs the Mandelbrot set, calculated through SQL.
552
565
 
566
+ ## Testing
567
+
568
+ ```bash
569
+ cp docker-compose.yml.sample docker-compose.yml
570
+ docker compose up -d
571
+ rake test_all
572
+ ```
573
+
553
574
  ## Query sources
554
575
 
555
576
  - [https://github.com/heroku/heroku-pg-extras](https://github.com/heroku/heroku-pg-extras)
556
577
  - [https://hakibenita.com/postgresql-unused-index-size](https://hakibenita.com/postgresql-unused-index-size)
557
578
  - [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)
579
+ - [https://wiki.postgresql.org/wiki/Index_Maintenance](https://wiki.postgresql.org/wiki/Index_Maintenance)
data/Rakefile CHANGED
@@ -3,3 +3,7 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
+ desc 'Test all PG versions'
7
+ task :test_all do
8
+ system("PG_VERSION=11 bundle exec rspec spec/ && PG_VERSION=12 bundle exec rspec spec/ && PG_VERSION=13 bundle exec rspec spec/")
9
+ end
@@ -3,7 +3,7 @@ version: '3'
3
3
  services:
4
4
  postgres11:
5
5
  image: postgres:11.5-alpine
6
- command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
6
+ command: postgres -c shared_preload_libraries=pg_stat_statements
7
7
  environment:
8
8
  POSTGRES_USER: postgres
9
9
  POSTGRES_DB: ruby-pg-extras-test
@@ -12,7 +12,7 @@ services:
12
12
  - '5432:5432'
13
13
  postgres12:
14
14
  image: postgres:12.7-alpine
15
- command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
15
+ command: postgres -c shared_preload_libraries=pg_stat_statements
16
16
  environment:
17
17
  POSTGRES_USER: postgres
18
18
  POSTGRES_DB: ruby-pg-extras-test
@@ -21,7 +21,7 @@ services:
21
21
  - '5433:5432'
22
22
  postgres13:
23
23
  image: postgres:13.3-alpine
24
- command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c max_connections=200
24
+ command: postgres -c shared_preload_libraries=pg_stat_statements
25
25
  environment:
26
26
  POSTGRES_USER: postgres
27
27
  POSTGRES_DB: ruby-pg-extras-test
@@ -0,0 +1,11 @@
1
+ /* Multiple indexes that have the same set of columns, same opclass, expression and predicate -- which make them equivalent. */
2
+
3
+ SELECT pg_size_pretty(sum(pg_relation_size(idx))::bigint) as size,
4
+ (array_agg(idx))[1] as idx1, (array_agg(idx))[2] as idx2,
5
+ (array_agg(idx))[3] as idx3, (array_agg(idx))[4] as idx4
6
+ FROM (
7
+ SELECT indexrelid::regclass as idx, (indrelid::text ||E'\n'|| indclass::text ||E'\n'|| indkey::text ||E'\n'||
8
+ coalesce(indexprs::text,'')||E'\n' || coalesce(indpred::text,'')) as key
9
+ FROM pg_index) sub
10
+ GROUP BY key HAVING count(*)>1
11
+ ORDER BY sum(pg_relation_size(idx)) DESC;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPGExtras
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -15,7 +15,7 @@ module RubyPGExtras
15
15
  long_running_queries mandelbrot outliers
16
16
  records_rank seq_scans table_indexes_size
17
17
  table_size total_index_size total_table_size
18
- unused_indexes vacuum_stats kill_all
18
+ unused_indexes duplicate_indexes vacuum_stats kill_all
19
19
  buffercache_stats buffercache_usage
20
20
  )
21
21
 
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: 2.0.0
4
+ version: 2.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-07-08 00:00:00.000000000 Z
11
+ date: 2021-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -92,6 +92,7 @@ files:
92
92
  - lib/ruby-pg-extras/queries/calls.sql
93
93
  - lib/ruby-pg-extras/queries/calls_legacy.sql
94
94
  - lib/ruby-pg-extras/queries/db_settings.sql
95
+ - lib/ruby-pg-extras/queries/duplicate_indexes.sql
95
96
  - lib/ruby-pg-extras/queries/extensions.sql
96
97
  - lib/ruby-pg-extras/queries/index_cache_hit.sql
97
98
  - lib/ruby-pg-extras/queries/index_size.sql