postgres error : failed to read kind from backend

本文分析了PgPool-II在Postgres Master-Slave模式下遇到的kind mismatch错误,并探讨了解决方案,包括调整配置和等待官方版本更新。

新安装了postgres master-slave 模式,连接上应用,发现如下报错

ERROR  - JDBC commit failed

org.postgresql.util.PSQLException: FATAL: failed to read kind from backend
  Detail: kind mismatch among backends. Possible last query was: "COMMIT" kind details are: 0[3] 1[1]
  Hint: check data consistency among db nodes


  从pgpool f&q查到如下描述:
  
  Why "SET default_transaction_isolation TO DEFAULT" fails ?
$ psql -h localhost -p 9999 -c 'SET default_transaction_isolation to DEFAULT;'
ERROR: kind mismatch among backends. Possible last query was: "SET default_transaction_isolation to DEFAULT;" kind details are: 0[N: statement: SET default_transaction_isolation to DEFAULT;] 1[C]
HINT: check data consistency among db nodes
ERROR: kind mismatch among backends. Possible last query was: "SET default_transaction_isolation to DEFAULT;" kind details are: 0[N: statement: SET default_transaction_isolation to DEFAULT;] 1[C]
HINT: check data consistency among db nodes
connection to server was lost
Pgpool-II detects that node 0 returns "N" (a NOTICE message comes from PostgreSQL) while node 1 returns "C" (which means the command finished).
Though pgpool-II expects that both node 0 and 1 returns identical messages, actually they are not. So pgpool-II threw an error.
Probably certain log/message settings are different in node 0 and 1. Please check client_min_messages or something like that.




从网上查到如下描述:

分析如下:


 send_to_where函数中,处在Master/Slave模式的时候,数据的增、删、改指令只向PrimaryDB发送。
 begin/commit这样的事务有关的指令,则既向Master送信,也向Slave送信。

该描述实际上是和官网上的描述有出入的,实际观察到的如下 log

2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Parse: BEGIN
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: Parse: BEGIN
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: B message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: B message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Execute: BEGIN
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: Execute: BEGIN
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Parse: *******************************
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: B message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: D message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Execute: ****************************************
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: C message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: C message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Parse: COMMIT
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: Parse: COMMIT
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: B message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: B message
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 0 backend pid: 5632 statement: Execute: COMMIT
2016-04-10 15:31:20: pid 5431: LOG:  DB node id: 1 backend pid: 9793 statement: Execute: COMMIT
2016-04-10 15:31:20: pid 5431: WARNING:  packet kind of backend 1 ['1'] does not match with master/majority nodes packet kind ['3']
2016-04-10 15:31:20: pid 5431: FATAL:  failed to read kind from backend
2016-04-10 15:31:20: pid 5431: DETAIL:  kind mismatch among backends. Possible last query was: "COMMIT" kind details are: 0[3] 1[1]
2016-04-10 15:31:20: pid 5431: HINT:  check data consistency among db nodes




 通过上述的分析,从pool_process_query→send_to_where 的调用关系,
 commit则既向Master送信,也向Slave送信,但是!
 由于子进程与Slave之间的网络通信被中断,pool_read发生错误,那么此子进程就exit消亡了。
 而此时,已经向PrimaryDB发送了的commit指令,已经成功,是无法取消的。




修改 postgres 备机上的hot_standby_feedback = off ,问题未解决,

更改pgpool 的client_min_messages =error,等待验证,依然无效

2016.4.14,

在官方网站上找到

http://www.pgpool.net/pipermail/pgpool-general/2016-March/004623.html

并且说是在pgpool3.6上会修复这个问题

http://pgpool.net/mediawiki/index.php/pgpool-II_3.6_development

只能等待了








### PostgreSQL SASL 认证失败和密码验证错误解决方案 当遇到 `PostgreSQL` 的 `SASL` 认证失败或密码验证错误时,通常会收到类似于以下的错误消息: - **Error**: `FATAL: password authentication failed for user "postgres"` - **SQLSTATE Code**: `28P01` 此问题可能由多种原因引起,以下是详细的分析和解决方法。 #### 一、检查配置文件 确保数据库服务器端的配置文件设置正确。主要涉及两个核心文件: 1. **pg_hba.conf** 文件用于定义客户端访问权限。 2. **postgresql.conf** 文件用于调整全局参数。 ##### pg_hba.conf 配置 确认 `pg_hba.conf` 中是否有针对用户的适当条目。例如,如果希望允许本地用户通过 MD5 密码认证,则应有如下行[^1]: ```plaintext host all postgres 127.0.0.1/32 md5 ``` 对于 IPv6 地址,也需要类似的条目: ```plaintext host all postgres ::1/128 md5 ``` 如果需要启用 `SCRAM-SHA-256` 或其他 `SASL` 方法,可以修改认证方式为 `scram-sha-256`[^2]: ```plaintext host all postgres 127.0.0.1/32 scram-sha-256 ``` ##### postgresql.conf 配置 确保启用了必要的选项来支持 `SASL` 和加密连接。例如,在某些情况下需要显式开启 SSL 支持: ```plaintext ssl = on password_encryption = 'scram-sha-256' ``` #### 二、重置 Postgres 用户密码 如果怀疑密码不匹配或者从未更改过默认密码,可以通过以下步骤重新设置密码。 1. 使用超级用户登录到 PostgreSQL 数据库: ```bash sudo -u postgres psql ``` 2. 修改目标用户的密码(假设用户名为 `postgres`): ```sql ALTER USER postgres PASSWORD 'new_secure_password'; ``` 3. 刷新权限并退出: ```sql \q ``` 注意:新密码需满足复杂度要求,并建议避免使用简单字符串作为密码[^3]。 #### 三、测试连接 完成上述操作后,尝试再次建立连接以验证修复效果。命令行工具如 `psql` 可用来模拟实际场景下的行为: ```bash psql -h localhost -U postgres -d your_database_name Password for user postgres: ``` 输入刚刚设定的新密码即可成功进入数据库环境。 #### 四、排查日志信息 若仍然无法解决问题,可查阅 PostgreSQL 日志获取更多细节。路径一般位于 `/var/log/postgresql/` 下面,具体取决于操作系统版本及安装方式。查找关键字 “authentication” 或者指定时间范围内的异常记录有助于定位根本原因[^4]。 --- ### 示例代码片段 下面是一个简单的 Python 脚本示例,展示如何利用 psycopg2 库实现带身份验证的安全连接: ```python import psycopg2 try: connection = psycopg2.connect( host="localhost", database="your_db", user="postgres", password="new_secure_password" ) except Exception as e: print(f"Connection error: {e}") else: cursor = connection.cursor() cursor.execute("SELECT version();") result = cursor.fetchone() print(result) finally: if connection: cursor.close() connection.close() ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值