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设置

sql 复制代码
postgres=# show max_standby_streaming_delay ;
 max_standby_streaming_delay 
-----------------------------
 3min
(1 row)

2、调大max_standby_streaming_delay的设置

sql 复制代码
postgres=#  alter system set max_standby_streaming_delay='10min';
ALTER SYSTEM
postgres=# select pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 row)
postgres=# show max_standby_streaming_delay ;
 max_standby_streaming_delay 
-----------------------------
 10min
(1 row)

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

sql 复制代码
[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

相关推荐
Zan2 小时前
SQLite + SQLx 实战:为什么已经发布的数据库迁移文件,绝对不能再修改?
数据库·后端·面试
修己xj3 小时前
服务器无法解析域名?一次 DNS 配置缺失的排查与修复
运维
这个DBA有点耶3 小时前
数据同步的三个工程底线:DDL同步、断点续传、一致性校验——开源CDC的边界与KFS的路径
数据库·dba·代码规范
SelectDB4 小时前
列式存储为什么适合分析类负载?原理、限制与日志场景应用
数据库
数据库小学妹5 小时前
MySQL大字段治理:行溢出机制、覆盖索引与拆表
数据库·mysql·性能优化
爱吃奥利奥_wen5 小时前
SQL Server 基础语法详解:从建库建表到约束与增删改查
服务器·数据库·oracle
这个DBA有点耶6 小时前
MySQL 8.0不可见索引:删索引怕出事,不删又拖慢写入——中间态怎么用?
数据库·mysql·代码规范
测试界的小码农8 小时前
【图数据库实战进阶(01):从零认识 Neo4j,搭建第一个图数据库项目】
数据库·neo4j
xbzb8 小时前
自定义 yum 软件源:Linux 上 createrepo,Windows 上纯 Python 也能造
linux·运维·windows·python·yum·createrepo