public class PostgresReplicationConnection extends JdbcConnection implements ReplicationConnection
ReplicationConnection for Postgresql. Note that replication connections in PG cannot execute
regular statements but only a limited number of replication-related commands.| Modifier and Type | Class and Description |
|---|---|
protected static class |
PostgresReplicationConnection.ReplicationConnectionBuilder |
JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.Operations, JdbcConnection.ResultSetConsumer, JdbcConnection.SingleParameterResultSetConsumer, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparerReplicationConnection.Builder| Modifier and Type | Field and Description |
|---|---|
private long |
defaultStartingPos |
private boolean |
dropSlotOnClose |
private static org.slf4j.Logger |
LOGGER |
private Configuration |
originalConfig |
private String |
pluginName |
private String |
slotName |
private Integer |
statusUpdateIntervalMillis |
| Modifier | Constructor and Description |
|---|---|
private |
PostgresReplicationConnection(Configuration config,
String slotName,
String pluginName,
boolean dropSlotOnClose,
Integer statusUpdateIntervalMillis)
Creates a new replication connection with the given params.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
private ReplicationStream |
createReplicationStream(org.postgresql.replication.LogSequenceNumber lsn) |
protected static void |
defaultSettings(Configuration.Builder builder) |
protected void |
initReplicationSlot() |
protected org.postgresql.PGConnection |
pgConnection() |
ReplicationStream |
startStreaming()
Opens a stream for reading logical replication changes from the last known position of the slot for which the connection
was opened.
|
ReplicationStream |
startStreaming(Long offset)
Opens a stream for reading logical replication changes from a given LSN position.
|
call, columnsFor, columnsFor, config, connect, connection, connectionString, database, execute, execute, isConnected, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareUpdate, print, print, query, query, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readSchema, readTableNames, readTypeInfo, setAutoCommit, tableTypes, usernameclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuilder, format, isConnectedprivate static org.slf4j.Logger LOGGER
private final String slotName
private final String pluginName
private final boolean dropSlotOnClose
private final Configuration originalConfig
private final Integer statusUpdateIntervalMillis
private long defaultStartingPos
private PostgresReplicationConnection(Configuration config, String slotName, String pluginName, boolean dropSlotOnClose, Integer statusUpdateIntervalMillis)
config - the JDBC configuration for the connection; may not be nullslotName - the name of the DB slot for logical replication; may not be nullpluginName - the name of the server side plugin used for streaming changes; may not be null;dropSlotOnClose - whether the replication slot should be dropped once the connection is closedstatusUpdateIntervalMillis - the number of milli-seconds at which the replication connection should periodically send status
updates to the serverprotected void initReplicationSlot()
throws SQLException
SQLExceptionpublic ReplicationStream startStreaming() throws SQLException
ReplicationConnectionconfirmed_flush_lsn value from the pg_replication_slots
table.
If there is no "last known value" (i.e. the connection is for a newly created slot) then the Postgres server will start streaming changes from that last position reported during this connection's creation.
startStreaming in interface ReplicationConnectionPGReplicationStream from which data is read; never nullSQLException - if there is a problem obtaining the replication streampublic ReplicationStream startStreaming(Long offset) throws SQLException
ReplicationConnection
Note that it is possible for a server to have recycled old WAL segments (see the wal_keep_segments setting). If
that is the case, then even though a LSN number may be valid, the server will not stream back any changes because they
are not available.
startStreaming in interface ReplicationConnectionoffset - a value representing the WAL sequence number where replication should start from; if the value
is null or negative, this behaves exactly like ReplicationConnection.startStreaming().PGReplicationStream from which data is read; never nullSQLException - if anything failsLogSequenceNumberprotected org.postgresql.PGConnection pgConnection()
throws SQLException
SQLExceptionprivate ReplicationStream createReplicationStream(org.postgresql.replication.LogSequenceNumber lsn) throws SQLException
SQLExceptionpublic void close()
close in interface AutoCloseableclose in class JdbcConnectionprotected static void defaultSettings(Configuration.Builder builder)
Copyright © 2017 JBoss by Red Hat. All rights reserved.