Skip to content

pg-index-health is an embeddable schema linter for PostgreSQL that detects common anti-patterns and promotes best practices.

License

Notifications You must be signed in to change notification settings

mfvanek/pg-index-health

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

pg-index-health

pg-index-health is an embeddable schema linter for PostgreSQL that detects common anti-patterns and promotes best practices.

Java CI Maven Central License: Apache 2.0 javadoc codecov

Bugs Vulnerabilities Code Smells Lines of Code Coverage

Mutation testing badge

What is this?

pg-index-health is a Java library designed to analyze PostgreSQL database schemas and help developers build efficient, reliable applications.

It scans database structures to identify common schema-level pitfalls that often go unnoticed until they cause problems in production.

By embedding pg-index-health into your CI/CD pipeline, you can proactively catch schema design flaws, enforce consistency, and adhere to PostgreSQL best practices before they impact performance or reliability.

Available checks

A list of all available checks (rules/diagnostics) can be found here.
In code, you can get all checks through an instance of the StandardChecksOnHost or StandardChecksOnCluster class.

User-defined (custom) checks

You can add your own database structure checks as shown in the link.

Installation

Using Gradle:

implementation("io.github.mfvanek:pg-index-health:0.30.0")

Using Maven:

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

How to use

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

  • unit\functional testing (see standard test in a section below) locally and in CI for compliance of the database structure with best practices;
  • collecting indexes, tables and sequences health data and bloat monitoring in runtime on production.

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.
More examples you can find in the pg-index-health-demo project.

Starter installation

Using Gradle:

testImplementation("io.github.mfvanek:pg-index-health-test-starter:0.30.0")

Using Maven:

<dependency>
    <groupId>io.github.mfvanek</groupId>
    <artifactId>pg-index-health-test-starter</artifactId>
    <version>0.30.0</version>
    <scope>test</scope>
</dependency>

Standard test

Add a standard test to your project as shown in the link. Ideally, all checks should pass and return an empty result.

Spring Boot compatibility

Spring Boot Min JDK pg-index-health-test-starter
2.7.x 11 0.8.x — 0.15.x
3.3.x 17 0.20.x
3.4.x 17 0.30.x

Spring Boot 3 compatibility

Supported PostgreSQL versions

PostgreSQL 13 PostgreSQL 14 PostgreSQL 15 PostgreSQL 16 PostgreSQL 17 PostgreSQL 18

Support for previous versions of PostgreSQL

Compatibility with previous PostgreSQL versions is no longer guaranteed, but it is very likely.
We focus only on the currently maintained versions of PostgreSQL.
For more information please see PostgreSQL Versioning Policy.

Supported Java versions

Supports Java 17 and above.

  • For Java 11 compatible version take a look at release 0.15.0 and lower.

Articles and publications

In English

In Russian

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.

Similar solutions

About

pg-index-health is an embeddable schema linter for PostgreSQL that detects common anti-patterns and promotes best practices.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors 11