├── .editorconfig ├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ └── tests.yml ├── .gitignore ├── .gitmodules ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── pg-index-health.forbidden-apis.gradle.kts │ ├── pg-index-health.java-application.gradle.kts │ ├── pg-index-health.java-compilation.gradle.kts │ ├── pg-index-health.java-conventions.gradle.kts │ ├── pg-index-health.java-library.gradle.kts │ ├── pg-index-health.kotlin-application.gradle.kts │ ├── pg-index-health.pitest.gradle.kts │ └── pg-index-health.publish.gradle.kts ├── config ├── checkstyle │ └── checkstyle.xml ├── detekt │ └── detekt.yml ├── forbidden-apis │ └── forbidden-apis.txt ├── pmd │ └── pmd.xml └── spotbugs │ └── exclude.xml ├── doc └── rus │ ├── bloated_indexes.md │ ├── bloated_tables.md │ ├── btree_indexes_on_array_columns.md │ ├── columns_not_following_naming_convention.md │ ├── columns_with_fixed_length_varchar.md │ ├── columns_with_json_type.md │ ├── columns_with_serial_types.md │ ├── columns_without_description.md │ ├── duplicated_foreign_keys.md │ ├── duplicated_indexes.md │ ├── foreign_keys_with_unmatched_column_type.md │ ├── foreign_keys_without_index.md │ ├── functions_without_description.md │ ├── indexes_with_boolean.md │ ├── indexes_with_null_values.md │ ├── indexes_with_unnecessary_where_clause.md │ ├── intersected_foreign_keys.md │ ├── intersected_indexes.md │ ├── invalid_indexes.md │ ├── not_valid_constraints.md │ ├── objects_not_following_naming_convention.md │ ├── possible_object_name_overflow.md │ ├── primary_keys_that_most_likely_natural_keys.md │ ├── primary_keys_with_serial_types.md │ ├── primary_keys_with_varchar.md │ ├── sequence_overflow.md │ ├── tables_not_linked_to_others.md │ ├── tables_with_missing_indexes.md │ ├── tables_with_zero_or_one_column.md │ ├── tables_without_description.md │ ├── tables_without_primary_key.md │ └── unused_indexes.md ├── docker ├── docker-compose.yml └── local_development.md ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── logo.png ├── pg-index-health-bom └── build.gradle.kts ├── pg-index-health-core ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── core │ │ ├── checks │ │ ├── common │ │ │ ├── CheckTypeAware.java │ │ │ ├── DatabaseCheckOnHost.java │ │ │ ├── Diagnostic.java │ │ │ ├── DiagnosticAware.java │ │ │ ├── QueryExecutor.java │ │ │ ├── RawTypeAware.java │ │ │ ├── ResultSetExtractor.java │ │ │ └── package-info.java │ │ ├── extractors │ │ │ ├── AnyObjectExtractor.java │ │ │ ├── ColumnExtractor.java │ │ │ ├── ColumnWithSerialTypeExtractor.java │ │ │ ├── DuplicatedForeignKeysExtractor.java │ │ │ ├── ForeignKeyExtractor.java │ │ │ ├── IndexWithColumnsExtractor.java │ │ │ ├── IndexWithSingleColumnExtractor.java │ │ │ ├── TableExtractor.java │ │ │ ├── TableWithColumnsExtractor.java │ │ │ └── package-info.java │ │ └── host │ │ │ ├── AbstractCheckOnHost.java │ │ │ ├── BtreeIndexesOnArrayColumnsCheckOnHost.java │ │ │ ├── ColumnsNotFollowingNamingConventionCheckOnHost.java │ │ │ ├── ColumnsWithFixedLengthVarcharCheckOnHost.java │ │ │ ├── ColumnsWithJsonTypeCheckOnHost.java │ │ │ ├── ColumnsWithSerialTypesCheckOnHost.java │ │ │ ├── ColumnsWithoutDescriptionCheckOnHost.java │ │ │ ├── DuplicatedForeignKeysCheckOnHost.java │ │ │ ├── DuplicatedIndexesCheckOnHost.java │ │ │ ├── ForeignKeysNotCoveredWithIndexCheckOnHost.java │ │ │ ├── ForeignKeysWithUnmatchedColumnTypeCheckOnHost.java │ │ │ ├── FunctionsWithoutDescriptionCheckOnHost.java │ │ │ ├── IndexesWithBloatCheckOnHost.java │ │ │ ├── IndexesWithBooleanCheckOnHost.java │ │ │ ├── IndexesWithNullValuesCheckOnHost.java │ │ │ ├── IndexesWithUnnecessaryWhereClauseCheckOnHost.java │ │ │ ├── IntersectedForeignKeysCheckOnHost.java │ │ │ ├── IntersectedIndexesCheckOnHost.java │ │ │ ├── InvalidIndexesCheckOnHost.java │ │ │ ├── NotValidConstraintsCheckOnHost.java │ │ │ ├── ObjectsNotFollowingNamingConventionCheckOnHost.java │ │ │ ├── PossibleObjectNameOverflowCheckOnHost.java │ │ │ ├── PrimaryKeysThatMostLikelyNaturalKeysCheckOnHost.java │ │ │ ├── PrimaryKeysWithSerialTypesCheckOnHost.java │ │ │ ├── PrimaryKeysWithVarcharCheckOnHost.java │ │ │ ├── SequenceOverflowCheckOnHost.java │ │ │ ├── TablesNotLinkedToOthersCheckOnHost.java │ │ │ ├── TablesWithBloatCheckOnHost.java │ │ │ ├── TablesWithMissingIndexesCheckOnHost.java │ │ │ ├── TablesWithZeroOrOneColumnCheckOnHost.java │ │ │ ├── TablesWithoutDescriptionCheckOnHost.java │ │ │ ├── TablesWithoutPrimaryKeyCheckOnHost.java │ │ │ ├── UnusedIndexesCheckOnHost.java │ │ │ └── package-info.java │ │ ├── statistics │ │ ├── StatisticsAware.java │ │ ├── StatisticsMaintenanceOnHost.java │ │ ├── StatisticsMaintenanceOnHostImpl.java │ │ ├── StatisticsQueryExecutor.java │ │ └── package-info.java │ │ └── utils │ │ ├── ClockHolder.java │ │ ├── ColumnsDataParser.java │ │ ├── NamedParametersParser.java │ │ ├── QueryExecutors.java │ │ ├── SqlQueryReader.java │ │ ├── exception │ │ ├── ReadQueryFromFileException.java │ │ └── package-info.java │ │ └── package-info.java │ ├── test │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── core │ │ ├── checks │ │ ├── common │ │ │ └── DiagnosticTest.java │ │ ├── extractors │ │ │ ├── ColumnExtractorTest.java │ │ │ ├── ColumnWithSerialTypeExtractorTest.java │ │ │ └── TableExtractorTest.java │ │ └── host │ │ │ ├── AbstractCheckOnHostTest.java │ │ │ ├── BtreeIndexesOnArrayColumnsCheckOnHostTest.java │ │ │ ├── ColumnsNotFollowingNamingConventionCheckOnHostTest.java │ │ │ ├── ColumnsWithFixedLengthVarcharCheckTest.java │ │ │ ├── ColumnsWithJsonTypeCheckOnHostTest.java │ │ │ ├── ColumnsWithSerialTypesCheckOnHostTest.java │ │ │ ├── ColumnsWithoutDescriptionCheckOnHostTest.java │ │ │ ├── DuplicatedForeignKeysCheckOnHostTest.java │ │ │ ├── DuplicatedIndexesCheckOnHostTest.java │ │ │ ├── ForeignKeysNotCoveredWithIndexCheckOnHostTest.java │ │ │ ├── ForeignKeysWithUnmatchedColumnTypeCheckOnHostTest.java │ │ │ ├── FunctionsWithoutDescriptionCheckOnHostTest.java │ │ │ ├── IndexesWithBloatCheckOnHostTest.java │ │ │ ├── IndexesWithBooleanCheckOnHostTest.java │ │ │ ├── IndexesWithNullValuesCheckOnHostTest.java │ │ │ ├── IndexesWithUnnecessaryWhereClauseCheckOnHostTest.java │ │ │ ├── IntersectedForeignKeysCheckOnHostTest.java │ │ │ ├── IntersectedIndexesCheckOnHostTest.java │ │ │ ├── InvalidIndexesCheckOnHostTest.java │ │ │ ├── NotValidConstraintsCheckOnHostTest.java │ │ │ ├── ObjectsNotFollowingNamingConventionCheckOnHostTest.java │ │ │ ├── PossibleObjectNameOverflowCheckOnHostTest.java │ │ │ ├── PrimaryKeysThatMostLikelyNaturalKeysCheckOnHostTest.java │ │ │ ├── PrimaryKeysWithSerialTypesCheckOnHostTest.java │ │ │ ├── PrimaryKeysWithVarcharCheckOnHostTest.java │ │ │ ├── SequenceOverflowCheckOnHostTest.java │ │ │ ├── TablesNotLinkedToOthersCheckOnHostTest.java │ │ │ ├── TablesWithBloatCheckOnHostTest.java │ │ │ ├── TablesWithMissingIndexesCheckOnHostTest.java │ │ │ ├── TablesWithZeroOrOneColumnCheckOnHostTest.java │ │ │ ├── TablesWithoutDescriptionCheckOnHostTest.java │ │ │ ├── TablesWithoutPrimaryKeyCheckOnHostTest.java │ │ │ └── UnusedIndexesCheckOnHostTest.java │ │ ├── statistics │ │ ├── StatisticsMaintenanceOnHostImplTest.java │ │ └── StatisticsMaintenanceOnHostImplUnitTest.java │ │ ├── support │ │ └── AbstractCheckOnHostAssert.java │ │ └── utils │ │ ├── ClockHolderTest.java │ │ ├── ColumnsDataParserTest.java │ │ ├── NamedParametersParserTest.java │ │ ├── PostgresVersionTest.java │ │ ├── QueryExecutorsTest.java │ │ └── SqlQueryReaderTest.java │ └── testFixtures │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── core │ └── fixtures │ └── support │ ├── DatabaseAwareTestBase.java │ ├── DatabaseConfigurer.java │ ├── DatabasePopulator.java │ ├── ExecuteUtils.java │ ├── SchemaNameHolder.java │ ├── StatisticsAwareTestBase.java │ ├── package-info.java │ └── statements │ ├── AbstractDbStatement.java │ ├── AddArrayColumnAndIndexToPartitionedTableStatement.java │ ├── AddBlankCommentOnColumnsStatement.java │ ├── AddBlankCommentOnFunctionsStatement.java │ ├── AddBlankCommentOnTablesStatement.java │ ├── AddCommentOnColumnsStatement.java │ ├── AddCommentOnFunctionsStatement.java │ ├── AddCommentOnProceduresStatement.java │ ├── AddCommentOnTablesStatement.java │ ├── AddDuplicatedForeignKeysStatement.java │ ├── AddDuplicatedForeignKeysToPartitionedTableStatement.java │ ├── AddIntersectedForeignKeysStatement.java │ ├── AddIntersectedForeignKeysToPartitionedTableStatement.java │ ├── AddInvalidForeignKeyStatement.java │ ├── AddLinksBetweenAccountsAndClientsStatement.java │ ├── AddNotValidConstraintToPartitionedTableStatement.java │ ├── AddPrimaryKeyForDefaultPartitionStatement.java │ ├── ConvertColumnToJsonTypeStatement.java │ ├── CreateAccountsTableStatement.java │ ├── CreateBadlyNamedObjectsStatement.java │ ├── CreateBadlyNamedPartitionedTableStatement.java │ ├── CreateClientsTableStatement.java │ ├── CreateCustomCollationStatement.java │ ├── CreateDuplicatedAndIntersectedIndexesInPartitionedTableStatement.java │ ├── CreateDuplicatedCustomCollationIndexStatement.java │ ├── CreateDuplicatedHashIndexStatement.java │ ├── CreateDuplicatedIndexStatement.java │ ├── CreateEmptyTableStatement.java │ ├── CreateForeignKeyOnNullableColumnStatement.java │ ├── CreateFunctionsStatement.java │ ├── CreateIndexWithBooleanValuesStatement.java │ ├── CreateIndexWithNullValuesStatement.java │ ├── CreateIndexWithUnnecessaryWhereClauseStatement.java │ ├── CreateIndexesOnArrayColumnStatement.java │ ├── CreateIndexesWithDifferentOpclassStatement.java │ ├── CreateMaterializedViewStatement.java │ ├── CreateNotSuitableIndexForForeignKeyStatement.java │ ├── CreatePartitionedIndexWithUnnecessaryWhereClauseStatement.java │ ├── CreatePartitionedTableWithDroppedColumnStatement.java │ ├── CreatePartitionedTableWithJsonAndSerialColumnsStatement.java │ ├── CreatePartitionedTableWithNullableFieldsStatement.java │ ├── CreatePartitionedTableWithSerialAndForeignKeysStatement.java │ ├── CreatePartitionedTableWithVarcharStatement.java │ ├── CreatePartitionedTableWithVeryLongNamesStatement.java │ ├── CreatePartitionedTableWithoutCommentsStatement.java │ ├── CreatePartitionedTableWithoutPrimaryKeyStatement.java │ ├── CreateProceduresStatement.java │ ├── CreateSchemaStatement.java │ ├── CreateSequenceStatement.java │ ├── CreateSuitableIndexForForeignKeyStatement.java │ ├── CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement.java │ ├── CreateTableWithColumnOfBigSerialTypeStatement.java │ ├── CreateTableWithFixedLengthVarcharStatement.java │ ├── CreateTableWithIdentityPrimaryKeyStatement.java │ ├── CreateTableWithNaturalKeyStatement.java │ ├── CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement.java │ ├── CreateTableWithUniqueSerialColumnStatement.java │ ├── CreateTableWithoutPrimaryKeyStatement.java │ ├── DbStatement.java │ ├── DropColumnStatement.java │ ├── InsertDataIntoTablesAction.java │ └── package-info.java ├── pg-index-health-generator ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── generator │ │ ├── AbstractDbMigrationGenerator.java │ │ ├── AbstractOptionsAwareSqlGenerator.java │ │ ├── ColumnWithSerialTypeMigrationGenerator.java │ │ ├── DbMigrationGenerator.java │ │ ├── DropDefaultValueGenerator.java │ │ ├── DropSequenceGenerator.java │ │ ├── ForeignKeyMigrationGenerator.java │ │ ├── GeneratingOptions.java │ │ ├── IdxPosition.java │ │ ├── PgIdentifierNameGenerator.java │ │ ├── PgIndexOnForeignKeyGenerator.java │ │ ├── package-info.java │ │ └── utils │ │ ├── NameUtils.java │ │ ├── StringUtils.java │ │ └── package-info.java │ └── test │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── generator │ ├── ColumnWithSerialTypeMigrationGeneratorTest.java │ ├── DropDefaultValueGeneratorTest.java │ ├── DropSequenceGeneratorTest.java │ ├── ForeignKeyMigrationGeneratorTest.java │ ├── GeneratingOptionsTest.java │ ├── PgIdentifierNameGeneratorTest.java │ ├── PgIndexOnForeignKeyGeneratorTest.java │ └── utils │ ├── NameUtilsTest.java │ └── StringUtilsTest.java ├── pg-index-health-jdbc-connection ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── connection │ │ ├── HighAvailabilityPgConnection.java │ │ ├── HighAvailabilityPgConnectionImpl.java │ │ ├── PgConnection.java │ │ ├── PgConnectionImpl.java │ │ ├── PrimaryHostDeterminer.java │ │ ├── PrimaryHostDeterminerImpl.java │ │ ├── exception │ │ ├── PgSqlException.java │ │ └── package-info.java │ │ ├── factory │ │ ├── ConnectionCredentials.java │ │ ├── HighAvailabilityPgConnectionFactory.java │ │ ├── HighAvailabilityPgConnectionFactoryImpl.java │ │ ├── PgConnectionFactory.java │ │ ├── PgConnectionFactoryImpl.java │ │ ├── PgConnectionHelper.java │ │ ├── PgConnectionValidators.java │ │ └── package-info.java │ │ ├── host │ │ ├── HostAware.java │ │ ├── PgHost.java │ │ ├── PgHostImpl.java │ │ ├── PgUrlParser.java │ │ ├── PgUrlValidators.java │ │ └── package-info.java │ │ └── package-info.java │ ├── test │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── connection │ │ ├── HighAvailabilityPgConnectionImplTest.java │ │ ├── HighAvailabilityPgConnectionUnitTest.java │ │ ├── PgConnectionImplTest.java │ │ ├── PrimaryHostDeterminerImplTest.java │ │ ├── factory │ │ ├── ConnectionCredentialsTest.java │ │ ├── HighAvailabilityPgConnectionFactoryImplTest.java │ │ ├── PgConnectionFactoryImplTest.java │ │ ├── PgConnectionHelperTest.java │ │ └── PgConnectionValidatorsTest.java │ │ ├── host │ │ ├── PgHostImplTest.java │ │ ├── PgUrlParserTest.java │ │ └── PgUrlValidatorsTest.java │ │ └── support │ │ └── DatabaseAwareTestBase.java │ └── testFixtures │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── connection │ └── fixtures │ └── support │ ├── LogsCaptor.java │ ├── PostgresVersionReader.java │ └── package-info.java ├── pg-index-health-logger ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── health │ │ └── logger │ │ ├── AbstractHealthLogger.java │ │ ├── DatabaseChecksOnCluster.java │ │ ├── Exclusions.java │ │ ├── HealthLogger.java │ │ ├── LoggingKey.java │ │ ├── SimpleLoggingKeyAdapter.java │ │ ├── StandardHealthLogger.java │ │ └── package-info.java │ └── test │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── health │ └── logger │ ├── DatabaseChecksOnClusterTest.java │ ├── ExclusionsTest.java │ ├── SimpleLoggingKeyAdapterTest.java │ └── StandardHealthLoggerTest.java ├── pg-index-health-model ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── model │ │ ├── bloat │ │ ├── BloatAware.java │ │ └── package-info.java │ │ ├── column │ │ ├── Column.java │ │ ├── ColumnNameAware.java │ │ ├── ColumnWithSerialType.java │ │ ├── ColumnsAware.java │ │ ├── SerialType.java │ │ └── package-info.java │ │ ├── constraint │ │ ├── Constraint.java │ │ ├── ConstraintNameAware.java │ │ ├── ConstraintType.java │ │ ├── ConstraintsAware.java │ │ ├── DuplicatedForeignKeys.java │ │ ├── ForeignKey.java │ │ └── package-info.java │ │ ├── context │ │ ├── PgContext.java │ │ └── package-info.java │ │ ├── dbobject │ │ ├── AnyObject.java │ │ ├── DbObject.java │ │ ├── PgObjectType.java │ │ └── package-info.java │ │ ├── function │ │ ├── StoredFunction.java │ │ └── package-info.java │ │ ├── index │ │ ├── AbstractIndexAware.java │ │ ├── DuplicatedIndexes.java │ │ ├── Index.java │ │ ├── IndexNameAware.java │ │ ├── IndexSizeAware.java │ │ ├── IndexWithBloat.java │ │ ├── IndexWithColumns.java │ │ ├── IndexesAware.java │ │ ├── UnusedIndex.java │ │ ├── package-info.java │ │ └── utils │ │ │ ├── DuplicatedIndexesParser.java │ │ │ └── package-info.java │ │ ├── predicates │ │ ├── AbstractFilterBySize.java │ │ ├── AbstractSkipTablesPredicate.java │ │ ├── SkipBloatUnderThresholdPredicate.java │ │ ├── SkipByColumnNamePredicate.java │ │ ├── SkipByConstraintNamePredicate.java │ │ ├── SkipBySequenceNamePredicate.java │ │ ├── SkipDbObjectsByNamePredicate.java │ │ ├── SkipFlywayTablesPredicate.java │ │ ├── SkipIndexesByNamePredicate.java │ │ ├── SkipLiquibaseTablesPredicate.java │ │ ├── SkipSmallIndexesPredicate.java │ │ ├── SkipSmallTablesPredicate.java │ │ ├── SkipTablesByNamePredicate.java │ │ └── package-info.java │ │ ├── sequence │ │ ├── SequenceNameAware.java │ │ ├── SequenceState.java │ │ └── package-info.java │ │ ├── settings │ │ ├── ImportantParam.java │ │ ├── ParamNameAware.java │ │ ├── package-info.java │ │ └── validation │ │ │ ├── ParamValidators.java │ │ │ └── package-info.java │ │ ├── table │ │ ├── AbstractTableAware.java │ │ ├── Table.java │ │ ├── TableNameAware.java │ │ ├── TableSizeAware.java │ │ ├── TableWithBloat.java │ │ ├── TableWithColumns.java │ │ ├── TableWithMissingIndex.java │ │ └── package-info.java │ │ ├── units │ │ ├── MemoryUnit.java │ │ └── package-info.java │ │ └── validation │ │ ├── Validators.java │ │ └── package-info.java │ ├── test │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── model │ │ ├── column │ │ ├── ColumnTest.java │ │ ├── ColumnWithSerialTypeTest.java │ │ └── SerialTypeTest.java │ │ ├── constraint │ │ ├── ConstraintTest.java │ │ ├── ConstraintTypeTest.java │ │ ├── DuplicatedForeignKeysTest.java │ │ └── ForeignKeyTest.java │ │ ├── context │ │ └── PgContextTest.java │ │ ├── dbobject │ │ ├── AnyObjectTest.java │ │ └── PgObjectTypeTest.java │ │ ├── function │ │ └── StoredFunctionTest.java │ │ ├── index │ │ ├── DuplicatedIndexesTest.java │ │ ├── IndexTest.java │ │ ├── IndexWithBloatTest.java │ │ ├── IndexWithColumnsTest.java │ │ ├── UnusedIndexTest.java │ │ └── utils │ │ │ └── DuplicatedIndexesParserTest.java │ │ ├── predicates │ │ ├── AbstractSkipTablesPredicateTest.java │ │ ├── SkipBloatUnderThresholdPredicateTest.java │ │ ├── SkipByColumnNamePredicateTest.java │ │ ├── SkipByConstraintNamePredicateTest.java │ │ ├── SkipBySequenceNamePredicateTest.java │ │ ├── SkipDbObjectsByNamePredicateTest.java │ │ ├── SkipFlywayTablesPredicateTest.java │ │ ├── SkipIndexesByNamePredicateTest.java │ │ ├── SkipLiquibaseTablesPredicateTest.java │ │ ├── SkipSmallIndexesPredicateTest.java │ │ ├── SkipSmallTablesPredicateTest.java │ │ └── SkipTablesByNamePredicateTest.java │ │ ├── sequence │ │ └── SequenceStateTest.java │ │ ├── settings │ │ ├── ImportantParamTest.java │ │ └── validation │ │ │ └── ParamValidatorsTest.java │ │ ├── table │ │ ├── TableTest.java │ │ ├── TableWithBloatTest.java │ │ ├── TableWithColumnsTest.java │ │ └── TableWithMissingIndexTest.java │ │ ├── units │ │ └── MemoryUnitTest.java │ │ └── validation │ │ └── ValidatorsTest.java │ └── testFixtures │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── model │ └── fixtures │ └── support │ ├── TestUtils.java │ └── package-info.java ├── pg-index-health-testing ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── testing │ │ ├── PostgreSqlClusterAliasHolder.java │ │ ├── PostgreSqlClusterWrapper.java │ │ ├── PostgreSqlContainerWrapper.java │ │ ├── PostgreSqlDataSourceHelper.java │ │ ├── PostgresBitnamiRepmgrContainer.java │ │ ├── PostgresVersionAware.java │ │ ├── PostgresVersionHolder.java │ │ ├── annotations │ │ ├── ExcludeFromJacocoGeneratedReport.java │ │ └── package-info.java │ │ └── package-info.java │ └── test │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── testing │ ├── PostgreSqlClusterAliasHolderTest.java │ ├── PostgreSqlClusterWrapperTest.java │ ├── PostgreSqlContainerWrapperTest.java │ ├── PostgreSqlDataSourceHelperTest.java │ ├── PostgresBitnamiRepmgrContainerTest.java │ └── PostgresVersionHolderTest.java ├── pg-index-health ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── health │ │ ├── checks │ │ ├── cluster │ │ │ ├── AbstractCheckOnCluster.java │ │ │ ├── BtreeIndexesOnArrayColumnsCheckOnCluster.java │ │ │ ├── ColumnsNotFollowingNamingConventionCheckOnCluster.java │ │ │ ├── ColumnsWithFixedLengthVarcharCheckOnCluster.java │ │ │ ├── ColumnsWithJsonTypeCheckOnCluster.java │ │ │ ├── ColumnsWithSerialTypesCheckOnCluster.java │ │ │ ├── ColumnsWithoutDescriptionCheckOnCluster.java │ │ │ ├── DuplicatedForeignKeysCheckOnCluster.java │ │ │ ├── DuplicatedIndexesCheckOnCluster.java │ │ │ ├── ForeignKeysNotCoveredWithIndexCheckOnCluster.java │ │ │ ├── ForeignKeysWithUnmatchedColumnTypeCheckOnCluster.java │ │ │ ├── FunctionsWithoutDescriptionCheckOnCluster.java │ │ │ ├── IndexesWithBloatCheckOnCluster.java │ │ │ ├── IndexesWithBooleanCheckOnCluster.java │ │ │ ├── IndexesWithNullValuesCheckOnCluster.java │ │ │ ├── IndexesWithUnnecessaryWhereClauseCheckOnCluster.java │ │ │ ├── IntersectedForeignKeysCheckOnCluster.java │ │ │ ├── IntersectedIndexesCheckOnCluster.java │ │ │ ├── InvalidIndexesCheckOnCluster.java │ │ │ ├── NotValidConstraintsCheckOnCluster.java │ │ │ ├── ObjectsNotFollowingNamingConventionCheckOnCluster.java │ │ │ ├── PossibleObjectNameOverflowCheckOnCluster.java │ │ │ ├── PrimaryKeysThatMostLikelyNaturalKeysCheckOnCluster.java │ │ │ ├── PrimaryKeysWithSerialTypesCheckOnCluster.java │ │ │ ├── PrimaryKeysWithVarcharCheckOnCluster.java │ │ │ ├── SequenceOverflowCheckOnCluster.java │ │ │ ├── TablesNotLinkedToOthersCheckOnCluster.java │ │ │ ├── TablesWithBloatCheckOnCluster.java │ │ │ ├── TablesWithMissingIndexesCheckOnCluster.java │ │ │ ├── TablesWithZeroOrOneColumnCheckOnCluster.java │ │ │ ├── TablesWithoutDescriptionCheckOnCluster.java │ │ │ ├── TablesWithoutPrimaryKeyCheckOnCluster.java │ │ │ ├── UnusedIndexesCheckOnCluster.java │ │ │ └── package-info.java │ │ ├── common │ │ │ ├── DatabaseCheckOnCluster.java │ │ │ └── package-info.java │ │ └── management │ │ │ ├── DatabaseManagement.java │ │ │ ├── DatabaseManagementImpl.java │ │ │ └── package-info.java │ │ └── utils │ │ ├── CollectionUtils.java │ │ └── package-info.java │ └── test │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── health │ ├── checks │ ├── cluster │ │ ├── AbstractCheckOnClusterTest.java │ │ ├── BtreeIndexesOnArrayColumnsCheckOnClusterTest.java │ │ ├── ColumnsNotFollowingNamingConventionCheckOnClusterTest.java │ │ ├── ColumnsWithFixedLengthVarcharCheckOnClusterTest.java │ │ ├── ColumnsWithJsonTypeCheckOnClusterTest.java │ │ ├── ColumnsWithSerialTypesCheckOnClusterTest.java │ │ ├── ColumnsWithoutDescriptionCheckOnClusterTest.java │ │ ├── DuplicatedForeignKeysCheckOnClusterTest.java │ │ ├── DuplicatedIndexesCheckOnClusterTest.java │ │ ├── ForeignKeysNotCoveredWithIndexCheckOnClusterTest.java │ │ ├── ForeignKeysWithUnmatchedColumnTypeCheckOnClusterTest.java │ │ ├── FunctionsWithoutDescriptionCheckOnClusterTest.java │ │ ├── IndexesWithBloatCheckOnClusterTest.java │ │ ├── IndexesWithBooleanCheckOnClusterTest.java │ │ ├── IndexesWithNullValuesCheckOnClusterTest.java │ │ ├── IndexesWithUnnecessaryWhereClauseCheckOnClusterTest.java │ │ ├── IntersectedForeignKeysCheckOnClusterTest.java │ │ ├── IntersectedIndexesCheckOnClusterTest.java │ │ ├── InvalidIndexesCheckOnClusterTest.java │ │ ├── NotValidConstraintsCheckOnClusterTest.java │ │ ├── ObjectsNotFollowingNamingConventionCheckOnClusterTest.java │ │ ├── PossibleObjectNameOverflowCheckOnClusterTest.java │ │ ├── PrimaryKeysThatMostLikelyNaturalKeysCheckOnClusterTest.java │ │ ├── PrimaryKeysWithSerialTypesCheckOnClusterTest.java │ │ ├── PrimaryKeysWithVarcharCheckOnClusterTest.java │ │ ├── SequenceOverflowCheckOnClusterTest.java │ │ ├── TablesNotLinkedToOthersCheckOnClusterTest.java │ │ ├── TablesWithBloatCheckOnClusterTest.java │ │ ├── TablesWithMissingIndexesCheckOnClusterTest.java │ │ ├── TablesWithZeroOrOneColumnCheckOnClusterTest.java │ │ ├── TablesWithoutDescriptionCheckOnClusterTest.java │ │ ├── TablesWithoutPrimaryKeyCheckOnClusterTest.java │ │ └── UnusedIndexesCheckOnClusterTest.java │ ├── common │ │ └── DatabaseCheckOnClusterTest.java │ └── management │ │ ├── DatabaseManagementImplTest.java │ │ └── DatabaseManagementImplUnitTest.java │ ├── e2e │ ├── HighAvailabilityPgConnectionClusterTest.java │ ├── PgConnectionAwareCluster.java │ └── PrimaryHostDeterminerClusterTest.java │ ├── support │ └── AbstractCheckOnClusterAssert.java │ └── utils │ └── CollectionUtilsTest.java ├── settings.gradle.kts ├── spring-boot-integration ├── console-demo-app │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── console │ │ │ │ └── ConsoleDemoApplication.java │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ └── console │ │ ├── ConsoleDemoApplicationRunTest.java │ │ └── ConsoleDemoApplicationTest.java ├── h2-demo-app │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── h2 │ │ │ │ └── H2DemoApplication.java │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ └── h2 │ │ ├── H2DemoApplicationRunTest.java │ │ └── H2DemoApplicationTest.java ├── kotlin-custom-ds-demo-app │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── kotlin │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── postgres │ │ │ │ └── kt │ │ │ │ └── custom │ │ │ │ └── ds │ │ │ │ ├── PostgresCustomDataSourceDemoApplication.kt │ │ │ │ └── config │ │ │ │ └── DataSourceConfiguration.kt │ │ └── resources │ │ │ ├── application.yaml │ │ │ ├── changelog │ │ │ ├── changelog.yaml │ │ │ └── sql │ │ │ │ └── warehouse.sql │ │ │ └── init.sql │ │ └── test │ │ ├── kotlin │ │ └── io │ │ │ └── github │ │ │ └── mfvanek │ │ │ └── pg │ │ │ └── spring │ │ │ └── postgres │ │ │ └── kt │ │ │ └── custom │ │ │ └── ds │ │ │ ├── DatabaseStructureStaticAnalysisTest.kt │ │ │ ├── PostgresCustomDataSourceDemoApplicationKtRunTest.kt │ │ │ └── PostgresCustomDataSourceDemoApplicationKtTest.kt │ │ └── resources │ │ └── application-test.yaml ├── kotlin-demo-app │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── kotlin │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── postgres │ │ │ │ └── kt │ │ │ │ ├── PostgresDemoApplication.kt │ │ │ │ └── config │ │ │ │ ├── ConfigurableEnvironmentMutator.kt │ │ │ │ └── DatabaseConfig.kt │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── kotlin │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ └── postgres │ │ └── kt │ │ ├── DatabaseStructureStaticAnalysisTest.kt │ │ ├── PostgresDemoApplicationKtTest.kt │ │ ├── PostgresDemoApplicationRunKtTest.kt │ │ └── config │ │ └── ConfigurableEnvironmentMutatorKtTest.kt ├── pg-index-health-test-starter │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ ├── DatabaseStructureChecksAutoConfiguration.java │ │ │ │ ├── DatabaseStructureHealthAutoConfiguration.java │ │ │ │ ├── DatabaseStructureHealthCondition.java │ │ │ │ ├── DatabaseStructureHealthProperties.java │ │ │ │ └── package-info.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring │ │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ ├── AutoConfigurationTestBase.java │ │ ├── DatabaseStructureHealthAutoConfigurationFilteringTest.java │ │ ├── DatabaseStructureHealthAutoConfigurationTest.java │ │ └── DatabaseStructureHealthPropertiesTest.java ├── postgres-demo-app-with-custom-user │ ├── build.gradle.kts │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── postgres │ │ │ │ └── with │ │ │ │ └── custom │ │ │ │ └── user │ │ │ │ ├── PostgresWithCustomUserDemoApplication.java │ │ │ │ └── config │ │ │ │ ├── ConfigurableEnvironmentMutator.java │ │ │ │ └── DatabaseConfig.java │ │ └── resources │ │ │ ├── application.yaml │ │ │ ├── changelog │ │ │ ├── changelog.yaml │ │ │ └── sql │ │ │ │ └── warehouse.sql │ │ │ └── init.sql │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ └── postgres │ │ └── with │ │ └── custom │ │ └── user │ │ ├── DatabaseStructureStaticAnalysisTest.java │ │ ├── PostgresWithCustomUserDemoApplicationRunTest.java │ │ ├── PostgresWithCustomUserDemoApplicationTest.java │ │ └── config │ │ └── ConfigurableEnvironmentMutatorTest.java ├── postgres-demo-app │ ├── build.gradle.kts │ ├── lombok.config │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mfvanek │ │ │ │ └── pg │ │ │ │ └── spring │ │ │ │ └── postgres │ │ │ │ ├── PostgresDemoApplication.java │ │ │ │ └── config │ │ │ │ ├── ConfigurableEnvironmentMutator.java │ │ │ │ └── DatabaseConfig.java │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── mfvanek │ │ └── pg │ │ └── spring │ │ └── postgres │ │ ├── DatabaseStructureStaticAnalysisTest.java │ │ ├── PostgresDemoApplicationRunTest.java │ │ ├── PostgresDemoApplicationTest.java │ │ └── config │ │ └── ConfigurableEnvironmentMutatorTest.java └── postgres-tc-url-demo-app │ ├── build.gradle.kts │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── mfvanek │ │ │ └── pg │ │ │ └── spring │ │ │ └── postgres │ │ │ └── tc │ │ │ └── url │ │ │ └── PostgresTestcontainersUrlDemoApplication.java │ └── resources │ │ └── application.yaml │ └── test │ └── java │ └── io │ └── github │ └── mfvanek │ └── pg │ └── spring │ └── postgres │ └── tc │ └── url │ ├── DatabaseStructureStaticAnalysisTest.java │ ├── PostgresTestcontainersUrlDemoApplicationRunTest.java │ └── PostgresTestcontainersUrlDemoApplicationTest.java └── сopyright.txt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: mfvanek 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | day: "monday" 8 | open-pull-requests-limit: 10 9 | - package-ecosystem: "gradle" 10 | directory: "/" 11 | schedule: 12 | interval: "weekly" 13 | day: "monday" 14 | open-pull-requests-limit: 10 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | # Gradle 26 | bin/ 27 | build/ 28 | .gradle/ 29 | .gradletasknamecache 30 | 31 | # IntelliJ 32 | out/ 33 | .idea/ 34 | .idea_modules/ 35 | *.iml 36 | *.ipr 37 | *.iws 38 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pg-index-health-core/src/main/resources"] 2 | path = pg-index-health-core/src/main/resources 3 | url = https://github.com/mfvanek/pg-index-health-sql.git 4 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | |---------| ------------------ | 7 | | 0.15.x | :white_check_mark: | 8 | 9 | ## Reporting a Vulnerability 10 | 11 | Please email mfvanek@gmail.com if you have a potential security vulnerability to report. 12 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | gradlePluginPortal() 7 | } 8 | 9 | dependencies { 10 | implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:6.1.13") 11 | implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:6.2.0.5505") 12 | implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.2.0") 13 | implementation("info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.15.0") 14 | implementation("org.gradle:test-retry-gradle-plugin:1.6.2") 15 | implementation(libs.forbiddenapis) 16 | implementation(libs.detekt) 17 | val kotlinVersion = "2.0.21" 18 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") 19 | implementation("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion") 20 | } 21 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "pg-index-health-conventions" 2 | 3 | dependencyResolutionManagement { 4 | versionCatalogs { 5 | create("libs") { 6 | from(files("../gradle/libs.versions.toml")) 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/pg-index-health.forbidden-apis.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis 12 | 13 | plugins { 14 | id("java") 15 | id("de.thetaphi.forbiddenapis") 16 | } 17 | 18 | forbiddenApis { 19 | bundledSignatures = setOf("jdk-unsafe", "jdk-deprecated", "jdk-internal", "jdk-non-portable", "jdk-system-out", "jdk-reflection") 20 | signaturesFiles = files("${rootDir}/config/forbidden-apis/forbidden-apis.txt") 21 | ignoreFailures = false 22 | } 23 | 24 | tasks { 25 | test { 26 | dependsOn(withType()) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/pg-index-health.java-application.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-compilation") 13 | id("pg-index-health.java-conventions") 14 | id("pg-index-health.forbidden-apis") 15 | } 16 | 17 | private val versionCatalog = extensions.getByType().named("libs") 18 | 19 | dependencies { 20 | versionCatalog.findLibrary("slf4j-simple").ifPresent { 21 | spotbugsSlf4j(it) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/pg-index-health.java-library.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("java-library") 13 | id("pg-index-health.java-compilation") 14 | id("pg-index-health.java-conventions") 15 | id("pg-index-health.forbidden-apis") 16 | id("pg-index-health.publish") 17 | } 18 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/pg-index-health.pitest.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | import info.solidsoft.gradle.pitest.PitestTask 12 | 13 | plugins { 14 | id("java") 15 | id("info.solidsoft.pitest") 16 | } 17 | 18 | dependencies { 19 | pitest("it.mulders.stryker:pit-dashboard-reporter:0.3.4") 20 | } 21 | 22 | pitest { 23 | junit5PluginVersion.set("1.2.3") 24 | pitestVersion.set("1.19.4") 25 | threads.set(4) 26 | if (System.getenv("STRYKER_DASHBOARD_API_KEY") != null) { 27 | outputFormats.set(setOf("stryker-dashboard")) 28 | } else { 29 | outputFormats.set(setOf("HTML")) 30 | } 31 | timestampedReports.set(false) 32 | mutationThreshold.set(100) 33 | exportLineCoverage.set(true) 34 | pluginConfiguration.set(mapOf("stryker.moduleName" to project.name)) 35 | } 36 | 37 | tasks.withType().configureEach { 38 | mustRunAfter(tasks.test) 39 | } 40 | 41 | tasks.build { 42 | dependsOn("pitest") 43 | } 44 | -------------------------------------------------------------------------------- /config/detekt/detekt.yml: -------------------------------------------------------------------------------- 1 | performance: 2 | SpreadOperator: 3 | active: false 4 | 5 | libraries: 6 | LibraryEntitiesShouldNotBePublic: 7 | active: false 8 | 9 | formatting: 10 | MaximumLineLength: 11 | maxLineLength: 200 12 | 13 | style: 14 | MaxLineLength: 15 | maxLineLength: 200 16 | -------------------------------------------------------------------------------- /config/forbidden-apis/forbidden-apis.txt: -------------------------------------------------------------------------------- 1 | @defaultMessage Avoid using these methods, consider alternative approaches 2 | java.util.Collections#emptyList() 3 | java.util.Collections#emptyMap() 4 | java.util.Collections#emptySet() 5 | java.util.Collections#emptyNavigableMap() 6 | java.util.Collections#emptyNavigableSet() 7 | java.util.Collections#emptySortedMap() 8 | java.util.Collections#emptySortedSet() 9 | java.util.Collections#singleton(java.lang.Object) 10 | java.util.Collections#singletonList(java.lang.Object) 11 | java.util.Collections#singletonMap(java.lang.Object,java.lang.Object) 12 | java.util.Arrays#asList(java.lang.Object[]) 13 | java.util.Collections#unmodifiableList(java.util.List) 14 | java.util.Collections#unmodifiableSet(java.util.Set) 15 | -------------------------------------------------------------------------------- /doc/rus/btree_indexes_on_array_columns.md: -------------------------------------------------------------------------------- 1 | # Проверка b-tree индексов на столбцах, содержащих массив значений 2 | 3 | ## Как работает b-tree индекс на столбцах с массивом значений 4 | 5 | b-tree индекс на таких столбцах эффективен, если нужно сравнивать массивы целиком, 6 | так как он [работает в условиях на равенство](https://postgrespro.ru/docs/postgresql/17/gin). 7 | Если нужно проверять вхождение элементов в массив, то он уже не подойдет. 8 | 9 | ## Почему больше подойдет индекс типа GIN 10 | 11 | Индекс GIN реализован как B-дерево, построенное по ключам - элементам массива, [подробнее в документации](https://postgrespro.ru/docs/postgresql/17/gin). 12 | Поэтому он подойдет, если потребуется сравнивать элементы массива в столбцах типа array. 13 | 14 | ## SQL запрос 15 | 16 | - [btree_indexes_on_array_columns.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/btree_indexes_on_array_columns.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 21 | 22 | ## Поддержка секционированных таблиц 23 | 24 | Поддерживает секционированные таблицы. 25 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 26 | -------------------------------------------------------------------------------- /doc/rus/columns_with_serial_types.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия столбцов типа serial, которые не являются первичным ключом 2 | 3 | ## Особенности типа serial в PosgreSQL 4 | 5 | Типы данных smallserial, serial и bigserial - это синтаксический сахар. 6 | Они реализованы через [последовательности целых чисел](https://postgrespro.ru/docs/postgresql/17/datatype-numeric). 7 | 8 | ## Почему serial не стоит использовать 9 | 10 | На столбце создается последовательность со значением по умолчанию, из которого будут вычисляться последующие значения. 11 | В БД создаются лишние объекты, которые на самом деле не нужны. 12 | В современных версиях PostgreSQL [даже для первичных ключей лучше не использовать serial-типы](primary_keys_with_serial_types.md). 13 | 14 | ## SQL запрос 15 | 16 | - [columns_with_serial_types.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/columns_with_serial_types.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 21 | 22 | ## Поддержка секционированных таблиц 23 | 24 | Поддерживает секционированные таблицы. 25 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 26 | -------------------------------------------------------------------------------- /doc/rus/columns_without_description.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия столбцов без описания 2 | 3 | ## Почему нужно добавлять описание столбцам 4 | 5 | Описание столбцов делает понятным бизнес-смысл хранящихся там значений. 6 | Разработчик\аналитик\тестировщик сделает меньше ошибок и быстрее выполнит свою работу, 7 | если будет понимать, какие есть ограничения на данные в столбцах со стороны бизнеса и откуда они берутся (какое у них назначение). 8 | Наличие описания у столбцов упрощает их поддержку и модификацию в будущем. 9 | 10 | ## SQL запрос 11 | 12 | - [columns_without_description.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/columns_without_description.sql) 13 | 14 | ## Тип проверки 15 | 16 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 17 | 18 | ## Поддержка секционированных таблиц 19 | 20 | Поддерживает секционированные таблицы. 21 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 22 | -------------------------------------------------------------------------------- /doc/rus/duplicated_foreign_keys.md: -------------------------------------------------------------------------------- 1 | # Проверка дублирующихся вторичных ключей в таблицах 2 | 3 | ## Как они появляются и почему нужно избавляться от дублирующихся вторичных ключей 4 | 5 | Внешние ключи могут быть созданы по нескольким атрибутам целевой таблицы - ссылка на ограничение по нескольким столбцам. 6 | При этом возможна ошибка - создание другого внешнего ключа с такими же атрибутами. 7 | Дублирование сущностей увеличивает когнитивную сложность и затрудняет поддержку и развитие схемы данных в будущем. 8 | 9 | ## SQL запрос 10 | 11 | - [duplicated_foreign_keys.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/duplicated_foreign_keys.sql) 12 | 13 | ## Тип проверки 14 | 15 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 16 | 17 | ## Поддержка секционированных таблиц 18 | 19 | Поддерживает секционированные таблицы. 20 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 21 | -------------------------------------------------------------------------------- /doc/rus/duplicated_indexes.md: -------------------------------------------------------------------------------- 1 | # Проверка дублирующихся индексов в таблицах 2 | 3 | ## Почему индекс может задублироваться 4 | 5 | Индекс на первичный ключ и индексы на ограничения уникальности создаются [автоматически](https://postgrespro.ru/docs/postgresql/17/indexes-unique). 6 | Если подобного рода индексы были созданы еще и вручную, то [получаются дубликаты](https://postgrespro.ru/docs/postgresql/17/sql-createindex). 7 | PostgreSQL не умеет отслеживать такие ситуации и предотвращать создание дубликатов. 8 | 9 | ## Почему нужно избавляться от дублирующихся индексов 10 | 11 | При изменении данных обновляется [каждый индекс](https://postgrespro.ru/docs/postgresql/17/btree). 12 | Таким образом дубликаты снижают производительность, занимают место на диске и 13 | требуют регулярного обслуживания (вакуумирование, реиндексация при распухании). 14 | 15 | ## SQL запрос 16 | 17 | - [duplicated_indexes.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/duplicated_indexes.sql) 18 | 19 | ## Тип проверки 20 | 21 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 22 | 23 | ## Поддержка секционированных таблиц 24 | 25 | Поддерживает секционированные таблицы. 26 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 27 | -------------------------------------------------------------------------------- /doc/rus/foreign_keys_with_unmatched_column_type.md: -------------------------------------------------------------------------------- 1 | # Проверка внешних ключей, у которых есть расхождения в типах столбцов 2 | 3 | ## Почему типы столбцов у внешних ключей должны совпадать 4 | 5 | Типы колонок в ссылающемся и целевом отношении должны совпадать. 6 | Колонка с типом `integer` должна ссылаться на колонку с типом `integer`. 7 | Это исключает лишние конвертации на уровне СУБД и в коде приложения, снижает количество ошибок, 8 | которые могут появляться из-за несоответствия типов в будущем. 9 | 10 | Можно возразить, достаточно чтобы в ссылающемся отношении типы колонок были совместимы и не меньше, чем в целевом отношении. 11 | Например, колонка с типом `bigint` может ссылаться на колонку с типом `integer`. 12 | **Так делать не следует**. 13 | Необходимо учитывать, что разные типы будут попадать в код приложения, особенно при автогенерации моделей. 14 | 15 | ## SQL запрос 16 | 17 | - [foreign_keys_with_unmatched_column_type.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/foreign_keys_with_unmatched_column_type.sql) 18 | 19 | ## Тип проверки 20 | 21 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 22 | 23 | ## Поддержка секционированных таблиц 24 | 25 | Поддерживает секционированные таблицы. 26 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 27 | -------------------------------------------------------------------------------- /doc/rus/functions_without_description.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия функций без описания 2 | 3 | ## Почему нужно добавлять описание функций 4 | 5 | С описанием легче применить функцию правильно и найти возможные ошибки в ее определении. 6 | Наличие описания у функций\процедур упрощает их поддержку и модификацию в будущем. 7 | 8 | ## SQL запрос 9 | 10 | - [functions_without_description.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/functions_without_description.sql) 11 | 12 | ## Тип проверки 13 | 14 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 15 | 16 | ## Поддержка секционированных таблиц 17 | 18 | Не применима для секционированных таблиц. 19 | -------------------------------------------------------------------------------- /doc/rus/indexes_with_boolean.md: -------------------------------------------------------------------------------- 1 | # Проверка индексов на boolean-столбцы в таблицах 2 | 3 | ## Почему такие индексы обычно не нужны 4 | 5 | boolean столбец может принимать только два значения: true и false. Поэтому у такого индекса низкая кардинальность. 6 | Индексы на столбцах с низкой кардинальностью редко используются планировщиком запросов, так как они незначительно ускоряют поиск данных. Планировщик, скорее всего, выберет полное сканирование при фильтрации по boolean-столбцу, если таблица небольшая или если запрос требует большого процента строк. 7 | 8 | ## Как лучше организовать индекс, включащий поиск по boolean-столбцу 9 | 10 | Если строк с определенным значением столбца типа boolean гораздо меньше половины и при поиске чаще ищутся именно такие строки, 11 | то [можно создать частичный индекс](https://postgrespro.ru/docs/postgrespro/17/indexes-partial) 12 | 13 | ## SQL запрос 14 | 15 | - [indexes_with_boolean.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/indexes_with_boolean.sql) 16 | 17 | ## Тип проверки 18 | 19 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 20 | 21 | ## Поддержка секционированных таблиц 22 | 23 | Поддерживает секционированные таблицы. 24 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 25 | -------------------------------------------------------------------------------- /doc/rus/indexes_with_null_values.md: -------------------------------------------------------------------------------- 1 | # Проверка присутствия индексов, включающих null значения 2 | 3 | ## Особенности создания b-tree индексов 4 | 5 | По умолчанию Postgres [включает null значения в btree-индексы](https://postgrespro.ru/docs/postgresql/17/indexes-ordering). 6 | 7 | ## Почему нужно удалять null значения из индексов 8 | 9 | Это может существенно уменьшить размер индекса в том случае если null значение встречается часто. 10 | Частичный индекс, из которого исключены null значения будет оптимальнее, потому что при поиске 11 | распространённого значения [индекс всё равно не будет использоваться](https://postgrespro.ru/docs/postgresql/17/indexes-partial). 12 | Поиск будет проходить быстрее. Индекс будет занимать меньше места на диске. 13 | 14 | ## SQL запрос 15 | 16 | - [indexes_with_null_values.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/indexes_with_null_values.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 21 | 22 | ## Поддержка секционированных таблиц 23 | 24 | Поддерживает секционированные таблицы. 25 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 26 | -------------------------------------------------------------------------------- /doc/rus/intersected_foreign_keys.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия пересекающихся внешних ключей в таблицах 2 | 3 | ## Как появляются пересекающиеся внешние ключи и почему иногда нужно избавиться от них 4 | 5 | Внешние ключи могут быть созданы по нескольким атрибутам (столбцам) целевой таблицы. 6 | При изменении структуры данных может потребоваться новое ограничение в целевой таблице и новый внешний ключ в ссылающейся таблице. 7 | Если устаревший внешний ключ останется, то это увеличивает когнитивную сложность и 8 | затрудняет поддержку и развитие структуры данных в дальнейшем. 9 | 10 | ## SQL запрос 11 | 12 | - [intersected_foreign_keys.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/intersected_foreign_keys.sql) 13 | 14 | ## Тип проверки 15 | 16 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 17 | 18 | ## Поддержка секционированных таблиц 19 | 20 | Поддерживает секционированные таблицы. 21 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 22 | -------------------------------------------------------------------------------- /doc/rus/intersected_indexes.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия пересекающихся индексов в таблицах 2 | 3 | ## Как появляется пересечение индексов 4 | 5 | Составной индекс может применяться в условиях [с любым подмножеством столбцов индекса](https://postgrespro.ru/docs/postgresql/17/indexes-multicolumn). 6 | Например, индекс для столбцов А+В так же эффективен при поиске по столбцу А, как и индекс только по столбцу А. 7 | Нужно только учесть, что в случае составного btree-индекса поиск будет эффективен, когда в условие входят ведущие (левые) столбцы составного индекса. 8 | 9 | ## Почему нужно избавляться от пересекающихся индексов 10 | 11 | При изменении данных обновляется [каждый индекс](https://postgrespro.ru/docs/postgresql/17/btree), 12 | таким образом дубликаты снижают производительность. 13 | 14 | ## SQL запрос 15 | 16 | - [intersected_indexes.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/intersected_indexes.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 21 | 22 | ## Поддержка секционированных таблиц 23 | 24 | Поддерживает секционированные таблицы. 25 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 26 | -------------------------------------------------------------------------------- /doc/rus/invalid_indexes.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия невалидных индексов в таблицах 2 | 3 | ## Почему может появиться невалидный индекс 4 | 5 | Иногда команда создания индекса CREATE INDEX CONCURRENTLY [завершается ошибкой](https://postgrespro.ru/docs/postgresql/17/sql-createindex). 6 | В этом случае индекс создается, но остаётся в невалидном состоянии и игнорируется при чтении данных. 7 | 8 | ## Почему нужно избавляться от невалидных индексов 9 | 10 | При вставке\удалении\обновлении данных невалидный индекс может использовать ресурсы системы так же, как и валидный, хотя он бесполезен. 11 | Если такой индекс уникальный (при этом он может быть составным, индексом по выражениям или частичным), 12 | то ограничение уникальности может остаться и влиять на изменения данных. 13 | Так же невалидный индекс занимает место на диске. 14 | 15 | ## SQL запрос 16 | 17 | - [invalid_indexes.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/invalid_indexes.sql) 18 | 19 | ## Тип проверки 20 | 21 | - **runtime** (имеет смысл запускать на работающем инстансе БД после выполнения миграций) 22 | - **static** (может выполняться в компонентных\интеграционных тестах при наличии миграций с проливкой начальных данных) 23 | 24 | ## Поддержка секционированных таблиц 25 | 26 | Поддерживает секционированные таблицы. Проверка выполняется на каждой секции. 27 | -------------------------------------------------------------------------------- /doc/rus/possible_object_name_overflow.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия объектов с названием максимальной длины 2 | 3 | ## Почему нужно отслеживать длину названий объектов БД 4 | 5 | Максимальный размер идентификатора составляет 63 байта. 6 | Если он превышен, то PostgreSQL без уведомления обрезает слишком длинное название. 7 | Это может привести к ситуации, когда 2 разных объекта становятся идентичными по названию. 8 | Например, если создается миграция, где создаются индексы с длинными названиями, 9 | которые начинаются одинаково, то при использовании выражения `IF NOT EXISTS` может создаться только один объект вместо нескольких. 10 | 11 | ## SQL запрос 12 | 13 | - [possible_object_name_overflow.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/possible_object_name_overflow.sql) 14 | 15 | ## Тип проверки 16 | 17 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 18 | 19 | ## Поддержка секционированных таблиц 20 | 21 | Поддерживает секционированные таблицы. 22 | Проверка выполняется как на самой секционированной таблице (родительской), так и на отдельных секциях (потомках). 23 | -------------------------------------------------------------------------------- /doc/rus/primary_keys_with_serial_types.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия первичных ключей с типом serial 2 | 3 | ## Почему первичный ключ не стоит создавать с типом serial 4 | 5 | Первичный ключ типа serial [создает проблемы](https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial): 6 | 7 | - не соответствует стандарту SQL, а значит код нельзя переиспользовать; 8 | - может вызывать ошибки, если манипуляции с таблицей включены в скрипты при деплое; 9 | - трудно вносить изменения в ПК с таким типом. 10 | 11 | Есть [другой вариант создания первичного ключа](https://postgrespro.ru/docs/postgresql/17/sql-createtable#SQL-CREATETABLE-PARMS-GENERATED-IDENTITY). 12 | Именно его нужно использовать. 13 | 14 | ## SQL запрос 15 | 16 | - [primary_keys_with_serial_types.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/primary_keys_with_serial_types.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 21 | 22 | ## Поддержка секционированных таблиц 23 | 24 | Поддерживает секционированные таблицы. 25 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 26 | -------------------------------------------------------------------------------- /doc/rus/sequence_overflow.md: -------------------------------------------------------------------------------- 1 | # Проверка состояния последовательностей на переполнение 2 | 3 | ## Почему нужно проверять состояние последовательности 4 | 5 | Суррогатные первичные ключи часто заполнятся из последовательности. 6 | Если данных много, то она может переполниться. 7 | Если не отслеживать объем оставшихся значений, то исправление ошибки может привести к длительной блокировке этой таблицы и других, 8 | если переполненный первичный ключ является для них внешним ключом. 9 | 10 | ## SQL запрос 11 | 12 | - [sequence_overflow.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/sequence_overflow.sql) 13 | 14 | ## Тип проверки 15 | 16 | - **runtime** (имеет смысл запускать на работающем инстансе БД) 17 | 18 | ## Поддержка секционированных таблиц 19 | 20 | Не применима для секционированных таблиц. 21 | -------------------------------------------------------------------------------- /doc/rus/tables_not_linked_to_others.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия таблиц, не связанных с другими таблицами 2 | 3 | ## Почему таблицы без связей нужно отслеживать 4 | 5 | Отсутствие связей в таблице может быть следствием ошибки: забыли добавить внешние ключи. 6 | Все таблицы в базе данных отражают модель данных - связи нужны для консистентных изменений в таблицах. 7 | Также внешние ключи дают возможность быстро и верно находить данные, относящиеся к одной сущности. 8 | 9 | Если таблицы без связей созданы намеренно, то их нужно просто проигнорировать. 10 | 11 | ## SQL запрос 12 | 13 | - [tables_not_linked_to_others.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_not_linked_to_others.sql) 14 | 15 | ## Тип проверки 16 | 17 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 18 | 19 | ## Поддержка секционированных таблиц 20 | 21 | Поддерживает секционированные таблицы. 22 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 23 | -------------------------------------------------------------------------------- /doc/rus/tables_with_missing_indexes.md: -------------------------------------------------------------------------------- 1 | # Проверка таблиц на нехватку индексов 2 | 3 | ## Как понять, что нужен индекс 4 | 5 | Представление pg_stat_all_tables [содержит статистику по обращениям к таблицам](https://postgrespro.ru/docs/postgresql/17/monitoring-stats#MONITORING-PG-STAT-ALL-INDEXES-VIEW). 6 | Отсюда можно получить данные о том, насколько часто используется последовательное сканирование и поиск с помощью индексов. 7 | Если таблица часто сканируется последовательно, то стоит добавить индексы для соответствующих столбцов. 8 | 9 | ## Почему нужно следить за использованием индексов 10 | 11 | Если статистика показывает много запросов с последовательным сканированием таблицы, 12 | то добавление индекса может ускорить поиск и снизить нагрузку на БД. 13 | 14 | ## SQL запрос 15 | 16 | - [tables_with_missing_indexes.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_with_missing_indexes.sql) 17 | 18 | ## Тип проверки 19 | 20 | - **runtime** (требует наличия накопленной статистики) 21 | 22 | В кластере БД проверка должна выполняться на каждом хосте. 23 | 24 | ## Поддержка секционированных таблиц 25 | 26 | Поддерживает секционированные таблицы. Проверка выполняется на каждой секции. 27 | -------------------------------------------------------------------------------- /doc/rus/tables_without_description.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия таблиц без описания 2 | 3 | ## Почему нужно добавлять описание таблицам 4 | 5 | Разработчикам легче ориентироваться, из каких таблиц брать нужные данные. 6 | Наличие описания у таблиц упрощает их поддержку и модификацию в будущем. 7 | 8 | ## SQL запрос 9 | 10 | - [tables_without_description.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_without_description.sql) 11 | 12 | ## Тип проверки 13 | 14 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 15 | 16 | ## Поддержка секционированных таблиц 17 | 18 | Поддерживает секционированные таблицы. 19 | Проверка выполняется на самой секционированной таблице (родительской). Отдельные секции (потомки) игнорируются. 20 | -------------------------------------------------------------------------------- /doc/rus/tables_without_primary_key.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия таблиц без первичных ключей 2 | 3 | ## Особенности создания таблиц 4 | 5 | PostgreSQL позволяет создавать таблицы без первичного ключа, но такой дизайн может приводить к проблемам в будущем, 6 | связанным с обслуживанием таблиц. 7 | Например, [pg_repack](https://github.com/reorg/pg_repack) не может обрабатывать таблицы без первичного ключа или иного ограничения уникальности. 8 | Аналогичная ситуация с [логической репликацией](https://postgrespro.ru/docs/postgresql/17/logical-replication-publication) - 9 | для эффективной работы в реплицируемых таблицах требуется наличие первичного ключа или иного ограничения уникальности. 10 | 11 | ## SQL запрос 12 | 13 | - [tables_without_primary_key.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/tables_without_primary_key.sql) 14 | 15 | ## Тип проверки 16 | 17 | - **static** (может выполняться на пустой БД в компонентных\интеграционных тестах) 18 | 19 | ## Поддержка секционированных таблиц 20 | 21 | Поддерживает секционированные таблицы. 22 | Проверка выполняется как на самой секционированной таблице (родительской), так и на каждой секции. 23 | -------------------------------------------------------------------------------- /doc/rus/unused_indexes.md: -------------------------------------------------------------------------------- 1 | # Проверка наличия неиспользуемых индексов в таблицах 2 | 3 | ## Как появляются неиспользуемые индексы 4 | 5 | PostgreSQL может никогда не использовать некоторые индексы. 6 | 7 | Причин у этого может быть много: 8 | * наличие аналогичных индексов (дублирующихся или пересекающихся) 9 | * малый размер таблицы 10 | * низкая селективность индекса и другие. 11 | 12 | ## Почему нужно избавляться от неиспользуемых индексов 13 | 14 | При изменении данных обновляется [каждый индекс](https://postgrespro.ru/docs/postgresql/17/btree), таким образом лишние индексы снижают производительность. 15 | Так же каждый индекс занимает место на диске. 16 | 17 | ## SQL запрос 18 | 19 | - [unused_indexes.sql](https://github.com/mfvanek/pg-index-health-sql/blob/master/sql/unused_indexes.sql) 20 | 21 | ## Тип проверки 22 | 23 | - **runtime** (требует наличия накопленной статистики) 24 | 25 | В кластере БД проверка должна выполняться на каждом хосте. 26 | 27 | ## Поддержка секционированных таблиц 28 | 29 | Поддерживает секционированные таблицы. Проверка выполняется на каждой секции. 30 | -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | postgres: 3 | image: postgres:17.4 4 | shm_size: "2gb" 5 | environment: 6 | POSTGRES_DB: "pgih-db" 7 | POSTGRES_USER: "pgih-db-user" 8 | POSTGRES_PASSWORD: "pgih-db-password" 9 | PGDATA: "/var/lib/postgresql/data/pgdata" 10 | volumes: 11 | - pgih-db-data:/var/lib/postgresql/data 12 | ports: 13 | - "6432:5432" 14 | 15 | volumes: 16 | pgih-db-data: 17 | -------------------------------------------------------------------------------- /docker/local_development.md: -------------------------------------------------------------------------------- 1 | # Run PostgreSQL in Docker for local development 2 | 3 | ## Docker Compose 4 | 5 | ### Start 6 | 7 | ```shell 8 | docker-compose --project-name="pgih-db" up -d 9 | ``` 10 | 11 | ### Stop 12 | 13 | ```shell 14 | docker-compose --project-name="pgih-db" down 15 | ``` 16 | 17 | ## Explore volumes 18 | 19 | ### List all volumes 20 | 21 | ```shell 22 | docker volume ls 23 | ``` 24 | 25 | ### Delete specified volume 26 | 27 | ```shell 28 | docker volume rm pgih-db_pgih-db-data 29 | ``` 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | sonatypeUsername= 2 | sonatypePassword= 3 | systemProp.org.gradle.internal.publish.checksums.insecure=true 4 | org.gradle.parallel=true 5 | org.gradle.daemon=true 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfvanek/pg-index-health/ab01f81959e538fd5430bd3d715021b1f99822b1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mfvanek/pg-index-health/ab01f81959e538fd5430bd3d715021b1f99822b1/logo.png -------------------------------------------------------------------------------- /pg-index-health-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | } 4 | 5 | description = "pg-index-health-core is a Java library for analyzing and maintaining indexes and tables health in PostgreSQL databases on a specific host." 6 | 7 | dependencies { 8 | api(project(":pg-index-health-model")) 9 | api(project(":pg-index-health-jdbc-connection")) 10 | 11 | testImplementation(project(":pg-index-health-testing")) 12 | testImplementation(testFixtures(project(":pg-index-health-model"))) 13 | testImplementation(testFixtures(project(":pg-index-health-jdbc-connection"))) 14 | testImplementation("org.junit.jupiter:junit-jupiter-params") 15 | testImplementation("org.mockito:mockito-core") 16 | testImplementation(libs.postgresql) 17 | 18 | testFixturesImplementation(libs.jspecify) 19 | testFixturesImplementation(libs.apache.commons.lang3) 20 | testFixturesImplementation(libs.postgresql) 21 | testFixturesImplementation(project(":pg-index-health-testing")) 22 | } 23 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/common/CheckTypeAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.common; 12 | 13 | /** 14 | * Allows getting information about check/diagnostic type. 15 | * 16 | * @author Ivan Vakhrushev 17 | * @since 0.13.2 18 | */ 19 | @FunctionalInterface 20 | public interface CheckTypeAware { 21 | 22 | /** 23 | * Defines whether this check/diagnostic is runtime (make sense to perform only on a production database with real data and statistics). 24 | * 25 | * @return true if this is a runtime check 26 | * @see Diagnostic.ExecutionTopology#ACROSS_CLUSTER 27 | */ 28 | boolean isRuntime(); 29 | 30 | /** 31 | * Defines whether this check/diagnostic is static (can be run in unit/integration tests on an empty database). 32 | * 33 | * @return true if this is a static check 34 | */ 35 | default boolean isStatic() { 36 | return !isRuntime(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/common/DiagnosticAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.common; 12 | 13 | /** 14 | * Allows getting information about rule related to the check. 15 | * 16 | * @author Ivan Vakhrushev 17 | * @since 0.6.0 18 | */ 19 | public interface DiagnosticAware { 20 | 21 | /** 22 | * Retrieves the diagnostic - a rule related to the check. 23 | * 24 | * @return diagnostic 25 | * @see Diagnostic 26 | */ 27 | Diagnostic getDiagnostic(); 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/common/RawTypeAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.common; 12 | 13 | import io.github.mfvanek.pg.model.dbobject.DbObject; 14 | 15 | /** 16 | * Allows getting information about original generic type. 17 | * 18 | * @param represents an object in a database associated with a table 19 | * @author Ivan Vakhrushev 20 | * @since 0.6.0 21 | */ 22 | public interface RawTypeAware { 23 | 24 | /** 25 | * Retrieves original java type. 26 | * 27 | * @return java type representing database object 28 | */ 29 | Class getType(); 30 | } 31 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/common/ResultSetExtractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.common; 12 | 13 | import java.sql.ResultSet; 14 | import java.sql.SQLException; 15 | 16 | /** 17 | * A mapper from raw data to domain model. 18 | * 19 | * @param any type represents an object in a database 20 | * @author Ivan Vakhrushev 21 | */ 22 | @FunctionalInterface 23 | public interface ResultSetExtractor { 24 | 25 | /** 26 | * Converts a row from database to an arbitrary domain model. 27 | * 28 | * @param resultSet the ResultSet to extract data from 29 | * @return an arbitrary result object 30 | * @throws SQLException if an SQLException is encountered getting column values or navigating 31 | */ 32 | T extractData(ResultSet resultSet) throws SQLException; 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/common/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Common checks related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.checks.common; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/extractors/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Result-set extractors. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.checks.extractors; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/checks/host/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Checks on host related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.checks.host; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/statistics/StatisticsAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.statistics; 12 | 13 | import java.time.OffsetDateTime; 14 | import java.util.Optional; 15 | 16 | /** 17 | * A set of methods to manage statistics. 18 | * 19 | * @author Ivan Vakhrushev 20 | */ 21 | public interface StatisticsAware { 22 | 23 | /** 24 | * Resets all statistics counters for the current database to zero. 25 | *

26 | * Note: superuser privileges are required. 27 | * 28 | * @return true if the operation is successful 29 | * @see Monitoring Database Activity 30 | */ 31 | boolean resetStatistics(); 32 | 33 | /** 34 | * Retrieves the time at which database statistics were last reset. 35 | * 36 | * @return {@code Optional} of null or time at which database statistics were last reset. 37 | */ 38 | Optional getLastStatsResetTimestamp(); 39 | } 40 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/statistics/StatisticsQueryExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.statistics; 12 | 13 | import io.github.mfvanek.pg.connection.PgConnection; 14 | import io.github.mfvanek.pg.core.checks.common.ResultSetExtractor; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * An abstraction of sql query executor without schema. 20 | * 21 | * @author Ivan Vakhrushev 22 | * @since 0.6.1 23 | */ 24 | @FunctionalInterface 25 | public interface StatisticsQueryExecutor { 26 | 27 | List executeQuery(PgConnection pgConnection, 28 | String sqlQuery, 29 | ResultSetExtractor rse); 30 | } 31 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/statistics/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Statistics related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.statistics; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/utils/exception/ReadQueryFromFileException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.utils.exception; 12 | 13 | import java.io.IOException; 14 | 15 | /** 16 | * Custom unchecked exception for IO errors while reading sql query from file. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @since 0.15.0 20 | */ 21 | public class ReadQueryFromFileException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 2030407491772154787L; 24 | 25 | public ReadQueryFromFileException(final String sqlFileName, final IOException cause) { 26 | super("Error occurred while reading sql query from file " + sqlFileName, cause); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/utils/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Custom checks exceptions. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.utils.exception; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/main/java/io/github/mfvanek/pg/core/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Utility classes for executing SQL queries. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.utils; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/extractors/ColumnExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.extractors; 12 | 13 | import org.junit.jupiter.api.Tag; 14 | import org.junit.jupiter.api.Test; 15 | 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | 18 | @Tag("fast") 19 | class ColumnExtractorTest { 20 | 21 | @Test 22 | void shouldCreateInstance() { 23 | assertThat(ColumnExtractor.of()) 24 | .isNotNull() 25 | .isInstanceOf(ColumnExtractor.class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/extractors/ColumnWithSerialTypeExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.extractors; 12 | 13 | import org.junit.jupiter.api.Tag; 14 | import org.junit.jupiter.api.Test; 15 | 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | 18 | @Tag("fast") 19 | class ColumnWithSerialTypeExtractorTest { 20 | 21 | @Test 22 | void shouldCreateInstance() { 23 | assertThat(ColumnWithSerialTypeExtractor.of()) 24 | .isNotNull() 25 | .isInstanceOf(ColumnWithSerialTypeExtractor.class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/test/java/io/github/mfvanek/pg/core/checks/extractors/TableExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.checks.extractors; 12 | 13 | import org.junit.jupiter.api.Tag; 14 | import org.junit.jupiter.api.Test; 15 | 16 | import static org.assertj.core.api.Assertions.assertThat; 17 | 18 | @Tag("fast") 19 | class TableExtractorTest { 20 | 21 | @Test 22 | void shouldCreateInstance() { 23 | assertThat(TableExtractor.of()) 24 | .isNotNull() 25 | .isInstanceOf(TableExtractor.class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/DatabaseConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support; 12 | 13 | @FunctionalInterface 14 | public interface DatabaseConfigurer { 15 | 16 | DatabasePopulator configure(DatabasePopulator databasePopulator); 17 | } 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Checks testing related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.fixtures.support; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddArrayColumnAndIndexToPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddArrayColumnAndIndexToPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.t1 add column if not exists roles text[];", 21 | "create index if not exists t1_roles_btree_idx on {schemaName}.t1 (roles) where roles is not null;" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddBlankCommentOnColumnsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddBlankCommentOnColumnsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on column {schemaName}.clients.id is '';", 21 | "comment on column {schemaName}.accounts.id is ' ';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddBlankCommentOnFunctionsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddBlankCommentOnFunctionsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on function {schemaName}.add(a integer, b integer) is ' ';", 21 | "comment on function {schemaName}.add(a int, b int, c int) is '';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddBlankCommentOnTablesStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddBlankCommentOnTablesStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on table {schemaName}.clients is ' ';", 21 | "comment on table {schemaName}.accounts is '';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddCommentOnFunctionsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddCommentOnFunctionsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on function {schemaName}.add(a integer, b integer) is 'Sums two given arguments';", 21 | "comment on function {schemaName}.add(a int, b int, c int) is 'Sums three given arguments';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddCommentOnProceduresStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddCommentOnProceduresStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on procedure {schemaName}.insert_data(a integer, b integer) is 'Inserts two rows into clients';", 21 | "comment on procedure {schemaName}.insert_data(a int, b int, c int) is 'Inserts three rows into clients';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddCommentOnTablesStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddCommentOnTablesStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "comment on table {schemaName}.clients is 'Customer Information';", 21 | "comment on table {schemaName}.accounts is 'Information about customer accounts';" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddDuplicatedForeignKeysStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddDuplicatedForeignKeysStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("alter table if exists {schemaName}.accounts " + 20 | "add constraint c_accounts_fk_client_id_duplicate foreign key (client_id) references {schemaName}.clients (id);" 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddDuplicatedForeignKeysToPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddDuplicatedForeignKeysToPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.t1 " + 21 | "add constraint t1_ref_type_fk_duplicate foreign key (ref_type) references {schemaName}.dict(ref_type);" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddIntersectedForeignKeysToPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddIntersectedForeignKeysToPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.dict add column ref_value varchar(64);", 21 | "create unique index if not exists idx_dict_ref_type_ref_value on {schemaName}.dict (ref_type, ref_value);", 22 | "alter table if exists {schemaName}.t1 " + 23 | "add constraint t1_ref_type_ref_value_fk foreign key (ref_type, ref_value) references {schemaName}.dict(ref_type, ref_value);" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddInvalidForeignKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddInvalidForeignKeyStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.accounts " + 21 | "add constraint c_accounts_fk_client_id_not_validated_yet foreign key (client_id) references {schemaName}.clients (id) not valid;", 22 | "alter table if exists {schemaName}.accounts " + 23 | "add constraint c_accounts_chk_client_id_not_validated_yet check (client_id > 0) not valid;" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddLinksBetweenAccountsAndClientsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddLinksBetweenAccountsAndClientsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("alter table if exists {schemaName}.accounts " + 20 | "add constraint c_accounts_fk_client_id foreign key (client_id) references {schemaName}.clients (id);" 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddNotValidConstraintToPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddNotValidConstraintToPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.t1 " + 21 | "add constraint t1_entity_id_not_validated_yet check (entity_id != '') not valid;", 22 | "alter table if exists {schemaName}.t1_default " + 23 | "add constraint t1_default_entity_id_not_validated_yet check (entity_id != '') not valid;" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/AddPrimaryKeyForDefaultPartitionStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class AddPrimaryKeyForDefaultPartitionStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.custom_entity_reference_with_very_very_very_long_name_1_default " + 21 | "add primary key (ref_type, ref_value, creation_date, entity_id);" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/ConvertColumnToJsonTypeStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class ConvertColumnToJsonTypeStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("alter table if exists {schemaName}.clients alter column info type json using info::json"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateAccountsTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateAccountsTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create sequence if not exists {schemaName}.accounts_seq", 21 | "create table if not exists {schemaName}.accounts (" + 22 | "id bigint not null primary key default nextval('{schemaName}.accounts_seq')," + 23 | "client_id bigint not null," + 24 | "account_number varchar(50) not null unique," + 25 | "account_balance numeric(22,2) not null default 0," + 26 | "deleted boolean not null default false)" 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateBadlyNamedPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateBadlyNamedPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.\"one-partitioned\"(" + 21 | "\"bad-id\" bigserial not null primary key" + 22 | ") partition by range (\"bad-id\");", 23 | "create table if not exists {schemaName}.\"one-default\" " + 24 | "partition of {schemaName}.\"one-partitioned\" default;" 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateDuplicatedAndIntersectedIndexesInPartitionedTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateDuplicatedAndIntersectedIndexesInPartitionedTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create index if not exists idx_t1_deleted_duplicate on {schemaName}.t1(deleted);", 21 | "create index if not exists idx_t1_deleted_entity_id on {schemaName}.t1(deleted, entity_id);" 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateDuplicatedCustomCollationIndexStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateDuplicatedCustomCollationIndexStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("create index if not exists i_accounts_account_number " + 20 | "on {schemaName}.accounts (account_number collate {schemaName}.\"C.UTF-8\")"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateDuplicatedHashIndexStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateDuplicatedHashIndexStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create index if not exists i_accounts_account_number on {schemaName}.accounts using hash(account_number)", 21 | "create index if not exists i_clients_last_first on {schemaName}.clients (last_name, first_name)", 22 | "create index if not exists i_clients_last_name on {schemaName}.clients using hash(last_name)" 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateEmptyTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateEmptyTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.empty ();" 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateForeignKeyOnNullableColumnStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateForeignKeyOnNullableColumnStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "alter table if exists {schemaName}.bad_clients " + 21 | "add constraint c_bad_clients_fk_real_client_id foreign key (real_client_id) references {schemaName}.clients (id);", 22 | "alter table if exists {schemaName}.bad_clients " + 23 | "add constraint c_bad_clients_fk_email_phone foreign key (email, phone) references {schemaName}.clients (email, phone);" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateFunctionsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateFunctionsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create or replace function {schemaName}.add(a integer, b integer) returns integer " + 21 | "as 'select $1 + $2;' " + 22 | "language sql " + 23 | "immutable " + 24 | "returns null on null input;", 25 | "create or replace function {schemaName}.add(a int, b int, c int) returns int " + 26 | "as 'select $1 + $2 + $3;' " + 27 | "language sql " + 28 | "immutable " + 29 | "returns null on null input;" 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithBooleanValuesStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateIndexWithBooleanValuesStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create index if not exists i_accounts_deleted " + 21 | "on {schemaName}.accounts (deleted)", 22 | "create unique index if not exists i_accounts_account_number_deleted " + 23 | "on {schemaName}.accounts (account_number, deleted)" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexWithNullValuesStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateIndexWithNullValuesStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("create index if not exists i_clients_middle_name on {schemaName}.clients (middle_name)"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateIndexesWithDifferentOpclassStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateIndexesWithDifferentOpclassStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create index if not exists i_clients_last_name " + 21 | "on {schemaName}.clients using btree(lower(last_name))", 22 | "create index if not exists i_clients_last_name_ops " + 23 | "on {schemaName}.clients using btree(lower(last_name) text_pattern_ops)" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateMaterializedViewStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateMaterializedViewStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create materialized view if not exists " + 21 | "{schemaName}.\"accounts-materialized-view-with-length-63-1234567890-1234567890\" as (" + 22 | "select client_id, account_number from {schemaName}.accounts);" 23 | ); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateNotSuitableIndexForForeignKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateNotSuitableIndexForForeignKeyStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("create index if not exists " + 20 | "i_accounts_account_number_client_id on {schemaName}.accounts (account_number, client_id)"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedIndexWithUnnecessaryWhereClauseStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreatePartitionedIndexWithUnnecessaryWhereClauseStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.one_partitioned(" + 21 | "\"first-ref\" bigint not null," + 22 | "second_ref bigint not null" + 23 | ") partition by range (second_ref);", 24 | "create index if not exists \"idx_second_ref_first-ref\" on {schemaName}.one_partitioned (second_ref, \"first-ref\") " + 25 | "where \"first-ref\" is not null;", 26 | "create table if not exists {schemaName}.one_default partition of {schemaName}.one_partitioned default;" 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithDroppedColumnStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreatePartitionedTableWithDroppedColumnStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.tp(" + 21 | "ref_type bigint not null," + 22 | "entity_id varchar(64) not null" + 23 | ") partition by range (ref_type);", 24 | "alter table if exists {schemaName}.tp drop column entity_id;", 25 | "create table if not exists {schemaName}.tp_default " + 26 | "partition of {schemaName}.tp default;" 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreatePartitionedTableWithJsonAndSerialColumnsStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreatePartitionedTableWithJsonAndSerialColumnsStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.parent(" + 21 | "ref_type varchar(32)," + 22 | "ref_value varchar(64)," + 23 | "creation_date timestamp with time zone not null," + 24 | "entity_id varchar(64) not null," + 25 | "real_client_id bigserial," + 26 | "raw_data json" + 27 | ") partition by range (creation_date);", 28 | "create table if not exists {schemaName}.partition_default " + 29 | "partition of {schemaName}.parent default;" 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateSuitableIndexForForeignKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateSuitableIndexForForeignKeyStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of("create index if not exists " + 20 | "i_accounts_client_id_account_number on {schemaName}.accounts (client_id, account_number)" 21 | ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateTableWithCheckConstraintOnSerialPrimaryKeyStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.another_table(" + 21 | "id bigserial primary key, " + 22 | "constraint not_reserved_id check (id > 1000), " + 23 | "constraint less_than_million check (id < 1000000));" 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithIdentityPrimaryKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateTableWithIdentityPrimaryKeyStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.test_table_with_identity_pk(" + 21 | "id bigint not null generated always as identity," + 22 | "num bigserial," + 23 | "constraint primary_key_length_62_for_test_table_with_identity_pk_12345678 primary key (id)," + 24 | "constraint num_less_than_million_constraint_with_length_63_1234567890_1234 check (num < 1000000));" 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateTableWithSerialPrimaryKeyReferencesToAnotherTableStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.test_table(" + 21 | "id bigserial, " + 22 | "num bigserial, " + 23 | "constraint test_table_pkey_id primary key (id), " + 24 | "constraint test_table_fkey_other_id foreign key (id) references {schemaName}.another_table (id), " + 25 | "constraint test_table_fkey_one_more_id foreign key (id) references {schemaName}.one_more_table (id));" 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithUniqueSerialColumnStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.util.List; 14 | 15 | public class CreateTableWithUniqueSerialColumnStatement extends AbstractDbStatement { 16 | 17 | @Override 18 | protected List getSqlToExecute() { 19 | return List.of( 20 | "create table if not exists {schemaName}.one_more_table(" + 21 | "id bigserial, " + 22 | "constraint unique_id unique (id), " + 23 | "constraint not_reserved_id check (id > 1000), " + 24 | "constraint less_than_million check (id < 1000000));" 25 | ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/CreateTableWithoutPrimaryKeyStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.sql.SQLException; 14 | import java.sql.Statement; 15 | import java.util.List; 16 | 17 | public class CreateTableWithoutPrimaryKeyStatement extends AbstractDbStatement { 18 | 19 | @Override 20 | protected List getSqlToExecute() { 21 | return List.of("create table if not exists {schemaName}.bad_clients (" + 22 | "id bigint not null, " + 23 | "name varchar(255) not null," + 24 | "real_client_id integer," + 25 | "email varchar(200)," + 26 | "phone varchar(51))"); 27 | } 28 | 29 | @Override 30 | public void postExecute(final Statement statement, final String schemaName) throws SQLException { 31 | throwExceptionIfTableDoesNotExist(statement, "bad_clients", schemaName); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/DbStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import java.sql.SQLException; 14 | import java.sql.Statement; 15 | 16 | @FunctionalInterface 17 | public interface DbStatement { 18 | 19 | void execute(Statement statement) throws SQLException; 20 | } 21 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/DropColumnStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.core.fixtures.support.statements; 12 | 13 | import io.github.mfvanek.pg.model.validation.Validators; 14 | 15 | import java.util.List; 16 | 17 | public class DropColumnStatement extends AbstractDbStatement { 18 | 19 | private final String tableName; 20 | private final String columnName; 21 | 22 | public DropColumnStatement(final String tableName, final String columnName) { 23 | this.tableName = Validators.tableNameNotBlank(tableName); 24 | this.columnName = Validators.notBlank(columnName, "columnName"); 25 | } 26 | 27 | @Override 28 | protected List getSqlToExecute() { 29 | return List.of("alter table if exists {schemaName}." + tableName + " drop column " + columnName); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pg-index-health-core/src/testFixtures/java/io/github/mfvanek/pg/core/fixtures/support/statements/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Database creating statements. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.core.fixtures.support.statements; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-generator/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | id("pg-index-health.pitest") 4 | } 5 | 6 | description = "pg-index-health-generator is an extension for generating database migrations in sql format based on pg-index-health diagnostics." 7 | 8 | dependencies { 9 | api(project(":pg-index-health-model")) 10 | 11 | testImplementation(testFixtures(project(":pg-index-health-model"))) 12 | testImplementation(testFixtures(project(":pg-index-health-jdbc-connection"))) 13 | } 14 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/AbstractOptionsAwareSqlGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator; 12 | 13 | import io.github.mfvanek.pg.model.table.TableNameAware; 14 | 15 | import java.util.Locale; 16 | import java.util.Objects; 17 | 18 | abstract class AbstractOptionsAwareSqlGenerator { 19 | 20 | protected static final String WHITESPACE = " "; 21 | 22 | protected final GeneratingOptions options; 23 | 24 | protected AbstractOptionsAwareSqlGenerator(final GeneratingOptions options) { 25 | this.options = Objects.requireNonNull(options, "options cannot be null"); 26 | } 27 | 28 | protected String keyword(final String keyword) { 29 | if (options.isUppercaseForKeywords()) { 30 | return keyword.toUpperCase(Locale.ROOT); 31 | } 32 | return keyword; 33 | } 34 | 35 | public abstract String generate(T dbObject); 36 | } 37 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/DbMigrationGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator; 12 | 13 | import io.github.mfvanek.pg.model.table.TableNameAware; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Database migrations generator. 19 | * 20 | * @param represents an object in a database associated with a table 21 | * @author Ivan Vakhrushev 22 | * @since 0.5.0 23 | */ 24 | public interface DbMigrationGenerator { 25 | 26 | /** 27 | * Generates sql migrations based on the specified rows. 28 | * 29 | * @param rows a set of data on the basis of which the sql migration will be generated 30 | * @return a list of generated sql migrations 31 | * @since 0.10.0 32 | */ 33 | List generate(List rows); 34 | } 35 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/DropSequenceGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator; 12 | 13 | import io.github.mfvanek.pg.model.column.ColumnWithSerialType; 14 | 15 | import java.util.Objects; 16 | 17 | final class DropSequenceGenerator extends AbstractOptionsAwareSqlGenerator { 18 | 19 | DropSequenceGenerator(final GeneratingOptions options) { 20 | super(options); 21 | } 22 | 23 | @Override 24 | public String generate(final ColumnWithSerialType column) { 25 | Objects.requireNonNull(column, "column cannot be null"); 26 | return keyword("drop sequence ") + 27 | keyword("if exists ") + 28 | column.getSequenceName() + 29 | ';'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/ForeignKeyMigrationGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator; 12 | 13 | import io.github.mfvanek.pg.model.constraint.ForeignKey; 14 | 15 | /** 16 | * Migration generator for creating indexes covering foreign keys. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @since 0.5.0 20 | */ 21 | public class ForeignKeyMigrationGenerator extends AbstractDbMigrationGenerator { 22 | 23 | private final PgIndexOnForeignKeyGenerator generator; 24 | 25 | public ForeignKeyMigrationGenerator(final GeneratingOptions options) { 26 | this.generator = new PgIndexOnForeignKeyGenerator(options); 27 | } 28 | 29 | @Override 30 | protected String generate(final ForeignKey foreignKey) { 31 | return generator.generate(foreignKey); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/IdxPosition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator; 12 | 13 | /** 14 | * Possible positions of "idx" in the generated index name. 15 | * 16 | * @author Ivan Vakhrushev 17 | * @since 0.5.0 18 | */ 19 | public enum IdxPosition { 20 | 21 | /** 22 | * Do not add "idx" to the index name. 23 | */ 24 | NONE, 25 | /** 26 | * Add "idx" to the beginning of the index name. 27 | */ 28 | PREFIX, 29 | /** 30 | * Add "idx" to the end of the index name. 31 | */ 32 | SUFFIX 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Database migrations generator related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.generator; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/utils/NameUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.generator.utils; 12 | 13 | import io.github.mfvanek.pg.model.table.TableNameAware; 14 | 15 | public final class NameUtils { 16 | 17 | private NameUtils() { 18 | throw new UnsupportedOperationException(); 19 | } 20 | 21 | public static String getTableNameWithoutSchema(final TableNameAware tableNameAware) { 22 | final String tableName = tableNameAware.getTableName(); 23 | final int index = tableName.indexOf('.'); 24 | final boolean containsSchema = index >= 0; 25 | if (containsSchema) { 26 | return tableName.substring(index + 1); 27 | } 28 | return tableName; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pg-index-health-generator/src/main/java/io/github/mfvanek/pg/generator/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An additional generator utils. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.generator.utils; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | id("pg-index-health.pitest") 4 | } 5 | 6 | description = "pg-index-health-jdbc-connection is an abstraction of a connection to a high availability PostgreSQL cluster." 7 | 8 | dependencies { 9 | api(project(":pg-index-health-model")) 10 | implementation(libs.apache.commons.dbcp2) 11 | 12 | testImplementation(project(":pg-index-health-testing")) 13 | testImplementation(testFixtures(project(":pg-index-health-model"))) 14 | testImplementation("org.mockito:mockito-core") 15 | testImplementation(libs.equalsverifier) 16 | testImplementation(libs.awaitility) 17 | 18 | testRuntimeOnly(libs.postgresql) 19 | 20 | testFixturesImplementation(libs.jspecify) 21 | } 22 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/HighAvailabilityPgConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection; 12 | 13 | import java.util.Set; 14 | 15 | /** 16 | * An abstraction of a connection to a high availability cluster (with set of primary host and replicas). 17 | * 18 | * @author Ivan Vakhrushev 19 | * @see PgConnection 20 | */ 21 | public interface HighAvailabilityPgConnection { 22 | 23 | /** 24 | * Retrieves connection to a primary host in the cluster. 25 | * 26 | * @return {@code PgConnection} to a primary host in the cluster 27 | */ 28 | PgConnection getConnectionToPrimary(); 29 | 30 | /** 31 | * Retrieves connections to all hosts in the cluster (including a connection to a primary host). 32 | * 33 | * @return {@code Set} of connections to all hosts in target cluster 34 | */ 35 | Set getConnectionsToAllHostsInCluster(); 36 | } 37 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection; 12 | 13 | import io.github.mfvanek.pg.connection.host.HostAware; 14 | import io.github.mfvanek.pg.connection.host.PgHost; 15 | 16 | import javax.sql.DataSource; 17 | 18 | /** 19 | * A wrapper of standard {@code DataSource} interface with awareness of real host. 20 | * 21 | * @author Ivan Vakhrushev 22 | * @see HostAware 23 | * @see PgHost 24 | */ 25 | public interface PgConnection extends HostAware { 26 | 27 | /** 28 | * Retrieves a standard {@code DataSource} object to access the database. 29 | * 30 | * @return {@code DataSource} 31 | */ 32 | DataSource getDataSource(); 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PrimaryHostDeterminer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection; 12 | 13 | /** 14 | * Represents a service that determines if a given database connection is established with a primary host. 15 | */ 16 | @FunctionalInterface 17 | public interface PrimaryHostDeterminer { 18 | 19 | /** 20 | * Determines whether given connection is a connection to a primary host. 21 | * 22 | * @param pgConnection {@code PgConnection} object 23 | * @return {@code true} if this is a connection to a primary host. 24 | */ 25 | boolean isPrimary(PgConnection pgConnection); 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/exception/PgSqlException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection.exception; 12 | 13 | import java.sql.SQLException; 14 | 15 | /** 16 | * Custom unchecked exception for SQL errors. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @since 0.5.0 20 | */ 21 | public class PgSqlException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = -8740709401886468019L; 24 | 25 | /** 26 | * Constructs a new {@code PgSqlException} with the specified cause. 27 | * 28 | * @param cause the {@link SQLException} that caused this exception; must not be {@code null}. 29 | */ 30 | public PgSqlException(final SQLException cause) { 31 | super(cause.getMessage(), cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Custom exceptions. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.connection.exception; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/PgConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection.factory; 12 | 13 | import io.github.mfvanek.pg.connection.PgConnection; 14 | 15 | import javax.sql.DataSource; 16 | 17 | public interface PgConnectionFactory { 18 | 19 | PgConnection forUrl(String pgUrl, String userName, String password); 20 | 21 | DataSource dataSourceFor(String pgUrl, String userName, String password); 22 | } 23 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/factory/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * PostgreSQL connection factory related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.connection.factory; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/host/HostAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.connection.host; 12 | 13 | /** 14 | * Allows getting information about database host. 15 | * 16 | * @author Ivan Vakhrushev 17 | */ 18 | public interface HostAware { 19 | 20 | /** 21 | * Retrieves information about host in the cluster. 22 | * 23 | * @return {@code PgHost} 24 | * @see PgHost 25 | */ 26 | PgHost getHost(); 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/host/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * PostgreSQL host related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.connection.host; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * PostgreSQL connection related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.connection; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-jdbc-connection/src/testFixtures/java/io/github/mfvanek/pg/connection/fixtures/support/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Connection testing utils. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.connection.fixtures.support; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-logger/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | } 4 | 5 | description = "pg-index-health-logger is a Java library for collecting and logging health state in PostgreSQL databases." 6 | 7 | dependencies { 8 | api(project(":pg-index-health-model")) 9 | api(project(":pg-index-health-jdbc-connection")) 10 | api(project(":pg-index-health-core")) 11 | api(project(":pg-index-health")) 12 | 13 | testImplementation(testFixtures(project(":pg-index-health-core"))) 14 | testImplementation("org.junit.jupiter:junit-jupiter-params") 15 | testImplementation("org.mockito:mockito-core") 16 | testImplementation(libs.postgresql) 17 | 18 | testCompileOnly(libs.forbiddenapis) 19 | } 20 | -------------------------------------------------------------------------------- /pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/LoggingKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.logger; 12 | 13 | /** 14 | * Represents a logging key with associated metadata. 15 | * 16 | * @author Ivan Vakhrushev 17 | */ 18 | @SuppressWarnings("WeakerAccess") 19 | public interface LoggingKey { 20 | 21 | /** 22 | * Gets the name of the key. 23 | * 24 | * @return the key name, never {@code null}. 25 | */ 26 | String getKeyName(); 27 | 28 | /** 29 | * Gets the name of the sub-key associated with this key. 30 | * 31 | * @return the sub-key name, never {@code null}. 32 | */ 33 | String getSubKeyName(); 34 | 35 | /** 36 | * Gets the description of this key. 37 | * 38 | * @return a description of the key, never {@code null}. 39 | */ 40 | String getDescription(); 41 | } 42 | -------------------------------------------------------------------------------- /pg-index-health-logger/src/main/java/io/github/mfvanek/pg/health/logger/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Database structure health data logging related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.health.logger; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | id("pg-index-health.pitest") 4 | } 5 | 6 | description = "pg-index-health-model is a set of common classes and interfaces for getting information about PostgreSQL database objects." 7 | 8 | dependencies { 9 | testImplementation(libs.equalsverifier) 10 | testImplementation("org.mockito:mockito-core") 11 | testImplementation("org.junit.jupiter:junit-jupiter-params") 12 | 13 | testFixturesImplementation(libs.jspecify) 14 | testFixturesCompileOnly(libs.forbiddenapis) 15 | } 16 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/bloat/BloatAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.bloat; 12 | 13 | /** 14 | * Allows getting information about bloat in database. 15 | * 16 | * @author Ivan Vakhrushev 17 | */ 18 | public interface BloatAware { 19 | 20 | /** 21 | * Retrieves bloat amount in bytes. 22 | * 23 | * @return bloat amount 24 | */ 25 | long getBloatSizeInBytes(); 26 | 27 | /** 28 | * Retrieves bloat percentage (in the range from 0 to 100 inclusive). 29 | * 30 | * @return bloat percentage 31 | */ 32 | double getBloatPercentage(); 33 | } 34 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/bloat/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Bloat related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.bloat; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/ColumnNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.column; 12 | 13 | import io.github.mfvanek.pg.model.table.TableNameAware; 14 | 15 | /** 16 | * Allows getting column name. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @see io.github.mfvanek.pg.model.table.TableNameAware 20 | * @since 0.6.2 21 | */ 22 | public interface ColumnNameAware extends TableNameAware { 23 | 24 | /** 25 | * Retrieves column name in the table. 26 | * 27 | * @return column name 28 | */ 29 | String getColumnName(); 30 | 31 | /** 32 | * Shows whether column can or cannot accept null values. 33 | * 34 | * @return true if column cannot accept null values 35 | */ 36 | boolean isNotNull(); 37 | 38 | /** 39 | * Shows whether column can accept null values. 40 | * 41 | * @return true if column can accept null values 42 | */ 43 | default boolean isNullable() { 44 | return !isNotNull(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/column/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Column related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.column; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.constraint; 12 | 13 | import io.github.mfvanek.pg.model.table.TableNameAware; 14 | 15 | /** 16 | * Represents an entity that is aware of a database constraint name. 17 | * Classes implementing this interface should provide the name of a specific database constraint. 18 | * 19 | * @author Ivan Vakhrushev 20 | * @since 0.13.3 21 | */ 22 | public interface ConstraintNameAware extends TableNameAware { 23 | 24 | /** 25 | * Retrieves the name of the database constraint associated with this entity. 26 | * 27 | * @return the name of the constraint as a non-null {@link String}. 28 | */ 29 | String getConstraintName(); 30 | 31 | /** 32 | * Retrieves type of constraint. 33 | * 34 | * @return type of constraint 35 | * @see ConstraintType 36 | * @since 0.15.0 37 | */ 38 | ConstraintType getConstraintType(); 39 | } 40 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/ConstraintsAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.constraint; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Represents an entity that is aware of database constraints. 17 | * Classes implementing this interface should provide access to a list of associated constraints. 18 | * 19 | * @author Ivan Vakhrushev 20 | * @since 0.13.3 21 | */ 22 | public interface ConstraintsAware { 23 | 24 | /** 25 | * Retrieves the list of database constraints associated with this entity. 26 | * 27 | * @return a list of {@link ConstraintNameAware} objects. The list may be empty but will never be {@code null}. 28 | */ 29 | List getConstraints(); 30 | } 31 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/constraint/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Constraint related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.constraint; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/context/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Context related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.context; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/dbobject/DbObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.dbobject; 12 | 13 | /** 14 | * A generalized representation of a database object. 15 | * Mostly used as a marker interface. 16 | * 17 | * @author Ivan Vakhrushev 18 | * @since 0.7.0 19 | */ 20 | public interface DbObject { 21 | 22 | /** 23 | * Retrieves database object name. 24 | * 25 | * @return database object name 26 | */ 27 | String getName(); 28 | 29 | /** 30 | * Retrieves database object type. 31 | * 32 | * @return database object type 33 | * @since 0.13.2 34 | */ 35 | PgObjectType getObjectType(); 36 | } 37 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/dbobject/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * General database object related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.dbobject; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/function/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Stored procedure/function related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.function; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.index; 12 | 13 | /** 14 | * Allows getting index name. 15 | * 16 | * @author Ivan Vakhrushev 17 | * @see io.github.mfvanek.pg.model.table.TableNameAware 18 | */ 19 | public interface IndexNameAware { 20 | 21 | /** 22 | * Retrieves index name. 23 | * 24 | * @return index name 25 | */ 26 | String getIndexName(); 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexSizeAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.index; 12 | 13 | import io.github.mfvanek.pg.model.table.TableSizeAware; 14 | 15 | /** 16 | * Allows getting index size in bytes. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @see TableSizeAware 20 | */ 21 | public interface IndexSizeAware extends IndexNameAware { 22 | 23 | /** 24 | * Retrieves index size in bytes. 25 | * 26 | * @return index size in bytes 27 | */ 28 | long getIndexSizeInBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/IndexesAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.index; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Represents an entity that is aware of and can provide a list of indexes. 17 | * Classes implementing this interface should return a list of objects that extend {@link Index}. 18 | * 19 | * @author Ivan Vakhrushev 20 | * @see Index 21 | * @since 0.13.3 22 | */ 23 | public interface IndexesAware { 24 | 25 | /** 26 | * Retrieves a list of indexes associated with this entity. 27 | * 28 | * @return a non-null list of {@link Index} or its subclasses. The list may be empty if no indexes are available. 29 | */ 30 | List getIndexes(); 31 | } 32 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An index related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.index; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/index/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An additional index related utilities. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.index.utils; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/predicates/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Set of classes for filtering {@link io.github.mfvanek.pg.model.dbobject.DbObject} instances. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.predicates; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/SequenceNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.sequence; 12 | 13 | /** 14 | * Represents an object that is aware of a database sequence name. 15 | * Classes implementing this interface provide a method to retrieve the name of a sequence. 16 | * 17 | * @author Ivan Vakhrushev 18 | * @since 0.13.3 19 | */ 20 | public interface SequenceNameAware { 21 | 22 | /** 23 | * Retrieves the name of the sequence associated with the implementing object. 24 | * 25 | * @return the name of the sequence, never null 26 | */ 27 | String getSequenceName(); 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/sequence/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Sequence related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.sequence; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/ParamNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.settings; 12 | 13 | /** 14 | * Represents an entity that is aware of its parameter name. 15 | */ 16 | public interface ParamNameAware { 17 | 18 | /** 19 | * Retrieves the name of the parameter. 20 | * 21 | * @return the name of the parameter, never {@code null} 22 | */ 23 | String getName(); 24 | } 25 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Settings related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.settings; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/validation/ParamValidators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.settings.validation; 12 | 13 | import java.util.Objects; 14 | 15 | /** 16 | * Utility class for validating PostgreSQL parameter values. 17 | */ 18 | public final class ParamValidators { 19 | 20 | private ParamValidators() { 21 | throw new UnsupportedOperationException(); 22 | } 23 | 24 | /** 25 | * Validates that the given parameter value is not {@code null}, and returns the trimmed value. 26 | * 27 | * @param value the parameter value to check 28 | * @param message the exception message if the value is {@code null} 29 | * @return the trimmed, non-null parameter value 30 | * @throws NullPointerException if {@code value} is {@code null} 31 | */ 32 | public static String paramValueNotNull(final String value, final String message) { 33 | return Objects.requireNonNull(value, message).trim(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/settings/validation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An additional validation methods related to database parameters. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.settings.validation; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableNameAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.table; 12 | 13 | /** 14 | * Allows getting table name. 15 | * 16 | * @author Ivan Vakhrushev 17 | * @see io.github.mfvanek.pg.model.index.IndexNameAware 18 | */ 19 | public interface TableNameAware { 20 | 21 | /** 22 | * Retrieves table name. 23 | * 24 | * @return table name 25 | */ 26 | String getTableName(); 27 | } 28 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/TableSizeAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.table; 12 | 13 | import io.github.mfvanek.pg.model.index.IndexSizeAware; 14 | 15 | /** 16 | * Allows getting table size in bytes. 17 | * 18 | * @author Ivan Vakhrushev 19 | * @see IndexSizeAware 20 | */ 21 | public interface TableSizeAware extends TableNameAware { 22 | 23 | /** 24 | * Retrieves table size in bytes. 25 | * 26 | * @return table size in bytes 27 | */ 28 | long getTableSizeInBytes(); 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/table/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Table related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.table; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/units/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Units of information for pg-index-health models. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.units; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/main/java/io/github/mfvanek/pg/model/validation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Various validation methods for pg-index-health models. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.validation; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-model/src/test/java/io/github/mfvanek/pg/model/units/MemoryUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.units; 12 | 13 | import org.junit.jupiter.api.Test; 14 | 15 | import static org.assertj.core.api.Assertions.assertThat; 16 | 17 | class MemoryUnitTest { 18 | 19 | @Test 20 | void convertToBytes() { 21 | assertThat(MemoryUnit.KB.convertToBytes(1)).isEqualTo(1_024L); 22 | assertThat(MemoryUnit.MB.convertToBytes(2)).isEqualTo(2_097_152L); 23 | assertThat(MemoryUnit.GB.convertToBytes(3)).isEqualTo(3_221_225_472L); 24 | } 25 | 26 | @Test 27 | void toStringTest() { 28 | assertThat(MemoryUnit.MB) 29 | .hasToString("MemoryUnit{dimension=1048576, description='megabyte'}"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pg-index-health-model/src/testFixtures/java/io/github/mfvanek/pg/model/fixtures/support/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.model.fixtures.support; 12 | 13 | import de.thetaphi.forbiddenapis.SuppressForbidden; 14 | 15 | import java.lang.reflect.Constructor; 16 | import java.lang.reflect.InvocationTargetException; 17 | 18 | public final class TestUtils { 19 | 20 | private TestUtils() { 21 | throw new UnsupportedOperationException(); 22 | } 23 | 24 | @SuppressWarnings("checkstyle:IllegalThrows") 25 | @SuppressForbidden 26 | public static void invokePrivateConstructor(final Class type) 27 | throws Throwable { 28 | final Constructor constructor = type.getDeclaredConstructor(); 29 | constructor.setAccessible(true); 30 | 31 | try { 32 | constructor.newInstance(); 33 | } catch (InvocationTargetException ex) { 34 | throw ex.getTargetException(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pg-index-health-model/src/testFixtures/java/io/github/mfvanek/pg/model/fixtures/support/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Models testing utils. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.model.fixtures.support; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-testing/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("pg-index-health.java-library") 3 | } 4 | 5 | description = "pg-index-health-testing is an auxiliary library that allows you to run a PostgreSQL cluster in tests." 6 | 7 | dependencies { 8 | api(project(":pg-index-health-model")) 9 | api(project(":pg-index-health-jdbc-connection")) 10 | implementation(libs.apache.commons.dbcp2) 11 | implementation(platform(libs.testcontainers.bom)) 12 | implementation("org.testcontainers:testcontainers") 13 | implementation("org.testcontainers:postgresql") 14 | implementation(libs.awaitility) 15 | 16 | testImplementation(testFixtures(project(":pg-index-health-model"))) 17 | testImplementation(testFixtures(project(":pg-index-health-jdbc-connection"))) 18 | testImplementation("org.mockito:mockito-core") 19 | testRuntimeOnly(libs.postgresql) 20 | } 21 | 22 | tasks { 23 | test { 24 | maxParallelForks = 1 // to increase tests stability 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/PostgreSqlDataSourceHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.testing; 12 | 13 | import org.apache.commons.dbcp2.BasicDataSource; 14 | import org.testcontainers.containers.JdbcDatabaseContainer; 15 | 16 | /** 17 | * Builder for DataSource. 18 | * 19 | * @author Ivan Vakhrushev 20 | * @since 0.6.2 21 | */ 22 | final class PostgreSqlDataSourceHelper { 23 | 24 | private PostgreSqlDataSourceHelper() { 25 | throw new UnsupportedOperationException(); 26 | } 27 | 28 | static BasicDataSource buildDataSource(final JdbcDatabaseContainer container) { 29 | final BasicDataSource basicDataSource = new BasicDataSource(); 30 | basicDataSource.setUrl(container.getJdbcUrl()); 31 | basicDataSource.setUsername(container.getUsername()); 32 | basicDataSource.setPassword(container.getPassword()); 33 | basicDataSource.setDriverClassName(container.getDriverClassName()); 34 | return basicDataSource; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/annotations/ExcludeFromJacocoGeneratedReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.testing.annotations; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * Custom annotation to exclude some methods from Jacoco code coverage report. 20 | * See issue 21 | */ 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target(ElementType.METHOD) 24 | public @interface ExcludeFromJacocoGeneratedReport { 25 | } 26 | -------------------------------------------------------------------------------- /pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An additional testing classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.testing.annotations; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health-testing/src/main/java/io/github/mfvanek/pg/testing/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Custom PostgreSQL container for testing in cluster environment. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.testing; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/BtreeIndexesOnArrayColumnsCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.BtreeIndexesOnArrayColumnsCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.IndexWithColumns; 16 | 17 | /** 18 | * Check for B-tree indexes on array columns on all hosts in the cluster. 19 | * GIN-index should be used instead for such columns. 20 | * 21 | * @author Vadim Khizhin 22 | * @since 0.11.0 23 | */ 24 | public class BtreeIndexesOnArrayColumnsCheckOnCluster extends AbstractCheckOnCluster { 25 | 26 | public BtreeIndexesOnArrayColumnsCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 27 | super(haPgConnection, BtreeIndexesOnArrayColumnsCheckOnHost::new); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithFixedLengthVarcharCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.ColumnsWithFixedLengthVarcharCheckOnHost; 15 | import io.github.mfvanek.pg.model.column.Column; 16 | 17 | /** 18 | * Check for columns with fixed length varchar type on all hosts in the cluster. 19 | * 20 | * @author Diana Gilfanova 21 | * @since 0.14.6 22 | */ 23 | public class ColumnsWithFixedLengthVarcharCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public ColumnsWithFixedLengthVarcharCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, ColumnsWithFixedLengthVarcharCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithJsonTypeCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.ColumnsWithJsonTypeCheckOnHost; 15 | import io.github.mfvanek.pg.model.column.Column; 16 | 17 | /** 18 | * Check for columns with {@code json} type on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.1 22 | */ 23 | public class ColumnsWithJsonTypeCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public ColumnsWithJsonTypeCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, ColumnsWithJsonTypeCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithSerialTypesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.ColumnsWithSerialTypesCheckOnHost; 15 | import io.github.mfvanek.pg.model.column.ColumnWithSerialType; 16 | 17 | /** 18 | * Check for columns of serial types that are not primary keys on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.2 22 | */ 23 | public class ColumnsWithSerialTypesCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public ColumnsWithSerialTypesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, ColumnsWithSerialTypesCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/ColumnsWithoutDescriptionCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.ColumnsWithoutDescriptionCheckOnHost; 15 | import io.github.mfvanek.pg.model.column.Column; 16 | 17 | /** 18 | * Check for columns without description on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class ColumnsWithoutDescriptionCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public ColumnsWithoutDescriptionCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, ColumnsWithoutDescriptionCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedForeignKeysCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.DuplicatedForeignKeysCheckOnHost; 15 | import io.github.mfvanek.pg.model.constraint.DuplicatedForeignKeys; 16 | 17 | /** 18 | * Check for duplicated (completely identical) foreign keys on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.13.1 22 | */ 23 | public class DuplicatedForeignKeysCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public DuplicatedForeignKeysCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, DuplicatedForeignKeysCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/DuplicatedIndexesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.DuplicatedIndexesCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.DuplicatedIndexes; 16 | 17 | /** 18 | * Check for duplicated (completely identical) indexes on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class DuplicatedIndexesCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public DuplicatedIndexesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, DuplicatedIndexesCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/ForeignKeysNotCoveredWithIndexCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.ForeignKeysNotCoveredWithIndexCheckOnHost; 15 | import io.github.mfvanek.pg.model.constraint.ForeignKey; 16 | 17 | /** 18 | * Check for foreign keys without associated indexes on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class ForeignKeysNotCoveredWithIndexCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public ForeignKeysNotCoveredWithIndexCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, ForeignKeysNotCoveredWithIndexCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/FunctionsWithoutDescriptionCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.FunctionsWithoutDescriptionCheckOnHost; 15 | import io.github.mfvanek.pg.model.function.StoredFunction; 16 | 17 | /** 18 | * Check for procedures/functions without description on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.7.0 22 | */ 23 | public class FunctionsWithoutDescriptionCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public FunctionsWithoutDescriptionCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, FunctionsWithoutDescriptionCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBloatCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IndexesWithBloatCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.IndexWithBloat; 16 | 17 | /** 18 | * Check for indexes bloat on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class IndexesWithBloatCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IndexesWithBloatCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IndexesWithBloatCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithBooleanCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IndexesWithBooleanCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.IndexWithColumns; 16 | 17 | /** 18 | * Check for indexes that contain boolean values on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.11.0 22 | */ 23 | public class IndexesWithBooleanCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IndexesWithBooleanCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IndexesWithBooleanCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithNullValuesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IndexesWithNullValuesCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.IndexWithColumns; 16 | 17 | /** 18 | * Check for indexes with null values on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class IndexesWithNullValuesCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IndexesWithNullValuesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IndexesWithNullValuesCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IndexesWithUnnecessaryWhereClauseCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IndexesWithUnnecessaryWhereClauseCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.IndexWithColumns; 16 | 17 | /** 18 | * Check for indexes with unnecessary where-clause on not null column on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.14.6 22 | */ 23 | public class IndexesWithUnnecessaryWhereClauseCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IndexesWithUnnecessaryWhereClauseCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IndexesWithUnnecessaryWhereClauseCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedForeignKeysCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IntersectedForeignKeysCheckOnHost; 15 | import io.github.mfvanek.pg.model.constraint.DuplicatedForeignKeys; 16 | 17 | /** 18 | * Check for intersected (partially identical) foreign keys on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.13.1 22 | */ 23 | public class IntersectedForeignKeysCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IntersectedForeignKeysCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IntersectedForeignKeysCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/IntersectedIndexesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.IntersectedIndexesCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.DuplicatedIndexes; 16 | 17 | /** 18 | * Check for intersected (partially identical) indexes on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class IntersectedIndexesCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public IntersectedIndexesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, IntersectedIndexesCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/InvalidIndexesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.InvalidIndexesCheckOnHost; 15 | import io.github.mfvanek.pg.model.index.Index; 16 | 17 | /** 18 | * Check for invalid (broken) indexes on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class InvalidIndexesCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public InvalidIndexesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, InvalidIndexesCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/NotValidConstraintsCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.NotValidConstraintsCheckOnHost; 15 | import io.github.mfvanek.pg.model.constraint.Constraint; 16 | 17 | /** 18 | * Check for not valid constraint on all hosts in the cluster. 19 | * 20 | * @author Blohny 21 | * @since 0.11.0 22 | */ 23 | public class NotValidConstraintsCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public NotValidConstraintsCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, NotValidConstraintsCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/PossibleObjectNameOverflowCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.PossibleObjectNameOverflowCheckOnHost; 15 | import io.github.mfvanek.pg.model.dbobject.AnyObject; 16 | 17 | /** 18 | * Check for objects whose names have a length of {@code max_identifier_length} (usually it is 63) on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @see PostgreSQL Limits 22 | * @since 0.13.2 23 | */ 24 | public class PossibleObjectNameOverflowCheckOnCluster extends AbstractCheckOnCluster { 25 | 26 | public PossibleObjectNameOverflowCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 27 | super(haPgConnection, PossibleObjectNameOverflowCheckOnHost::new); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/PrimaryKeysWithSerialTypesCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.PrimaryKeysWithSerialTypesCheckOnHost; 15 | import io.github.mfvanek.pg.model.column.ColumnWithSerialType; 16 | 17 | /** 18 | * Check for primary keys columns with serial types (smallserial/serial/bigserial) on all hosts in the cluster. 19 | * New "generated as identity" syntax should be used instead. 20 | * 21 | * @author Vadim Khizhin 22 | * @since 0.13.0 23 | */ 24 | public class PrimaryKeysWithSerialTypesCheckOnCluster extends AbstractCheckOnCluster { 25 | 26 | public PrimaryKeysWithSerialTypesCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 27 | super(haPgConnection, PrimaryKeysWithSerialTypesCheckOnHost::new); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/SequenceOverflowCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.SequenceOverflowCheckOnHost; 15 | import io.github.mfvanek.pg.model.sequence.SequenceState; 16 | 17 | /** 18 | * Check for sequence overflow on all hosts in the cluster. 19 | * 20 | * @author Blohny 21 | * @since 0.12.0 22 | */ 23 | public class SequenceOverflowCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public SequenceOverflowCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, SequenceOverflowCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/TablesNotLinkedToOthersCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.TablesNotLinkedToOthersCheckOnHost; 15 | import io.github.mfvanek.pg.model.table.Table; 16 | 17 | /** 18 | * Check for tables that are not linked to other tables on all hosts in the cluster. 19 | *

20 | * These are often service tables that are not part of the project, or 21 | * tables that are no longer in use or were created by mistake, but were not deleted in a timely manner. 22 | * 23 | * @author Ivan Vakhrushev 24 | * @since 0.13.2 25 | */ 26 | public class TablesNotLinkedToOthersCheckOnCluster extends AbstractCheckOnCluster { 27 | 28 | public TablesNotLinkedToOthersCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 29 | super(haPgConnection, TablesNotLinkedToOthersCheckOnHost::new); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithBloatCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.TablesWithBloatCheckOnHost; 15 | import io.github.mfvanek.pg.model.table.TableWithBloat; 16 | 17 | /** 18 | * Check for tables bloat on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class TablesWithBloatCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public TablesWithBloatCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, TablesWithBloatCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithZeroOrOneColumnCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.TablesWithZeroOrOneColumnCheckOnHost; 15 | import io.github.mfvanek.pg.model.table.TableWithColumns; 16 | 17 | /** 18 | * Check for tables with zero or one column on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.14.6 22 | */ 23 | public class TablesWithZeroOrOneColumnCheckOnCluster extends AbstractCheckOnCluster { 24 | 25 | public TablesWithZeroOrOneColumnCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, TablesWithZeroOrOneColumnCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutDescriptionCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.TablesWithoutDescriptionCheckOnHost; 15 | import io.github.mfvanek.pg.model.table.Table; 16 | 17 | /** 18 | * Check for tables without description on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class TablesWithoutDescriptionCheckOnCluster extends AbstractCheckOnCluster
{ 24 | 25 | public TablesWithoutDescriptionCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, TablesWithoutDescriptionCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/TablesWithoutPrimaryKeyCheckOnCluster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.health.checks.cluster; 12 | 13 | import io.github.mfvanek.pg.connection.HighAvailabilityPgConnection; 14 | import io.github.mfvanek.pg.core.checks.host.TablesWithoutPrimaryKeyCheckOnHost; 15 | import io.github.mfvanek.pg.model.table.Table; 16 | 17 | /** 18 | * Check for tables without primary key on all hosts in the cluster. 19 | * 20 | * @author Ivan Vakhrushev 21 | * @since 0.6.0 22 | */ 23 | public class TablesWithoutPrimaryKeyCheckOnCluster extends AbstractCheckOnCluster
{ 24 | 25 | public TablesWithoutPrimaryKeyCheckOnCluster(final HighAvailabilityPgConnection haPgConnection) { 26 | super(haPgConnection, TablesWithoutPrimaryKeyCheckOnHost::new); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/cluster/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Checks on cluster related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.health.checks.cluster; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/common/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Common checks on cluster related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.health.checks.common; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/checks/management/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Database management related classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.health.checks.management; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /pg-index-health/src/main/java/io/github/mfvanek/pg/health/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * An additional util classes and interfaces. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.health.utils; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /spring-boot-integration/console-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | } 16 | 17 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 18 | ext["assertj.version"] = libs.versions.assertj.get() 19 | ext["junit-jupiter.version"] = libs.versions.junit.get() 20 | 21 | dependencies { 22 | implementation(libs.spring.boot.starter.root) 23 | 24 | testImplementation(libs.spring.boot.starter.test) 25 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-integration/console-demo-app/src/main/java/io/github/mfvanek/pg/spring/console/ConsoleDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.console; 12 | 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.boot.CommandLineRunner; 16 | import org.springframework.boot.SpringApplication; 17 | import org.springframework.boot.autoconfigure.SpringBootApplication; 18 | 19 | @SpringBootApplication 20 | public class ConsoleDemoApplication implements CommandLineRunner { 21 | 22 | private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleDemoApplication.class); 23 | 24 | public static void main(final String[] args) { 25 | SpringApplication.run(ConsoleDemoApplication.class, args); 26 | } 27 | 28 | @Override 29 | public void run(final String... args) { 30 | LOGGER.info("Executing: command line runner"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-integration/console-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | -------------------------------------------------------------------------------- /spring-boot-integration/console-demo-app/src/test/java/io/github/mfvanek/pg/spring/console/ConsoleDemoApplicationRunTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.console; 12 | 13 | import org.junit.jupiter.api.Test; 14 | import org.junit.jupiter.api.extension.ExtendWith; 15 | import org.springframework.boot.test.system.CapturedOutput; 16 | import org.springframework.boot.test.system.OutputCaptureExtension; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.assertj.core.api.Assertions.assertThatCode; 20 | 21 | @ExtendWith(OutputCaptureExtension.class) 22 | class ConsoleDemoApplicationRunTest { 23 | 24 | @Test 25 | void applicationShouldRun(final CapturedOutput output) { 26 | assertThatCode(() -> ConsoleDemoApplication.main(new String[]{})) 27 | .doesNotThrowAnyException(); 28 | assertThat(output.getAll()) 29 | .contains("Starting ConsoleDemoApplication using Java") 30 | .contains("Started ConsoleDemoApplication in"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-integration/console-demo-app/src/test/java/io/github/mfvanek/pg/spring/console/ConsoleDemoApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.console; 12 | 13 | import org.junit.jupiter.api.Test; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 17 | import org.springframework.context.ApplicationContext; 18 | import org.springframework.test.context.ActiveProfiles; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | @ActiveProfiles("test") 23 | @SpringBootTest(webEnvironment = WebEnvironment.NONE) 24 | class ConsoleDemoApplicationTest { 25 | 26 | @Autowired 27 | private ApplicationContext context; 28 | 29 | @Test 30 | void contextLoads() { 31 | assertThat(context.containsBean("dataSource")) 32 | .isFalse(); 33 | assertThat(context.containsBean("pgConnection")) 34 | .isFalse(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-integration/h2-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | } 16 | 17 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 18 | ext["assertj.version"] = libs.versions.assertj.get() 19 | ext["junit-jupiter.version"] = libs.versions.junit.get() 20 | 21 | dependencies { 22 | implementation(libs.spring.boot.starter.data.jdbc) 23 | 24 | runtimeOnly("com.h2database:h2") 25 | 26 | testImplementation(libs.spring.boot.starter.test) 27 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-integration/h2-demo-app/src/main/java/io/github/mfvanek/pg/spring/h2/H2DemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.h2; 12 | 13 | import org.springframework.boot.SpringApplication; 14 | import org.springframework.boot.autoconfigure.SpringBootApplication; 15 | 16 | @SpringBootApplication 17 | public class H2DemoApplication { 18 | 19 | /** 20 | * Demo application with H2 datasource and without PostgreSQL. 21 | */ 22 | public static void main(final String[] args) { 23 | SpringApplication.run(H2DemoApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-integration/h2-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | -------------------------------------------------------------------------------- /spring-boot-integration/h2-demo-app/src/test/java/io/github/mfvanek/pg/spring/h2/H2DemoApplicationRunTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.h2; 12 | 13 | import org.junit.jupiter.api.Test; 14 | import org.junit.jupiter.api.extension.ExtendWith; 15 | import org.springframework.boot.test.system.CapturedOutput; 16 | import org.springframework.boot.test.system.OutputCaptureExtension; 17 | 18 | import static org.assertj.core.api.Assertions.assertThat; 19 | import static org.assertj.core.api.Assertions.assertThatCode; 20 | 21 | @ExtendWith(OutputCaptureExtension.class) 22 | class H2DemoApplicationRunTest { 23 | 24 | @Test 25 | void applicationShouldRun(final CapturedOutput output) { 26 | assertThatCode(() -> H2DemoApplication.main(new String[]{})) 27 | .doesNotThrowAnyException(); 28 | assertThat(output.getAll()) 29 | .contains("Starting H2DemoApplication using Java") 30 | .contains("Started H2DemoApplication in"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-integration/h2-demo-app/src/test/java/io/github/mfvanek/pg/spring/h2/H2DemoApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.h2; 12 | 13 | import org.junit.jupiter.api.Test; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.context.ApplicationContext; 17 | import org.springframework.test.context.ActiveProfiles; 18 | 19 | import javax.sql.DataSource; 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | 23 | @SpringBootTest 24 | @ActiveProfiles("test") 25 | class H2DemoApplicationTest { 26 | 27 | @Autowired 28 | private ApplicationContext applicationContext; 29 | 30 | @Test 31 | void contextLoadsAndDoesNotContainPgIndexHealthBeans() { 32 | assertThat(applicationContext.getBean("dataSource")) 33 | .isInstanceOf(DataSource.class); 34 | 35 | assertThat(applicationContext.containsBean("pgConnection")) 36 | .isFalse(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.kotlin-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | } 16 | 17 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 18 | ext["assertj.version"] = libs.versions.assertj.get() 19 | ext["junit-jupiter.version"] = libs.versions.junit.get() 20 | 21 | dependencies { 22 | implementation(platform(libs.testcontainers.bom)) 23 | implementation("org.testcontainers:postgresql") 24 | implementation(libs.spring.boot.starter.data.jdbc) 25 | implementation(libs.liquibase.core) 26 | implementation(libs.liquibase.sessionlock) 27 | 28 | runtimeOnly(libs.postgresql) 29 | 30 | testImplementation(libs.spring.boot.starter.test) 31 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/main/kotlin/io/github/mfvanek/pg/spring/postgres/kt/custom/ds/PostgresCustomDataSourceDemoApplication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.postgres.kt.custom.ds 12 | 13 | import org.springframework.boot.autoconfigure.SpringBootApplication 14 | import org.springframework.boot.runApplication 15 | 16 | @SpringBootApplication 17 | class PostgresCustomDataSourceDemoApplication 18 | 19 | fun main(args: Array) { 20 | runApplication(*args) 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | liquibase: 7 | change-log: classpath:/changelog/changelog.yaml 8 | default-schema: custom_ds_schema 9 | 10 | pgih: 11 | custom: 12 | datasource: 13 | jdbc-url: jdbc:tc:postgresql:17.4:///demo_for_pg_index_health_starter?TC_INITSCRIPT=init.sql 14 | driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver 15 | maximum-pool-size: 5 16 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/main/resources/changelog/changelog.yaml: -------------------------------------------------------------------------------- 1 | databaseChangeLog: 2 | - include: 3 | file: changelog/sql/warehouse.sql 4 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/main/resources/changelog/sql/warehouse.sql: -------------------------------------------------------------------------------- 1 | --liquibase formatted sql 2 | 3 | --changeset ivan.vakhrushev:2024.12.04:warehouse.table 4 | create table if not exists warehouse 5 | ( 6 | id bigint primary key generated always as identity, 7 | name text not null 8 | ); 9 | 10 | comment on table warehouse is 'Information about the warehouses'; 11 | comment on column warehouse.id is 'Unique identifier of the warehouse'; 12 | comment on column warehouse.name is 'Human readable name of the warehouse'; 13 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/main/resources/init.sql: -------------------------------------------------------------------------------- 1 | create schema if not exists custom_ds_schema; 2 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-custom-ds-demo-app/src/test/resources/application-test.yaml: -------------------------------------------------------------------------------- 1 | pg.index.health.test: 2 | datasource-bean-name: pgihCustomDataSource 3 | datasource-url-property-name: pgih.custom.datasource.jdbc-url 4 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.kotlin-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | } 16 | 17 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 18 | ext["assertj.version"] = libs.versions.assertj.get() 19 | ext["junit-jupiter.version"] = libs.versions.junit.get() 20 | 21 | dependencies { 22 | implementation(project(":pg-index-health-testing")) 23 | implementation(libs.spring.boot.starter.data.jdbc) 24 | implementation(platform(libs.testcontainers.bom)) 25 | implementation("org.testcontainers:postgresql") 26 | 27 | runtimeOnly(libs.postgresql) 28 | 29 | testImplementation(libs.spring.boot.starter.test) 30 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-demo-app/src/main/kotlin/io/github/mfvanek/pg/spring/postgres/kt/PostgresDemoApplication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.postgres.kt 12 | 13 | import org.springframework.boot.autoconfigure.SpringBootApplication 14 | import org.springframework.boot.runApplication 15 | 16 | @SpringBootApplication 17 | class PostgresDemoApplication 18 | 19 | fun main(args: Array) { 20 | runApplication(*args) 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-integration/kotlin-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | -------------------------------------------------------------------------------- /spring-boot-integration/pg-index-health-test-starter/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-library") 13 | id("pg-index-health.pitest") 14 | } 15 | 16 | description = "Spring Boot Starter for pg-index-health-core library" 17 | 18 | dependencies { 19 | api(project(":pg-index-health-model")) 20 | api(project(":pg-index-health-jdbc-connection")) 21 | api(project(":pg-index-health-core")) 22 | implementation(libs.spring.boot.starter.root) 23 | annotationProcessor(libs.spring.boot.autoconfigure.processor) 24 | annotationProcessor(libs.spring.boot.configuration.processor) 25 | 26 | testImplementation(libs.spring.boot.starter.test) 27 | testImplementation(libs.apache.commons.lang3) 28 | testImplementation(libs.postgresql) 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | /** 12 | * Spring Boot Starter for pg-index-health-core library. 13 | */ 14 | @NullMarked 15 | package io.github.mfvanek.pg.spring; 16 | 17 | import org.jspecify.annotations.NullMarked; 18 | -------------------------------------------------------------------------------- /spring-boot-integration/pg-index-health-test-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | io.github.mfvanek.pg.spring.DatabaseStructureHealthAutoConfiguration 2 | io.github.mfvanek.pg.spring.DatabaseStructureChecksAutoConfiguration 3 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | id("io.freefair.lombok") version "8.13.1" 16 | } 17 | 18 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 19 | ext["assertj.version"] = libs.versions.assertj.get() 20 | ext["junit-jupiter.version"] = libs.versions.junit.get() 21 | 22 | dependencies { 23 | implementation(project(":pg-index-health-testing")) 24 | implementation(libs.spring.boot.starter.data.jdbc) 25 | implementation(platform(libs.testcontainers.bom)) 26 | implementation("org.testcontainers:postgresql") 27 | implementation(libs.liquibase.core) 28 | implementation(libs.liquibase.sessionlock) 29 | 30 | runtimeOnly(libs.postgresql) 31 | 32 | testImplementation(libs.spring.boot.starter.test) 33 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/src/main/java/io/github/mfvanek/pg/spring/postgres/with/custom/user/PostgresWithCustomUserDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.postgres.with.custom.user; 12 | 13 | import org.springframework.boot.SpringApplication; 14 | import org.springframework.boot.autoconfigure.SpringBootApplication; 15 | 16 | @SpringBootApplication 17 | public class PostgresWithCustomUserDemoApplication { 18 | 19 | /** 20 | * Demo application with PostgreSQL datasource. 21 | */ 22 | public static void main(final String[] args) { 23 | SpringApplication.run(PostgresWithCustomUserDemoApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | datasource: 5 | # see resources/init.sql 6 | username: custom_user 7 | password: customUserPassword 8 | main: 9 | banner-mode: off 10 | liquibase: 11 | change-log: classpath:/changelog/changelog.yaml 12 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/src/main/resources/changelog/changelog.yaml: -------------------------------------------------------------------------------- 1 | databaseChangeLog: 2 | - include: 3 | file: changelog/sql/warehouse.sql 4 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/src/main/resources/changelog/sql/warehouse.sql: -------------------------------------------------------------------------------- 1 | --liquibase formatted sql 2 | 3 | --changeset ivan.vakhrushev:2024.12.09:warehouse.table 4 | create table if not exists warehouse 5 | ( 6 | id bigserial primary key, 7 | name text not null 8 | ); 9 | 10 | comment on table warehouse is 'Information about the warehouses'; 11 | comment on column warehouse.id is 'Unique identifier of the warehouse'; 12 | comment on column warehouse.name is 'Human readable name of the warehouse'; 13 | 14 | --changeset ivan.vakhrushev:2024.12.09:warehouse.initial.data 15 | insert into warehouse (name) 16 | select string_agg(substr(md5(random()::text), 1, 8), '') 17 | from generate_series(1, 400); 18 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app-with-custom-user/src/main/resources/init.sql: -------------------------------------------------------------------------------- 1 | create schema if not exists main_schema authorization main_user; 2 | create schema if not exists additional_schema authorization pg_monitor; 3 | 4 | create user custom_user with nosuperuser nocreatedb nocreaterole password 'customUserPassword' connection limit 10; 5 | grant usage on schema main_schema to custom_user; 6 | 7 | create table if not exists additional_schema.additional_table ( 8 | id bigserial primary key, 9 | name text not null 10 | ); 11 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | id("io.freefair.lombok") version "8.13.1" 16 | } 17 | 18 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 19 | ext["assertj.version"] = libs.versions.assertj.get() 20 | ext["junit-jupiter.version"] = libs.versions.junit.get() 21 | 22 | dependencies { 23 | implementation(project(":pg-index-health-testing")) 24 | implementation(libs.spring.boot.starter.data.jdbc) 25 | implementation(platform(libs.testcontainers.bom)) 26 | implementation("org.testcontainers:postgresql") 27 | 28 | runtimeOnly(libs.postgresql) 29 | 30 | testImplementation(libs.spring.boot.starter.test) 31 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 32 | } 33 | 34 | lombok { 35 | version = "1.18.38" 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app/lombok.config: -------------------------------------------------------------------------------- 1 | # https://projectlombok.org/features/configuration 2 | config.stopBubbling = true 3 | lombok.addLombokGeneratedAnnotation = true 4 | lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value 5 | lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier 6 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app/src/main/java/io/github/mfvanek/pg/spring/postgres/PostgresDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.postgres; 12 | 13 | import org.springframework.boot.SpringApplication; 14 | import org.springframework.boot.autoconfigure.SpringBootApplication; 15 | 16 | @SpringBootApplication 17 | public class PostgresDemoApplication { 18 | 19 | /** 20 | * Demo application with PostgreSQL datasource. 21 | */ 22 | public static void main(final String[] args) { 23 | SpringApplication.run(PostgresDemoApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-tc-url-demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | plugins { 12 | id("pg-index-health.java-application") 13 | alias(libs.plugins.spring.boot.gradlePlugin) 14 | alias(libs.plugins.spring.dependency.management) 15 | } 16 | 17 | ext["commons-lang3.version"] = libs.versions.commons.lang3.get() 18 | ext["assertj.version"] = libs.versions.assertj.get() 19 | ext["junit-jupiter.version"] = libs.versions.junit.get() 20 | 21 | dependencies { 22 | implementation(platform(libs.testcontainers.bom)) 23 | implementation("org.testcontainers:postgresql") 24 | implementation(libs.spring.boot.starter.data.jdbc) 25 | 26 | runtimeOnly(libs.postgresql) 27 | 28 | testImplementation(libs.spring.boot.starter.test) 29 | testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-tc-url-demo-app/src/main/java/io/github/mfvanek/pg/spring/postgres/tc/url/PostgresTestcontainersUrlDemoApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2025. Ivan Vakhrushev and others. 3 | * https://github.com/mfvanek/pg-index-health 4 | * 5 | * This file is a part of "pg-index-health" - a Java library for 6 | * analyzing and maintaining indexes health in PostgreSQL databases. 7 | * 8 | * Licensed under the Apache License 2.0 9 | */ 10 | 11 | package io.github.mfvanek.pg.spring.postgres.tc.url; 12 | 13 | import org.springframework.boot.SpringApplication; 14 | import org.springframework.boot.autoconfigure.SpringBootApplication; 15 | 16 | @SpringBootApplication 17 | public class PostgresTestcontainersUrlDemoApplication { 18 | 19 | /** 20 | * Demo application with PostgreSQL datasource. 21 | */ 22 | public static void main(final String[] args) { 23 | SpringApplication.run(PostgresTestcontainersUrlDemoApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-integration/postgres-tc-url-demo-app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | debug: false 2 | 3 | spring: 4 | main: 5 | banner-mode: off 6 | datasource: 7 | url: jdbc:tc:postgresql:17.4:///demo_for_pg_index_health_starter 8 | driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver 9 | 10 | logging: 11 | level: 12 | root: info 13 | io.github.mfvanek.pg.core.utils.QueryExecutors: trace 14 | -------------------------------------------------------------------------------- /сopyright.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019-$today.year. Ivan Vakhrushev and others. 2 | https://github.com/mfvanek/pg-index-health 3 | 4 | This file is a part of "pg-index-health" - a Java library for 5 | analyzing and maintaining indexes health in PostgreSQL databases. 6 | 7 | Licensed under the Apache License 2.0 8 | --------------------------------------------------------------------------------