ruby-pg-extras 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +32 -6
- data/README.md +22 -0
- data/Rakefile +4 -0
- data/docker-compose.yml.sample +3 -3
- data/lib/ruby-pg-extras/queries/duplicate_indexes.sql +11 -0
- data/lib/ruby-pg-extras/version.rb +1 -1
- data/lib/ruby-pg-extras.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a88ff7e79fc4b77781012f9ee52afeee2462dcc46177d6bec8d24885c9822526
|
4
|
+
data.tar.gz: 9befdd7dd6f98195391fe323f5fabf0d74a6bb9bb0d717f7cf74c30219f91462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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://
|
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
|
-
|
26
|
-
|
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
data/docker-compose.yml.sample
CHANGED
@@ -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
|
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
|
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
|
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;
|
data/lib/ruby-pg-extras.rb
CHANGED
@@ -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.
|
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-
|
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
|