我正在尝试通过java PostgreSQL 42.0.0.jre7 API创建一个逻辑复制槽,这是我的代码:
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();
但是当我运行它时,我得到了这个例外,说我有编码问题。
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
这是我的postgres配置我试过sql_ascii,utf8用于客户端编码,但总是出现同样的错误:
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
答案 0 :(得分:1)
您只需将设置更改为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'
并且不要忘记发表评论" client_encoding = windows-1251"。
这应该有效!