三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

postgresql因在从库备份时间长而失败

postgresql因在从库备份时间长而失败

文章目录

  • 环境
  • 症状
  • 问题原因
  • 解决方案
  • 报错编码

环境

系统平台:Linux x86-64 Red Hat Enterprise Linux 7,Linux x86-64 Red Hat Enterprise Linux 8
版本:10.4,11,12,13,14

症状

在standby从库用pg_dump因数据库比较大备份时间久,抛出错误备份失败。报错信息如下

postgres@vm112 ~]$ pg_dump -dpostgres -f a.dmp pg_dump: error: Dumping the contents of table "t1" failed: PQgetResult() failed. pg_dump: error: Error message from server: ERROR: canceling statement due to conflict with recovery DETAIL: User query might have needed to see row versions that must be removed.

问题原因

standby从库有个wal replay进程在进行wal回放, 如果回放过程中有查询会话和回放的内容发生了冲突, 那么wal回放会进行等待,等待的时间不会大于参数max_standby_streaming_delay的设定。当等待超过这个时间时, wal replay会cancel与之有冲突的所有查询会话, 然后开始恢复。

解决方案

1、查询max_standby_streaming_delay设置

postgres=# show max_standby_streaming_delay ;max_standby_streaming_delay-----------------------------3min(1row)

2、调大max_standby_streaming_delay的设置

postgres=# alter system set max_standby_streaming_delay='10min';ALTERSYSTEM postgres=# select pg_reload_conf();pg_reload_conf----------------t(1row)postgres=# show max_standby_streaming_delay ;max_standby_streaming_delay-----------------------------10min(1row)

3、重新进行备份,备份成功

[postgres@vm112~]$ pg_dump-dpostgres-f a.dmp;[postgres@vm112~]$

报错编码

pg_dump: error: Error message from server: ERROR: canceling statement due to conflict with recovery

← 返回列表