1

I am trying to create a logical replication slot via the java PostgreSQL 42.0.0.jre7 API and this is my code :

String url = "jdbc:postgresql://localhost:5432/sampledb?characterEncoding=utf8";
Properties props = new Properties();
PGProperty.USER.set(props, "postgres");
PGProperty.PASSWORD.set(props, "root");
PGProperty.ASSUME_MIN_SERVER_VERSION.set(props, "9.6");
PGProperty.REPLICATION.set(props, "true");
PGProperty.PREFER_QUERY_MODE.set(props, "simple");
DriverManager.registerDriver(new org.postgresql.Driver());
Connection con = DriverManager.getConnection(url, props);
PGConnection replConnection = con.unwrap(PGConnection.class);

replConnection.getReplicationAPI()
.createReplicationSlot()
.logical()
.withSlotName("logical_replication_slot")
.withOutputPlugin("test_decoding")
.make();

but when i run it I get this exception saying that I have an encoding problem.

Caused by: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0xe9 0x71 0x75
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:260)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at org.postgresql.replication.fluent.logical.LogicalCreateSlotBuilder.make(LogicalCreateSlotBuilder.java:48)[423:org.postgresql.jdbc41:42.0.0.jre7]
        at com.soprahr.hub.replication.postgresql.activator.Activator.start(Activator.java:41)[424:com.soprahr.hub.replication.postgresql:0.0.1.SNAPSHOT]
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)[org.apache.felix.framework-5.6.1.jar:]
        ... 16 more

This is my postgres config i have tried sql_ascii, utf8 for client encoding but always the same error :

client_encoding = windows-1251      # actually, defaults to database
                    # encoding

# These settings are initialized by initdb, but they can be changed.
lc_messages = 'French_France.1252'          # locale for system error message
                    # strings
lc_monetary = 'French_France.1252'          # locale for monetary formatting
lc_numeric = 'French_France.1252'           # locale for number formatting
lc_time = 'French_France.1252'              # locale for time formatting
2
  • Maybe you should set client_encoding to cp1252, or iso8859-1 or iso8859-15 ? (you can also set it at the start of the session via set client_encoding iso8859-15; Commented Apr 24, 2017 at 12:00
  • i can't set it it shows the following error Not connected to the server or the connection to the server has been closed. but when i try show client_encoding it gives UNICODE i tried to edit it from the config file but always UNICODE Commented Apr 24, 2017 at 13:13

1 Answer 1

1

You just need to change the settings into postgres.conf

lc_messages = 'English_United States.1252' 
lc_monetary = 'English_United States.1252'  
lc_numeric = 'English_United States.1252'   
lc_time = 'English_United States.1252'      
default_text_search_config = 'pg_catalog.english'

And don't forget to comment "client_encoding = windows-1251".

This should work!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.