/pg-index-health

pg-index-health is a Java library for analyzing and maintaining indexes health in Postgresql databases.

Primary LanguageJavaApache License 2.0Apache-2.0

pg-index-health

pg-index-health is a Java library for analyzing and maintaining indexes health in PostgreSQL databases.

Java CI Maven Central License: Apache 2.0 javadoc codecov

Supported PostgreSQL versions

PostgreSQL 9.6 PostgreSQL 10 PostgreSQL 11 PostgreSQL 12 PostgreSQL 13 PostgreSQL 14

Supported Java versions

Java 8 and above

Available checks

pg-index-health allows you to detect the following problems:

  1. Invalid (broken) indexes (sql).
  2. Duplicated (completely identical) indexes (sql).
  3. Intersected (partially identical) indexes (sql).
  4. Unused indexes (sql).
  5. Foreign keys without associated indexes (sql).
  6. Indexes with null values (sql).
  7. Tables with missing indexes (sql).
  8. Tables without primary key (sql).
  9. Indexes bloat (sql).
  10. Tables bloat (sql).

For raw sql queries see pg-index-health-sql project.

How does it work?

pg_index_health utilizes the PostgreSQL's statistics collector.
You can call pg_stat_reset() on each host to reset all statistics counters for the current database to zero but the best way to do it is to use IndexesHealth::resetStatistics() method.

Installation

Using Gradle:

implementation 'io.github.mfvanek:pg-index-health:0.4.0'

Using Maven:

<dependency>
  <groupId>io.github.mfvanek</groupId>
  <artifactId>pg-index-health</artifactId>
  <version>0.4.0</version>
</dependency>

How to use

There are three main scenarios of using pg-index-health in your projects:

  • unit\functional testing;
  • collecting indexes health data and monitoring bloat;
  • analysis of database configuration.

All these cases are covered with examples in the pg-index-health-demo project.

Integration with Spring Boot

There is a Spring Boot starter pg-index-health-test-starter for unit/integration testing as well.

Questions, issues, feature requests and contributions

  • If you have any question or a problem with the library, please file an issue.
  • Contributions are always welcome! Please see contributing guide for more details.
  • We utilize Testcontainers for testing pg-index-health. So you need to have Docker installed on your machine.

Related projects

pg_analyse - a set of tools to gather useful information from PostgreSQL, written in Python, with command line interface.

Acknowledgements

Supported by JetBrains with Licenses for Open Source Development