diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 167c30e0..07d69c1d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: build: strategy: matrix: - pg_version: [ "12.17", "13.13", "14.10", "15.5", "16.1" ] + pg_version: [ "12.18", "13.14", "14.11", "15.6", "16.2" ] env: TEST_PG_VERSION: ${{ matrix.pg_version }} runs-on: ubuntu-latest @@ -42,16 +42,16 @@ jobs: restore-keys: | ${{ runner.os }}-gradle- - name: Build with Gradle and analyze - if: matrix.pg_version == '14.10' + if: matrix.pg_version == '14.11' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: ./gradlew build sonarqube --info - name: Build with Gradle - if: matrix.pg_version != '14.10' + if: matrix.pg_version != '14.11' run: ./gradlew build - name: Upload coverage to Codecov - if: matrix.pg_version == '14.10' + if: matrix.pg_version == '14.11' uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88cb8311..d2199630 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ Java >= 11 is required. This will build the project and run tests. -By default, [PostgreSQL 16.1 from Testcontainers](https://www.testcontainers.org/) is used to run tests. +By default, [PostgreSQL 16.2 from Testcontainers](https://www.testcontainers.org/) is used to run tests. Set `TEST_PG_VERSION` environment variable to use any of other available PostgreSQL version: ``` TEST_PG_VERSION=11.20-alpine @@ -38,7 +38,7 @@ Domain model is located in a [pg-index-health-model](https://github.com/mfvanek/ All domain classes should be minimalistic and well-defined. They should include enough information to generate corrective SQL migrations via [pg-index-health-generator](https://github.com/mfvanek/pg-index-health/tree/master/pg-index-health-generator). -### Add the code for a new check +### Add the code for the new check All checks can be divided into 2 parts: 1. Runtime checks (those that make sense to run only on a production database) @@ -63,3 +63,11 @@ Implement a new class extending [AbstractCheckOnCluster](https://github.com/mfva * Your code must be 100% covered. * Mutation tests via [pitest](https://pitest.org/) should work. + +### Further steps + +1. Update readme and add information about the new check +2. Update [Spring Boot starter](https://github.com/mfvanek/pg-index-health-test-starter). + Use a locally built pg-index-health version and send a draft PR. +3. Add sample code to the demo apps ([first](https://github.com/mfvanek/pg-index-health-demo), [second](https://github.com/mfvanek/pg-index-health-spring-boot-demo)). + Use a locally built pg-index-health version and send a draft PR. diff --git a/README.md b/README.md index 56ac0363..2c3411ee 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,6 @@ [![javadoc](https://javadoc.io/badge2/io.github.mfvanek/pg-index-health/javadoc.svg)](https://javadoc.io/doc/io.github.mfvanek/pg-index-health "javadoc") [![codecov](https://codecov.io/gh/mfvanek/pg-index-health/branch/master/graph/badge.svg)](https://codecov.io/gh/mfvanek/pg-index-health) -[![Total lines](https://tokei.rs/b1/github/mfvanek/pg-index-health)](https://github.com/mfvanek/pg-index-health) -[![Files](https://tokei.rs/b1/github/mfvanek/pg-index-health?category=files)](https://github.com/mfvanek/pg-index-health) - [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=bugs)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health) @@ -17,6 +14,7 @@ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mfvanek_pg-index-health&metric=coverage)](https://sonarcloud.io/summary/new_code?id=mfvanek_pg-index-health) ## Supported PostgreSQL versions + [![PostgreSQL 12](https://img.shields.io/badge/PostgreSQL-12-green.svg)](https://www.postgresql.org/about/news/1976/ "PostgreSQL 12") [![PostgreSQL 13](https://img.shields.io/badge/PostgreSQL-13-green.svg)](https://www.postgresql.org/about/news/postgresql-13-released-2077/ "PostgreSQL 13") [![PostgreSQL 14](https://img.shields.io/badge/PostgreSQL-14-green.svg)](https://www.postgresql.org/about/news/postgresql-14-released-2318/ "PostgreSQL 14") @@ -24,15 +22,18 @@ [![PostgreSQL 16](https://img.shields.io/badge/PostgreSQL-16-green.svg)](https://www.postgresql.org/about/news/postgresql-16-released-2715/ "PostgreSQL 16") ### Support for previous versions of PostgreSQL + Compatibility with PostgreSQL versions **9.6**, **10** and **11** 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](https://www.postgresql.org/support/versioning/). ### Supported Java versions + Supports [Java 11](https://www.java.com/en/) and above For **Java 8** compatible version take a look at release [0.7.0](https://github.com/mfvanek/pg-index-health/releases/tag/v.0.7.0) and lower ## Available checks + **pg-index-health** allows you to detect the following problems: 1. Invalid (broken) indexes ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/invalid_indexes.sql)). 2. Duplicated (completely identical) indexes ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/duplicated_indexes.sql)). @@ -49,16 +50,19 @@ For **Java 8** compatible version take a look at release [0.7.0](https://github. 13. Columns with [json](https://www.postgresql.org/docs/current/datatype-json.html) type ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/columns_with_json_type.sql)). 14. Columns of [serial types](https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL) that are not primary keys ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/non_primary_key_columns_with_serial_types.sql)). 15. Functions without [description](https://www.postgresql.org/docs/current/sql-comment.html) ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/functions_without_description.sql)). +16. Indexes [with boolean](https://habr.com/ru/companies/tensor/articles/488104/) ([sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/indexes_with_boolean.sql)) For raw sql queries see [pg-index-health-sql](https://github.com/mfvanek/pg-index-health-sql) project. ## How does it work? + **pg_index_health** utilizes [the Cumulative Statistics System](https://www.postgresql.org/docs/current/monitoring-stats.html) (formerly known as [PostgreSQL's statistics collector](https://www.postgresql.org/docs/14/monitoring-stats.html)). 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 [DatabaseManagement::resetStatistics()](https://github.com/mfvanek/pg-index-health/blob/1b999374ebc4850ac60e70712399336175348f81/src/main/java/io/github/mfvanek/pg/common/management/DatabaseManagement.java#L32) method. ## Installation + Using Gradle: ```groovy implementation 'io.github.mfvanek:pg-index-health:0.10.3' @@ -82,9 +86,11 @@ Using Maven: ``` ## Articles and publications + * [Index health in PostgreSQL through the eyes of a Java developer](https://habr.com/ru/post/490824/) ## 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; @@ -93,19 +99,14 @@ There are three main scenarios of using **pg-index-health** in your projects: All these cases are covered with examples in the [pg-index-health-demo](https://github.com/mfvanek/pg-index-health-demo) project. ## Integration with Spring Boot + There is a Spring Boot starter [pg-index-health-test-starter](https://github.com/mfvanek/pg-index-health-test-starter) for unit/integration testing as well. More examples you can find in [pg-index-health-spring-boot-demo](https://github.com/mfvanek/pg-index-health-spring-boot-demo) project. ## Questions, issues, feature requests and contributions + * If you have any question or a problem with the library, please [file an issue](https://github.com/mfvanek/pg-index-health/issues). * Contributions are always welcome! Please see [contributing guide](CONTRIBUTING.md) for more details. * We utilize [Testcontainers](https://www.testcontainers.org/) for testing **pg-index-health**. So you need to have [Docker](https://www.docker.com/) installed on your machine. - -## Related projects -[pg_analyse](https://github.com/idlesign/pg_analyse) - a set of tools to gather useful information from PostgreSQL, -written in Python, with command line interface. - -## Acknowledgements -Supported by [JetBrains](https://www.jetbrains.com/) with [Licenses for Open Source Development](https://www.jetbrains.com/community/opensource/#support) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 693f667c..320e22e1 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.9" services: postgres: - image: postgres:16.1 + image: postgres:16.2 environment: POSTGRES_DB: "pgih-db" POSTGRES_USER: "pgih-db-user" diff --git a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapper.java b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapper.java index 2be3dfb7..e9860714 100644 --- a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapper.java +++ b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapper.java @@ -128,7 +128,7 @@ public boolean isOutParametersInProcedureSupported() { /** * Creates {@code PostgreSqlContainerWrapper} with default PostgreSQL version. * The default version is taken from the environment variable {@code TEST_PG_VERSION} if it is set, - * otherwise the default version {@code 16.1} is used. + * otherwise the default version {@code 16.2} is used. * * @return {@code PostgreSqlContainerWrapper} */ diff --git a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java index ab8cecbc..620b3416 100644 --- a/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java +++ b/pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgresVersionHolder.java @@ -76,7 +76,7 @@ private static String preparePostgresVersion() { if (pgVersion != null) { return pgVersion; } - return "16.1"; + return "16.2"; } @Nonnull @@ -114,7 +114,7 @@ static PostgresVersionHolder forCluster(@Nonnull final String pgVersion) { /** * Creates {@code PostgresVersionHolder} for single node installation. * The version is taken from the environment variable {@code TEST_PG_VERSION} if it is set, - * otherwise the default version {@code 16.1} is used. + * otherwise the default version {@code 16.2} is used. * * @return {@code PostgresVersionHolder} */ diff --git a/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapperTest.java b/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapperTest.java index 80310484..acf1fb5f 100644 --- a/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapperTest.java +++ b/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgreSqlContainerWrapperTest.java @@ -41,7 +41,7 @@ void withDefaultVersionShouldWork() { @Test void withVersionShouldWork() { - try (PostgreSqlContainerWrapper container = PostgreSqlContainerWrapper.withVersion("16.1")) { + try (PostgreSqlContainerWrapper container = PostgreSqlContainerWrapper.withVersion("16.2")) { assertThat(container) .isNotNull() .satisfies(c -> { diff --git a/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgresVersionHolderTest.java b/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgresVersionHolderTest.java index 73744edc..88791e28 100644 --- a/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgresVersionHolderTest.java +++ b/pg-index-health-testing/src/test/java/io/github/mfvanek/pg/testing/PostgresVersionHolderTest.java @@ -80,7 +80,7 @@ void forClusterShouldBeBitnamiAware() { .isEqualTo(System.getenv("TEST_PG_VERSION").split("-")[0] + ".0"); } else { assertThat(versionHolder.getVersion()) - .isEqualTo("16.1.0"); + .isEqualTo("16.2.0"); } } @@ -110,7 +110,7 @@ void forSingleNodeShouldBeEnvAware() { .isEqualTo(System.getenv("TEST_PG_VERSION")); } else { assertThat(versionHolder.getVersion()) - .isEqualTo("16.1"); + .isEqualTo("16.2"); } } diff --git a/pg-index-health/src/test/java/io/github/mfvanek/pg/utils/PostgresVersionTest.java b/pg-index-health/src/test/java/io/github/mfvanek/pg/utils/PostgresVersionTest.java index 2c9b8669..0bb5ff59 100644 --- a/pg-index-health/src/test/java/io/github/mfvanek/pg/utils/PostgresVersionTest.java +++ b/pg-index-health/src/test/java/io/github/mfvanek/pg/utils/PostgresVersionTest.java @@ -25,7 +25,7 @@ final class PostgresVersionTest extends DatabaseAwareTestBase { @Test void checkPgVersion() { final String pgVersionFromEnv = System.getenv(PG_VERSION_ENVIRONMENT_VARIABLE); - final String requiredPgVersionString = (pgVersionFromEnv == null) ? "16.1 (Debian 16.1-" : pgVersionFromEnv.split("-")[0]; + final String requiredPgVersionString = (pgVersionFromEnv == null) ? "16.2 (Debian 16.2-" : pgVersionFromEnv.split("-")[0]; final String actualPgVersionString = PostgresVersionReader.readVersion(getDataSource()); assertThat(actualPgVersionString) .startsWith(requiredPgVersionString);