当前位置: 首页 > news >正文

postgresql 15.2 用pgbackup搭建备库后,主从复制一直无法启动

pgbackup搭建主从复制过程

主备检查:
log 日志检查,主从库都正常
从库

2025-03-11 10:18:23.952 CST [15567] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2025-03-11 10:18:23.952 CST [15567] LOG:  listening on IPv4 address "0.0.0.0", port 1922
2025-03-11 10:18:23.952 CST [15567] LOG:  listening on IPv6 address "::", port 1922
2025-03-11 10:18:23.954 CST [15567] LOG:  listening on Unix socket "/tmp/.s.PGSQL.1922"
2025-03-11 10:18:23.956 CST [15571] LOG:  database system was shut down in recovery at 2025-03-11 10:17:43 CST
2025-03-11 10:18:23.957 CST [15571] LOG:  entering standby mode
2025-03-11 10:18:23.960 CST [15571] LOG:  redo starts at 7/9C000028
2025-03-11 10:18:23.970 CST [15571] LOG:  consistent recovery state reached at 7/9C41B8D8
2025-03-11 10:18:23.970 CST [15571] LOG:  recovery stopping before commit of transaction 177155, time 2025-03-04 14:48:21.479534+08
2025-03-11 10:18:23.970 CST [15571] LOG:  pausing at the end of recovery
2025-03-11 10:18:23.970 CST [15571] HINT:  Execute pg_wal_replay_resume() to promote.
2025-03-11 10:18:23.970 CST [15567] LOG:  database system is ready to accept read-only connections

主库:

2025-03-11 09:21:41.100 CST [1277] LOG:  starting PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2025-03-11 09:21:41.100 CST [1277] LOG:  listening on IPv4 address "0.0.0.0", port 1922
2025-03-11 09:21:41.100 CST [1277] LOG:  listening on IPv6 address "::", port 1922
2025-03-11 09:21:41.108 CST [1277] LOG:  listening on Unix socket "/tmp/.s.PGSQL.1922"
2025-03-11 09:21:41.370 CST [1377] LOG:  database system was interrupted; last known up at 2025-03-10 14:26:57 CST
2025-03-11 09:21:51.197 CST [1377] LOG:  database system was not properly shut down; automatic recovery in progress
2025-03-11 09:21:51.232 CST [1377] LOG:  redo starts at 7/9D0000D8
2025-03-11 09:21:51.232 CST [1377] LOG:  invalid record length at 7/9D0001C0: wanted 24, got 0
2025-03-11 09:21:51.232 CST [1377] LOG:  redo done at 7/9D000188 system usage: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.01 s
2025-03-11 09:21:51.398 CST [1375] LOG:  checkpoint starting: end-of-recovery immediate wait
2025-03-11 09:21:51.839 CST [1375] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.109 s, total=0.445 s; sync files=2, longest=0.083 s, average=0.055 s; distance=0 kB, estimate=0 kB
2025-03-11 09:21:51.932 CST [1277] LOG:  database system is ready to accept connections

主库视图检查


postgres=# SELECT client_addr,sync_state FROM pg_stat_replication;
 client_addr | sync_state
-------------+------------
(0 rows)

postgres=# \du
                                    List of roles
 Role name  |                         Attributes                         | Member of
------------+------------------------------------------------------------+-----------
 fdw_user   |                                                            | {}
 local_user |                                                            | {}
 postgres   | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 qn         | Create role, Create DB                                     | {}
 repl       | Replication                                               +| {}
            | 32 connections                                             |
 replc      | Replication                                               +| {}
            | 8 connections                                              |
 repmgr     | Superuser, Replication                                    +| {}
            | 5 connections                                              |
 test       | Superuser, Create DB                                       | {}
 testa      |                                                            | {}
 u11        |                                                            | {}
 u12        |                                                            | {}
 user2      |                                                            | {}

pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
host   all             all             ::1/128                md5
host  replication      repl   0.0.0.0/0                        md5
# host    all             all             127.0.0.1/32            trust
# host    all             all             ::1/128                 trust
# local   replication     all                                     trust
# host    replication     all             127.0.0.1/32            trust
# host    replication     all             ::1/128                 trust
# host    all             all             0.0.0.0/0               trust

host    replication     repmgr          0.0.0.0/0         md5
host    replication     repmgr          0.0.0.0/0         md5
host    all             all             0.0.0.0/0              md5

[postgres@postgres01 data]$  psql -h 192.168.99.151 -p 1922 -U repl  postgres -W
Password:
psql (15.2)
Type "help" for help.

postgres=> exit

都没问题

从库检查:

[postgres@postgres02 data]$ cat postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
logging_collector = 'on'
# wal_level = 'archive'
force_parallel_mode = 'on'
synchronous_commit = 'on'
wal_sender_timeout = '6000'
synchronous_standby_names = ''
archive_mode = 'on'
wal_keep_size = '1024'
max_slot_wal_keep_size = '1024'

# Recovery settings generated by pgBackRest restore on 2023-12-13 02:18:46
# restore_command = 'pgbackrest --stanza=test archive-get %f "%p"'
recovery_target_time = '2023-12-13 01:40:52+08'
# recovery_target_action = 'promote'
primary_conninfo = 'user=repl password=111111 channel_binding=disable host=192.168.99.150 port=1922 sslmode=disable sslcompression=0 sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=disable krbsrvname=postgres target_session_attrs=any'


postgres=# select pg_is_in_recovery() ;
 pg_is_in_recovery
-------------------
 t
(1 row)

postgres@postgres02 ~]$ ps -ef | grep -i post
root      1658  1590  0 09:22 pts/0    00:00:00 su - postgres
postgres  1659  1658  0 09:22 pts/0    00:00:00 -bash
postgres  1762     1  0 09:22 ?        00:00:00 /usr/local/pgsql15.2/bin/postgres
postgres  1770  1762  0 09:22 ?        00:00:00 postgres: logger
postgres  1771  1762  0 09:22 ?        00:00:00 postgres: checkpointer
postgres  1772  1762  0 09:22 ?        00:00:00 postgres: background writer
postgres  1773  1762  0 09:22 ?        00:00:00 postgres: startup recovering 00000003000000070000009C
postgres  1864  1659  0 09:23 pts/0    00:00:00 ps -ef
postgres  1865  1659  0 09:23 pts/0    00:00:00 -bash

从库看上似乎正常,就是没有启动复制进程

检查检查postgresql.conf 发现,恢复文件自带参数:
recovery_target_time = ‘2023-12-13 01:40:52+08’

将参数屏蔽,然后重启服务器后,复制就正常了

postgres=# select * from pg_stat_wal_receiver  ;
-[ RECORD 1 ]---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pid                   | 24770
status                | streaming
receive_start_lsn     | 7/9C000000
receive_start_tli     | 3
written_lsn           | 7/A4000060
flushed_lsn           | 7/A4000060
received_tli          | 3
last_msg_send_time    | 2025-03-11 10:48:52.235255+08
last_msg_receipt_time | 2025-03-11 10:48:50.653625+08
latest_end_lsn        | 7/A4000060
latest_end_time       | 2025-03-11 10:47:46.071326+08
slot_name             |
sender_host           | 192.168.99.150
sender_port           | 1922
conninfo              | user=repl password=******** channel_binding=disable dbname=replication host=192.168.99.150 port=1922 application_name=standby_node fallback_application_name=walreceiver sslmode=disable sslcompression=0 sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=disable krbsrvname=postgres target_session_attrs=any


相关文章:

  • 从0到1入门Docker
  • word毕业论文“et al.”替换为“等”——宏
  • 爱迪斯通科技携手北京晨光溢海参展2025年北京教育装备展
  • MySQL:MySQL库和表的基本操作
  • Vue Amazing UI插件推荐
  • 【二分算法】-- x的平⽅根(easy)
  • @ComponentScan和@SpringBootApplication的scanBasePackages 同时使用
  • 面试模拟舱Pro:AI赋能的求职训练革命
  • DICOM Query/Retrieve(QR)详解与实现
  • 【Java】反射与动态代理篇
  • DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加列宽调整功能,示例Table14_03可调整列宽的固定表头表格
  • 机器学习与深度学习算法及工具在图像分类中的应用总结
  • 移动Android和IOS自动化中常见问题
  • NPM安装与配置全流程详解(2025最新版)
  • Nginx的流式响应配置详解
  • 【每日学点HarmonyOS Next知识】状态变量、动画UI残留、Tab控件显示、ob前缀问题、文字背景拉伸
  • 【网络编程】HTTP网络编程
  • 前后端+数据库的项目实战--学生信息管理系统-易
  • Cesium 入门教程(基于 vue3)
  • Linux学习(十五)(故障排除(ICMP,Ping,Traceroute,网络统计,数据包分析))
  • 又一例!易方达基金张坤卸任副总职务,将专注于投资管理工作
  • 刘小涛任江苏省委副书记
  • 张国清将赴俄罗斯举行中俄“长江—伏尔加河”地方合作理事会第五次会议和“东北—远东”政府间合作委员会双方主席会晤
  • 舱位已排到月底,跨境电商忙补货!美线订单大增面临爆舱,6月运价或翻倍
  • 泽连斯基与埃尔多安会面,称已决定派遣代表团前往伊斯坦布尔
  • 陕西省安康市汉阴县县长陈永乐已任汉阴县委书记