Top Description Fields Constructors Methods
liquibase.database.core

public Class PostgresDatabase

extends AbstractJdbcDatabase
Class Inheritance
Known Direct Subclasses
liquibase.database.core.CockroachDatabase, liquibase.database.core.EnterpriseDBDatabase
Imports
liquibase.CatalogAndSchema, .GlobalConfiguration, .Scope, liquibase.changelog.column.LiquibaseColumn, liquibase.database.AbstractJdbcDatabase, .DatabaseConnection, .ObjectQuotingStrategy, liquibase.database.jvm.JdbcConnection, liquibase.exception.DatabaseException, liquibase.logging.Logger, liquibase.statement.SqlStatement, liquibase.statement.core.RawCallStatement, liquibase.structure.DatabaseObject, liquibase.structure.core.Schema, .Table, liquibase.util.JdbcUtil, .StringUtil, java.math.BigInteger, java.nio.charset.Charset, java.sql.ResultSet, .SQLException, .Statement, java.util.*

Encapsulates PostgreSQL database support.

Field Summary

Modifier and TypeField and Description
private static final String
private static final Logger
public static final int
public static final int
private static final int
pack-priv static final int
PGSQL_PK_BYTES_LIMIT

Maximum length of PostgresSQL identifier.

pack-priv static final String
public static final String
private final Set<String>
private final Set<String>
public static final List<String>
VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMES

The data type names which are valid for auto-increment columns.

Inherited from liquibase.database.AbstractJdbcDatabase:
caseSensitivecurrentDateTimeFunctiondateFunctionsdefaultAutoIncrementBydefaultAutoIncrementStartWithdefaultCatalogNamedefaultSchemaNamequotingStrategysequenceCurrentValueFunctionsequenceNextValueFunctionunmodifiableDataTypesunquotedObjectsAreUppercased

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
correctObjectName(String objectName, Class<? extends DatabaseObject> objectType)

Overrides liquibase.database.AbstractJdbcDatabase.correctObjectName.

Implements liquibase.database.Database.correctObjectName.

Fix the object name to the format the database expects, handling changes in case, etc.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides liquibase.database.AbstractJdbcDatabase.equals.

Indicates whether some other object is "equal to" this one.

public String
escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)

Overrides liquibase.database.AbstractJdbcDatabase.escapeObjectName.

Implements liquibase.database.Database.escapeObjectName.

This has special case logic to handle NOT quoting column names if they are of type 'LiquibaseColumn' - columns in the DATABASECHANGELOG or DATABASECHANGELOGLOCK tables.

public boolean
public boolean
public String

Returns:

PK name.
generatePrimaryKeyName
(final String
Table name as the base name for the generated PK.
tableName
)

Overrides liquibase.database.AbstractJdbcDatabase.generatePrimaryKeyName.

Implements liquibase.database.Database.generatePrimaryKeyName.

Generates PK following PostgreSQL conventions:

  • Postgres PK size is limited with 63 bytes.
  • Postgres PK is suffixed with '_pkey'.
  • public String
    protected String
    getAutoIncrementClause(final String generationType, final Boolean defaultOnNull)

    Overrides liquibase.database.AbstractJdbcDatabase.getAutoIncrementClause.

    Default implementation.

    protected SqlStatement
    getConnectionSchemaNameCallStatement()

    Overrides liquibase.database.AbstractJdbcDatabase.getConnectionSchemaNameCallStatement.

    Used to obtain the connection schema name through a statement Override this method to change the statement.

    public String
    public String
    protected String
    public String
    getDefaultDriver(String url)

    Implements liquibase.database.Database.getDefaultDriver.

    If this database understands the given url, return the default driver class name.

    public Integer
    public int
    getMaxFractionalDigitsForTimestamp()

    Overrides liquibase.database.AbstractJdbcDatabase.getMaxFractionalDigitsForTimestamp.

    Implements liquibase.database.Database.getMaxFractionalDigitsForTimestamp.

    Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.

    public int
    public CatalogAndSchema.CatalogAndSchemaCase
    public String
    getShortName()

    Implements liquibase.database.Database.getShortName.

    Returns an all-lower-case short name of the product.

    public Set<String>
    getSystemViews()

    Overrides liquibase.database.AbstractJdbcDatabase.getSystemViews.

    Returns system (undroppable) views.

    public int
    hashCode()

    Overrides liquibase.database.AbstractJdbcDatabase.hashCode.

    Returns a hash code value for this object.

    protected boolean
    hasMixedCase(String tableName)

    public boolean
    isCorrectDatabaseImplementation(DatabaseConnection conn)

    Implements liquibase.database.Database.isCorrectDatabaseImplementation.

    Is this AbstractDatabase subclass the correct one to use for the given connection.

    public boolean
    public boolean
    public void
    public void
    public void
    public boolean
    public boolean
    supportsCreateIfNotExists(Class<? extends DatabaseObject>
    the DatabaseObject type to be checked.
    type
    )

    Overrides default liquibase.database.Database.supportsCreateIfNotExists.

    Does the database support the "if not exits" syntax?

    public boolean
    supportsInitiallyDeferrableColumns()

    Implements liquibase.database.Database.supportsInitiallyDeferrableColumns.

    Returns whether this database support initially deferrable columns.

    public boolean
    public boolean
    public String
    public boolean
    useSerialDatatypes()

    Should the database use "serial" datatypes vs. "generated by default as identity"

    Inherited from liquibase.database.AbstractJdbcDatabase:
    addReservedWordscanCreateChangeLogTableclosecommitcorrectSchemacorrectSchemacreatesIndexesForForeignKeysdataTypeIsNotModifiabledisableForeignKeyChecksdoesTagExistdropDatabaseObjectsenableForeignKeyChecksescapeColumnNameescapeColumnNameescapeColumnNameListescapeConstraintNameescapeDataTypeNameescapeIndexNameescapeObjectNameescapeSequenceNameescapeStringForDatabaseescapeTableNameescapeViewNameexecuteexecuteRollbackStatementsexecuteRollbackStatementsexecuteStatementsfilterRollbackVisitorsgenerateDatabaseFunctionValuegetgetAutoCommitModegetAutoIncrementByClausegetAutoIncrementClausegetAutoIncrementClosinggetAutoIncrementOpeninggetAutoIncrementStartWithClausegetConcatSqlgetConnectiongetConnectionCatalogNamegetConnectionSchemaNamegetContainingObjectsgetCurrentDateTimeFunctiongetDatabaseMajorVersiongetDatabaseMinorVersiongetDatabaseProductNamegetDatabaseProductVersiongetDataTypeMaxParametersgetDateFunctionsgetDateLiteralgetDateLiteralgetDateLiteralgetDateTimeLiteralgetDefaultCatalogNamegetDefaultFractionalDigitsForTimestampgetDefaultScaleForNativeDataTypegetDefaultSchemagetDefaultSchemaNamegetFetchSizegetJdbcCatalogNamegetJdbcCatalogNamegetJdbcSchemaNamegetJdbcSchemaNamegetLineCommentgetLiquibaseCatalogNamegetLiquibaseSchemaNamegetLiquibaseTablespaceNamegetNamegetObjectQuotingStrategygetOutputDefaultCataloggetOutputDefaultSchemagetQuotingEndCharactergetQuotingEndReplacementgetQuotingStartCharactergetRanChangeSetgetRanChangeSetListgetRanDategetRawDatabaseChangeLogLockTableNamegetRawDatabaseChangeLogTableNamegetRunStatusgetSchemaFromJdbcInfogetSystemSchemagetSystemTablesgetTimeLiteralgetViewDefinitionisAutoCommitisCaseSensitiveisCatalogOrSchemaTypeisCurrentTimeFunctionisDateOnlyisDateTimeisDefaultCatalogisDefaultSchemaisFunctionisLiquibaseObjectisSafeToRunUpdateisSystemViewisTimeOnlyisTimestampjdbcCallsCatalogsSchemasmarkChangeSetExecStatusmustQuoteObjectNameparseDatequoteObjectremoveRanStatusrequiresExplicitNullForColumnsrequiresPasswordrequiresUsernameresetInternalStatesaveRollbackStatementsaveStatementssetsetAutoCommitsetCanCacheLiquibaseTableInfosetCaseSensitivesetCurrentDateTimeFunctionsetDatabaseChangeLogLockTableNamesetDatabaseChangeLogTableNamesetDefaultSchemaNamesetLiquibaseCatalogNamesetLiquibaseSchemaNamesetLiquibaseTablespaceNamesetObjectQuotingStrategysetOutputDefaultCatalogsetOutputDefaultSchemastartsWithNumericsupportsAutoIncrementsupportsBatchUpdatessupportsCatalogssupportsDDLInTransactionsupportsDropTableCascadeConstraintssupportsForeignKeyDisablesupportsNotNullConstraintNamessupportsPrimaryKeyNamessupportsRestrictForeignKeyssupportsSchemastagtoStringunescapeDataTypeStringvalidate

    Field Detail

    dbFullVersionback to summary
    private static final String dbFullVersion
    LOGback to summary
    private static final Logger LOG
    MINIMUM_DBMS_MAJOR_VERSIONback to summary
    public static final int MINIMUM_DBMS_MAJOR_VERSION
    MINIMUM_DBMS_MINOR_VERSIONback to summary
    public static final int MINIMUM_DBMS_MINOR_VERSION
    PGSQL_DEFAULT_TCP_PORT_NUMBERback to summary
    private static final int PGSQL_DEFAULT_TCP_PORT_NUMBER
    PGSQL_PK_BYTES_LIMITback to summary
    pack-priv static final int PGSQL_PK_BYTES_LIMIT

    Maximum length of PostgresSQL identifier. For details:

    See Also
    SQL-SYNTAX-IDENTIFIERS
    PGSQL_PK_SUFFIXback to summary
    pack-priv static final String PGSQL_PK_SUFFIX
    PRODUCT_NAMEback to summary
    public static final String PRODUCT_NAME
    reservedWordsback to summary
    private final Set<String> reservedWords

    Hides liquibase.database.AbstractJdbcDatabase.reservedWords.

    systemTablesAndViewsback to summary
    private final Set<String> systemTablesAndViews
    VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMESback to summary
    public static final List<String> VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMES

    The data type names which are valid for auto-increment columns.

    Constructor Detail

    PostgresDatabaseback to summary
    public PostgresDatabase()

    Method Detail

    correctObjectNameback to summary
    public String correctObjectName(String objectName, Class<? extends DatabaseObject> objectType)

    Overrides liquibase.database.AbstractJdbcDatabase.correctObjectName.

    Implements liquibase.database.Database.correctObjectName.

    Doc from liquibase.database.Database.correctObjectName.

    Fix the object name to the format the database expects, handling changes in case, etc.

    Annotations
    @Override
    equalsback to summary
    public boolean equals(Object o)

    Overrides liquibase.database.AbstractJdbcDatabase.equals.

    Doc from java.lang.Object.equals.

    Indicates whether some other object is "equal to" this one.

    The equals method implements an equivalence relation on non-null object references:

    • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
    • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
    • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
    • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
    • For any non-null reference value x, x.equals(null) should return false.

    An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

    Parameters
    o:Object

    the reference object with which to compare.

    Returns:boolean

    true if this object is the same as the obj argument; false otherwise.

    Annotations
    @Override
    escapeObjectNameback to summary
    public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)

    Overrides liquibase.database.AbstractJdbcDatabase.escapeObjectName.

    Implements liquibase.database.Database.escapeObjectName.

    This has special case logic to handle NOT quoting column names if they are of type 'LiquibaseColumn' - columns in the DATABASECHANGELOG or DATABASECHANGELOGLOCK tables.

    Annotations
    @Override
    generateAutoIncrementByback to summary
    public boolean generateAutoIncrementBy(BigInteger incrementBy)

    Overrides liquibase.database.AbstractJdbcDatabase.generateAutoIncrementBy.

    Annotations
    @Override
    generateAutoIncrementStartWithback to summary
    public boolean generateAutoIncrementStartWith(BigInteger startWith)

    Overrides liquibase.database.AbstractJdbcDatabase.generateAutoIncrementStartWith.

    Annotations
    @Override
    generatePrimaryKeyNameback to summary
    public String generatePrimaryKeyName(final String tableName)

    Overrides liquibase.database.AbstractJdbcDatabase.generatePrimaryKeyName.

    Implements liquibase.database.Database.generatePrimaryKeyName.

    Generates PK following PostgreSQL conventions:

  • Postgres PK size is limited with 63 bytes.
  • Postgres PK is suffixed with '_pkey'.
    Parameters
    tableName:String

    Table name as the base name for the generated PK.

    Returns:String

    PK name.

    Annotations
    @Override
  • getAutoIncrementClauseback to summary
    public String getAutoIncrementClause()

    Overrides liquibase.database.AbstractJdbcDatabase.getAutoIncrementClause.

    Annotations
    @Override
    getAutoIncrementClauseback to summary
    protected String getAutoIncrementClause(final String generationType, final Boolean defaultOnNull)

    Overrides liquibase.database.AbstractJdbcDatabase.getAutoIncrementClause.

    Doc from liquibase.database.AbstractJdbcDatabase.getAutoIncrementClause.

    Default implementation. Intended for override in database specific cases

    Annotations
    @Override
    getConnectionSchemaNameCallStatementback to summary
    protected SqlStatement getConnectionSchemaNameCallStatement()

    Overrides liquibase.database.AbstractJdbcDatabase.getConnectionSchemaNameCallStatement.

    Doc from liquibase.database.AbstractJdbcDatabase.getConnectionSchemaNameCallStatement.

    Used to obtain the connection schema name through a statement Override this method to change the statement. Only override this if getConnectionSchemaName is left unchanged or is using this method.

    Annotations
    @Override
    getDatabaseChangeLogLockTableNameback to summary
    public String getDatabaseChangeLogLockTableName()

    Overrides liquibase.database.AbstractJdbcDatabase.getDatabaseChangeLogLockTableName.

    Implements liquibase.database.Database.getDatabaseChangeLogLockTableName.

    Annotations
    @Override
    getDatabaseChangeLogTableNameback to summary
    public String getDatabaseChangeLogTableName()

    Overrides liquibase.database.AbstractJdbcDatabase.getDatabaseChangeLogTableName.

    Implements liquibase.database.Database.getDatabaseChangeLogTableName.

    Annotations
    @Override
    getDefaultDatabaseProductNameback to summary
    protected String getDefaultDatabaseProductName()

    Implements abstract liquibase.database.AbstractJdbcDatabase.getDefaultDatabaseProductName.

    Annotations
    @Override
    getDefaultDriverback to summary
    public String getDefaultDriver(String url)

    Implements liquibase.database.Database.getDefaultDriver.

    Doc from liquibase.database.Database.getDefaultDriver.

    If this database understands the given url, return the default driver class name. Otherwise return null.

    Annotations
    @Override
    getDefaultPortback to summary
    public Integer getDefaultPort()

    Implements liquibase.database.Database.getDefaultPort.

    Annotations
    @Override
    getMaxFractionalDigitsForTimestampback to summary
    public int getMaxFractionalDigitsForTimestamp()

    Overrides liquibase.database.AbstractJdbcDatabase.getMaxFractionalDigitsForTimestamp.

    Implements liquibase.database.Database.getMaxFractionalDigitsForTimestamp.

    Doc from liquibase.database.AbstractJdbcDatabase.getMaxFractionalDigitsForTimestamp.

    Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.

    Returns:int

    the maximum number of supported fractional digits in TIMESTAMP columns

    Annotations
    @Override
    @SuppressWarnings:squid:S109
    getPriorityback to summary
    public int getPriority()

    Implements liquibase.servicelocator.PrioritizedService.getPriority.

    Annotations
    @Override
    getSchemaAndCatalogCaseback to summary
    public CatalogAndSchema.CatalogAndSchemaCase getSchemaAndCatalogCase()

    Overrides liquibase.database.AbstractJdbcDatabase.getSchemaAndCatalogCase.

    Implements liquibase.database.Database.getSchemaAndCatalogCase.

    Doc from liquibase.database.AbstractJdbcDatabase.getSchemaAndCatalogCase.

    This logic is used when db support catalogs

    Returns:CatalogAndSchema.CatalogAndSchemaCase

    UPPER_CASE by default

    Annotations
    @Override
    getShortNameback to summary
    public String getShortName()

    Implements liquibase.database.Database.getShortName.

    Doc from liquibase.database.Database.getShortName.

    Returns an all-lower-case short name of the product. Used for end-user selecting of database type such as the DBMS precondition.

    Annotations
    @Override
    getSystemViewsback to summary
    public Set<String> getSystemViews()

    Overrides liquibase.database.AbstractJdbcDatabase.getSystemViews.

    Doc from liquibase.database.AbstractJdbcDatabase.getSystemViews.

    Returns system (undroppable) views.

    Annotations
    @Override
    hashCodeback to summary
    public int hashCode()

    Overrides liquibase.database.AbstractJdbcDatabase.hashCode.

    Doc from java.lang.Object.hashCode.

    Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

    The general contract of hashCode is:

    • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
    • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
    • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
    Returns:int

    a hash code value for this object

    Annotations
    @Override
    hasMixedCaseback to summary
    protected boolean hasMixedCase(String tableName)
    isCorrectDatabaseImplementationback to summary
    public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException

    Implements liquibase.database.Database.isCorrectDatabaseImplementation.

    Doc from liquibase.database.Database.isCorrectDatabaseImplementation.

    Is this AbstractDatabase subclass the correct one to use for the given connection.

    Annotations
    @Override
    isReservedWordback to summary
    public boolean isReservedWord(String tableName)

    Overrides liquibase.database.AbstractJdbcDatabase.isReservedWord.

    Implements liquibase.database.Database.isReservedWord.

    Annotations
    @Override
    isSystemObjectback to summary
    public boolean isSystemObject(DatabaseObject example)

    Overrides liquibase.database.AbstractJdbcDatabase.isSystemObject.

    Implements liquibase.database.Database.isSystemObject.

    Annotations
    @Override
    rollbackback to summary
    public void rollback() throws DatabaseException

    Overrides liquibase.database.AbstractJdbcDatabase.rollback.

    Implements liquibase.database.Database.rollback.

    Annotations
    @Override
    setConnectionback to summary
    public void setConnection(DatabaseConnection conn)

    Overrides liquibase.database.AbstractJdbcDatabase.setConnection.

    Implements liquibase.database.Database.setConnection.

    Annotations
    @Override
    setDefaultCatalogNameback to summary
    public void setDefaultCatalogName(String defaultCatalogName)

    Overrides liquibase.database.AbstractJdbcDatabase.setDefaultCatalogName.

    Implements liquibase.database.Database.setDefaultCatalogName.

    Annotations
    @Override
    supportsCatalogInObjectNameback to summary
    public boolean supportsCatalogInObjectName(Class<? extends DatabaseObject> type)

    Overrides liquibase.database.AbstractJdbcDatabase.supportsCatalogInObjectName.

    Implements liquibase.database.Database.supportsCatalogInObjectName.

    Annotations
    @Override
    supportsCreateIfNotExistsback to summary
    public boolean supportsCreateIfNotExists(Class<? extends DatabaseObject> type)

    Overrides default liquibase.database.Database.supportsCreateIfNotExists.

    Doc from liquibase.database.Database.supportsCreateIfNotExists.

    Does the database support the "if not exits" syntax?

    Parameters
    type:Class<? extends DatabaseObject>

    the DatabaseObject type to be checked.

    Returns:boolean

    true if the "if not exists" syntax is supported, false otherwise.

    Annotations
    @Override
    supportsInitiallyDeferrableColumnsback to summary
    public boolean supportsInitiallyDeferrableColumns()

    Implements liquibase.database.Database.supportsInitiallyDeferrableColumns.

    Doc from liquibase.database.Database.supportsInitiallyDeferrableColumns.

    Returns whether this database support initially deferrable columns.

    Annotations
    @Override
    supportsSequencesback to summary
    public boolean supportsSequences()

    Overrides liquibase.database.AbstractJdbcDatabase.supportsSequences.

    Implements liquibase.database.Database.supportsSequences.

    Doc from liquibase.database.AbstractJdbcDatabase.supportsSequences.

    Does the database type support sequence.

    Annotations
    @Override
    supportsTablespacesback to summary
    public boolean supportsTablespaces()

    Implements liquibase.database.Database.supportsTablespaces.

    Annotations
    @Override
    unescapeDataTypeNameback to summary
    public String unescapeDataTypeName(String dataTypeName)

    Overrides liquibase.database.AbstractJdbcDatabase.unescapeDataTypeName.

    Implements liquibase.database.Database.unescapeDataTypeName.

    Annotations
    @Override
    useSerialDatatypesback to summary
    public boolean useSerialDatatypes()

    Should the database use "serial" datatypes vs. "generated by default as identity"