public class PostgresConnection extends JdbcConnection
JdbcConnection connection extension used for connecting to Postgres instances.| Modifier and Type | Class and Description |
|---|---|
private static class |
PostgresConnection.SqlTypeMapper
Allows to obtain the SQL type corresponding to PG types.
|
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetMapper<T>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer| Modifier and Type | Field and Description |
|---|---|
private Charset |
databaseCharset |
protected static JdbcConnection.ConnectionFactory |
FACTORY |
private static org.slf4j.Logger |
LOGGER |
private static int |
MAX_ATTEMPTS_FOR_OBTAINING_REPLICATION_SLOT
Obtaining a replication slot may fail if there's a pending transaction.
|
private static Duration |
PAUSE_BETWEEN_REPLICATION_SLOT_RETRIEVAL_ATTEMPTS |
private static String |
SQL_ARRAY_TYPES |
private static String |
SQL_NON_ARRAY_TYPES |
private TypeRegistry |
typeRegistry |
private static String |
URL_PATTERN |
| Constructor and Description |
|---|
PostgresConnection(Configuration config)
Creates a Postgres connection using the supplied configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
connectionString()
Returns a JDBC connection string for the current configuration.
|
Long |
currentTransactionId()
Returns the PG id of the current active transaction
|
long |
currentXLogLocation()
Returns the current position in the server tx log.
|
protected static void |
defaultSettings(Configuration.Builder builder) |
private Charset |
determineDatabaseCharset() |
boolean |
dropPublication(String publicationName)
Drops the debezium publication that was created.
|
boolean |
dropReplicationSlot(String slotName)
Drops a replication slot that was created on the DB
|
private ServerInfo.ReplicationSlot |
fetchReplicationSlotInfo(String slotName,
String pluginName)
Fetches the state of a replication stage given a slot name and plugin name
|
Charset |
getDatabaseCharset() |
SlotState |
getReplicationSlotState(String slotName,
String pluginName)
Returns the current state of the replication slot
|
TypeRegistry |
getTypeRegistry() |
private static TypeRegistry |
initTypeRegistry(Connection db) |
private Long |
parseConfirmedFlushLsn(String slotName,
String pluginName,
String database,
ResultSet rs)
Obtains the LSN to resume streaming from.
|
private Long |
parseRestartLsn(String slotName,
String pluginName,
String database,
ResultSet rs) |
protected ServerInfo.ReplicationSlot |
queryForSlot(String slotName,
String database,
String pluginName,
JdbcConnection.ResultSetMapper<ServerInfo.ReplicationSlot> map) |
ServerInfo.ReplicaIdentity |
readReplicaIdentityInfo(TableId tableId)
Prints out information about the REPLICA IDENTITY status of a table.
|
(package private) ServerInfo.ReplicationSlot |
readReplicationSlotInfo(String slotName,
String pluginName)
Fetches a replication slot, repeating the query until either the slot is created or until
the max number of attempts has been reached
To fetch the slot without the retries, use the
fetchReplicationSlotInfo(java.lang.String, java.lang.String) call |
protected int |
resolveNativeType(String typeName) |
ServerInfo |
serverInfo()
Returns information about the PG server to which this instance is connected.
|
private Long |
tryParseLsn(String slotName,
String pluginName,
String database,
ResultSet rs,
String column) |
private static void |
validateServerVersion(Statement statement) |
call, columnsFor, columnsFor, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, isConnected, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, queryWithBlockingConsumer, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readSchema, readTableColumn, readTableNames, setAutoCommit, tableTypes, usernameprivate static org.slf4j.Logger LOGGER
private static final String URL_PATTERN
protected static final JdbcConnection.ConnectionFactory FACTORY
private static final String SQL_NON_ARRAY_TYPES
private static final String SQL_ARRAY_TYPES
private static final int MAX_ATTEMPTS_FOR_OBTAINING_REPLICATION_SLOT
private static final Duration PAUSE_BETWEEN_REPLICATION_SLOT_RETRIEVAL_ATTEMPTS
private final TypeRegistry typeRegistry
private final Charset databaseCharset
public PostgresConnection(Configuration config)
config - Configuration instance, may not be null.public String connectionString()
String where the variables in urlPattern are replaced with values from the configurationpublic ServerInfo.ReplicaIdentity readReplicaIdentityInfo(TableId tableId) throws SQLException
tableId - the identifier of the tableSQLException - if there is a problem obtaining the replica identity information for the given tablepublic SlotState getReplicationSlotState(String slotName, String pluginName) throws SQLException
slotName - the name of the slotpluginName - the name of the plugin used for the desired slotSlotState or null, if no slot state is foundSQLExceptionprivate ServerInfo.ReplicationSlot fetchReplicationSlotInfo(String slotName, String pluginName) throws SQLException
slotName - the name of the slotpluginName - the name of the plugin used for the desired slotServerInfo.ReplicationSlot object or a ServerInfo.ReplicationSlot.INVALID if
the slot is not validSQLException - is thrown by the underlying JDBC@VisibleForTesting ServerInfo.ReplicationSlot readReplicationSlotInfo(String slotName, String pluginName) throws SQLException, InterruptedException
fetchReplicationSlotInfo(java.lang.String, java.lang.String) callslotName - the slot namepluginName - the name of the pluginServerInfo.ReplicationSlot object or a ServerInfo.ReplicationSlot.INVALID if
the slot is not validSQLException - is thrown by the underyling jdbc driverInterruptedException - is thrown if we don't return an answer within the set number of retriesprotected ServerInfo.ReplicationSlot queryForSlot(String slotName, String database, String pluginName, JdbcConnection.ResultSetMapper<ServerInfo.ReplicationSlot> map) throws SQLException
SQLExceptionprivate Long parseConfirmedFlushLsn(String slotName, String pluginName, String database, ResultSet rs)
private Long parseRestartLsn(String slotName, String pluginName, String database, ResultSet rs)
private Long tryParseLsn(String slotName, String pluginName, String database, ResultSet rs, String column) throws org.apache.kafka.connect.errors.ConnectException, SQLException
org.apache.kafka.connect.errors.ConnectExceptionSQLExceptionpublic boolean dropReplicationSlot(String slotName)
slotName - the name of the replication slot, may not be nulltrue if the slot was dropped, false otherwisepublic boolean dropPublication(String publicationName)
publicationName - the publication name, may not be nulltrue if the publication was dropped, false otherwisepublic void close()
close in interface AutoCloseableclose in class JdbcConnectionpublic Long currentTransactionId() throws SQLException
SQLException - if anything fails.public long currentXLogLocation()
throws SQLException
SQLException - if anything unexpected fails.public ServerInfo serverInfo() throws SQLException
ServerInfo instance, never nullSQLException - if anything failspublic Charset getDatabaseCharset()
private Charset determineDatabaseCharset()
protected static void defaultSettings(Configuration.Builder builder)
private static void validateServerVersion(Statement statement) throws SQLException
SQLExceptionprotected int resolveNativeType(String typeName)
resolveNativeType in class JdbcConnectionprivate static TypeRegistry initTypeRegistry(Connection db)
public TypeRegistry getTypeRegistry()
Copyright © 2019 JBoss by Red Hat. All rights reserved.