PSQL:错误:编码“UTF8”的无效字节序列(PSQL : ERROR: invalid byte sequence for encoding “UTF8”)

编程入门 行业动态 更新时间:2024-10-27 03:32:58
PSQL:错误:编码“UTF8”的无效字节序列(PSQL : ERROR: invalid byte sequence for encoding “UTF8”)

我试图通过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

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

最满意答案

您只需将设置更改为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”。

这应该工作!

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!

更多推荐

本文发布于:2023-08-04 15:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   字节   错误   PSQL   encoding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!