Skip to content

Add a unused_indexes service#420

Merged
gleu merged 1 commit into
masterfrom
issue32
May 11, 2026
Merged

Add a unused_indexes service#420
gleu merged 1 commit into
masterfrom
issue32

Conversation

@gleu
Copy link
Copy Markdown
Collaborator

@gleu gleu commented May 4, 2026

Basic fix for #32

@gleu gleu added this to the 2.10 milestone May 4, 2026
@gleu gleu self-assigned this May 4, 2026
@gleu gleu linked an issue May 4, 2026 that may be closed by this pull request
@frost242
Copy link
Copy Markdown
Member

frost242 commented May 4, 2026

Hello,

Thanks for taking some time to fix and add new things on check_pgactivity. Regarding this service, I don't agree that it's a feature that we want. Checking for unused indexes is challenging and can lead to "false positives" : think about an index mandatory in a monthly or yearly batch. Think on an index backing an unique constrainte (PK or not).

A simple test leads to a false positive :

[postgres]# create table t1 (i integer primary key);
CREATE TABLE
[postgres]# insert into t1 values (1);
INSERT 0 1
[postgres]# insert into t1 values (2);
INSERT 0 1
[postgres]# insert into t1 values (3);
INSERT 0 1

The query embedded in the script will make this service bail out about the index supporting the PK.

@Krysztophe
Copy link
Copy Markdown
Collaborator

I agree that all indexes for PKs and UNIQUE keys should be excluded.

As for indexes on FKs, this is more difficult. They should be present by default there until proven useless, this service could help to detect them.

You need a big warning that an index may be useful once a year, but this service could be useful if not used blindly.

@gleu
Copy link
Copy Markdown
Collaborator Author

gleu commented May 4, 2026

I added support for checking primary key and unique constraints indexes.

It may bring false positive, but many other services do too. I still think it's worth it.

@gleu gleu merged commit 0e88277 into master May 11, 2026
17 of 18 checks passed
@gleu gleu deleted the issue32 branch May 11, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check for unused indexes

3 participants