Aurora Postgres Logical Replication in Java

0

My goal is to stream the Postgres WAL inside a system that runs on the JVM. I am using Aurora RDS Postgres.

If I try to run the following:

    PGReplicationStream stream =
        pgConnection.getReplicationAPI()
            .replicationStream()
            .logical()
            .withSlotName("test_slot")
            .withStartPosition(lsn)
            .start();

I get the error:

; (err) ERROR: syntax error at or near "START_REPLICATION"
; (err)   Position: 1

Postgres logs the following command:

:ERROR:  syntax error at or near "START_REPLICATION" at character 1
:STATEMENT:  START_REPLICATION SLOT test_slot LOGICAL 0/40DCC70;

This does look like the command the jdbc driver is trying to write. (as seen here)

START_REPLICATION does seem to be a command Postgres supports. Is it that Aurora RDS does not support this? If so, is there an alternative way to do this?

stopa
asked a year ago384 views
1 Answer
0
Accepted Answer

The problem was that I was using the wrong connection. I had a HikariCP, and thought I could just take one of the connections from it.

But what you need to do, is to create a specific 'replication' connection. Something like:

    Properties props = new Properties();
    PGProperty.USER.set(props, "user");
    PGProperty.PASSWORD.set(props, "pass");
    PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.4");
    PGProperty.REPLICATION.set(props, "database");
    PGProperty.PREFER_QUERY_MODE.set(props, "simple");

    Connection con = DriverManager.getConnection(url, props);
stopa
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions