Postgresql流复制切换的时候遇到的一个小问题

Pg10搭建了流复制主备切换

配置
主库10.10.10.13 pghost4
备库10.10.10.14 pghost5

测试主库出现问题,停止后,备库自动切换成为新主库。老主库现在应该是备库了,启动它验证状态。发现备库启动不起来。通过以下方法,备库启动了。

  1. 新备库通过pg_ctl start启动,出现告警日志。

[[email protected] ~]# su - pg10
[email protected]>pg_ctl start
waiting for server to start....2019-12-20 21:44:10.004 CST [23416] LOG: listening on IPv4 address "0.0.0.0", port 1921
2019-12-20 21:44:10.004 CST [23416] LOG: listening on IPv6 address "::", port 1921
2019-12-20 21:44:10.006 CST [23416] LOG: listening on Unix socket "/tmp/.s.PGSQL.1921"
2019-12-20 21:44:10.014 CST [23417] LOG: database system was shut down in recovery at 2019-12-20 21:33:31 CST
2019-12-20 21:44:10.014 CST [23417] LOG: entering standby mode
2019-12-20 21:44:10.014 CST [23417] FATAL: requested timeline 2 is not a child of this server‘s history
2019-12-20 21:44:10.014 CST [23417] DETAIL: Latest checkpoint is at 0/11000028 on timeline 1, but in the history of the requested timeline, the server forked off from that timeline at 0/C000098.
2019-12-20 21:44:10.015 CST [23416] LOG: startup process (PID 23417) exited with exit code 1
2019-12-20 21:44:10.015 CST [23416] LOG: aborting startup due to startup process failure
2019-12-20 21:44:10.016 CST [23416] LOG: database system is shut down
stopped waiting
pg_ctl: could not start server
Examine the log output.

从上边的意思可以看到,新备库pg_wal目录下的00000002.history 这个跟新主库不一致。

[email protected]>ll
total 273M
-rw------- 1 pg10 pg10 16M Dec 18 22:40 000000010000000000000001
-rw------- 1 pg10 pg10 16M Dec 18 23:01 000000010000000000000002
-rw------- 1 pg10 pg10 16M Dec 18 23:02 000000010000000000000003
-rw------- 1 pg10 pg10 16M Dec 18 23:06 000000010000000000000004
-rw------- 1 pg10 pg10 16M Dec 18 23:39 000000010000000000000005
-rw------- 1 pg10 pg10 16M Dec 18 23:51 000000010000000000000006
-rw------- 1 pg10 pg10 16M Dec 18 23:55 000000010000000000000007
-rw------- 1 pg10 pg10 16M Dec 18 23:58 000000010000000000000008
-rw------- 1 pg10 pg10 16M Dec 19 00:15 000000010000000000000009
-rw------- 1 pg10 pg10 16M Dec 19 00:15 00000001000000000000000A
-rw------- 1 pg10 pg10 16M Dec 19 00:27 00000001000000000000000B
-rw------- 1 pg10 pg10 16M Dec 19 00:29 00000001000000000000000C
-rw------- 1 pg10 pg10 16M Dec 19 00:34 00000001000000000000000D
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000E
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000F
-rw------- 1 pg10 pg10 302 Dec 19 00:36 00000001000000000000000F.00000028.backup
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000010
-rw------- 1 pg10 pg10 16M Dec 20 21:33 000000010000000000000011
-rw------- 1 pg10 pg10 41 Dec 19 00:30 00000002.history
drwx------ 2 pg10 pg10 4.0K Dec 20 21:31 archive_status
[email protected]>more 00000002.history
1 0/C000098 no recovery target specified
[email protected]>

然后看新主库该路径下的目录

[email protected]>ll
total 132K
-rw------- 1 pg10 pg10 206 Dec 19 00:36 backup_label.old
drwx------ 5 pg10 pg10 4.0K Dec 19 00:36 base
drwx------ 2 pg10 pg10 4.0K Dec 20 21:27 global
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_commit_ts
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_dynshmem
-rw------- 1 pg10 pg10 4.6K Dec 19 00:36 pg_hba.conf
-rw------- 1 pg10 pg10 1.6K Dec 19 00:36 pg_ident.conf
drwx------ 4 pg10 pg10 4.0K Dec 19 00:38 pg_logical
drwx------ 4 pg10 pg10 4.0K Dec 19 00:36 pg_multixact
drwx------ 2 pg10 pg10 4.0K Dec 19 00:37 pg_notify
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_replslot
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_serial
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_snapshots
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_stat
drwx------ 2 pg10 pg10 4.0K Dec 20 21:48 pg_stat_tmp
drwx------ 2 pg10 pg10 4.0K Dec 19 00:38 pg_subtrans
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_tblspc
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_twophase
-rw------- 1 pg10 pg10 3 Dec 19 00:36 PG_VERSION
drwx------ 3 pg10 pg10 4.0K Dec 19 00:38 pg_wal
drwx------ 2 pg10 pg10 4.0K Dec 19 00:36 pg_xact
-rw------- 1 pg10 pg10 88 Dec 19 00:36 postgresql.auto.conf
-rw------- 1 pg10 pg10 23K Dec 19 00:36 postgresql.conf
-rw------- 1 pg10 pg10 31 Dec 19 00:37 postmaster.opts
-rw------- 1 pg10 pg10 74 Dec 19 00:38 postmaster.pid
-rw-r--r-- 1 pg10 pg10 5.8K Dec 19 00:37 recovery.done
[email protected]>cd pg_wal/br/>[email protected]>ll
total 65M
-rw------- 1 pg10 pg10 16M Dec 19 00:36 00000001000000000000000F
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000010
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000010000000000000011.partial
-rw------- 1 pg10 pg10 16M Dec 19 00:38 000000020000000000000011
-rw------- 1 pg10 pg10 42 Dec 19 00:38 00000002.history
drwx------ 2 pg10 pg10 4.0K Dec 19 00:38 archive_statusbr/>[email protected]>pwd
/data/pg10/data/pg_wal
[email protected]>more 00000002.history
1 0/11000098 no recovery target specified

将新备库的00000002.history 备份,然后删除。
将新主库的传递到新备库。
然后启动。
[email protected]>scp 00000002.history 10.10.10.13:/data/pg10/data/pg_wal/
[email protected]‘s password:
00000002.history 100% 42 0.0KB/s 00:00
[email protected]>

[email protected]>pg_ctl start
waiting for server to start....2019-12-20 21:51:25.142 CST [23486] LOG: listening on IPv4 address "0.0.0.0", port 1921
2019-12-20 21:51:25.142 CST [23486] LOG: listening on IPv6 address "::", port 1921
2019-12-20 21:51:25.144 CST [23486] LOG: listening on Unix socket "/tmp/.s.PGSQL.1921"
2019-12-20 21:51:25.155 CST [23487] LOG: database system was shut down in recovery at 2019-12-20 21:33:31 CST
2019-12-20 21:51:25.155 CST [23487] LOG: entering standby mode
2019-12-20 21:51:25.171 CST [23487] LOG: consistent recovery state reached at 0/11000098
2019-12-20 21:51:25.171 CST [23487] LOG: invalid record length at 0/11000098: wanted 24, got 0
2019-12-20 21:51:25.171 CST [23486] LOG: database system is ready to accept read only connections
2019-12-20 21:51:25.179 CST [23491] LOG: started streaming WAL from primary at 0/11000000 on timeline 2
2019-12-20 21:51:25.225 CST [23487] LOG: redo starts at 0/11000098
done
server started
[email protected]>

发现已经启动。

[email protected]>pg_controldata|grep cluster
Database cluster state: in archive recovery
[email protected]>

可以看到新备库处于备库模式。

Postgresql流复制切换的时候遇到的一个小问题

原文地址:https://blog.51cto.com/lishiyan/2460518

时间: 2024-12-14 09:51:44

Postgresql流复制切换的时候遇到的一个小问题的相关文章

Postgresql流复制+pgpool实现高可用

pgpool 概述 pgpool-II 是一个位于 PostgreSQL 服务器和 PostgreSQL 数据库客户端之间的中间件,它提供以下功能:连接池.复制.负载均衡.限制超过限度的连接以及并行查询.文档在此. 四种模式 O 意味着“可用”, X 意味着“不可用(1) 并行查询模式需要同时打开复制和负载均衡,但是复制和负载均衡无法用于并行查询模式中的分布式表.(2) 在线恢复可以和流复制同时使用.(*3) 客户端仅仅是通过 pgpool-II 连接到 PostgreSQL服务器.这种模式仅仅

PostgreSQL流复制

原理机制 参考--https://yq.aliyun.com/articles/51009 主备总体结构 PG主备流复制的核心部分由walsender,walreceiver和startup三个进程组成. walsender进程是用来发送WAL日志记录的 walreceiver进程是用来接收WAL日志记录的 startup进程是用来apply日志的 配置环境 主机名 IP地址 角色 数据目录 postgres202 192.168.1.202 primary /home/postgres/dat

postgresql 流复制(streaming replication)

基本环境说明: os:FreeBSD 9.3 postgresql version:9.3.6 master:192.168.56.101 standby:192.168.56.102 安装过程略,基于pkg包 1.配置master端 # psql -U pgsql -d postgres -c "CREATE USER rep REPLICATION LOGIN ENCRYPTED PASSWORD 'password';" # cd /usr/local/pgsql # vim d

【Postgresql】postgresql9.3.9版本基于流复制方式双机热备方案

系统环境:centos6.5数据库版本: postgres9.3.9虚拟机2台:Master:10.0.2.160Slave:10.0.2.69数据存储位置:/usr/local/pgsql/data/ 安装pgsql数据库 安装过程可参考我上一篇博客:http://blog.51cto.com/13632960/2117902 两台机器都需要安装完成,我在做热备的时候,Master数据库开启,Slave关闭. 创建流复制用户 Master端进入数据库并执行: CREATE USER repus

Postgresql9 PPAS9流复制配置

PostgreSQL流复制集群搭建,这个是翻的陈年旧档 主机: PPAS1 PPAS2 1 安装PPAS 9.0 [[email protected] ~]# setenforce 0 [[email protected] ~]# ppasmeta-9.0.4.14-linux-x64.run--全部安装 [[email protected] ~]# vim /etc/bashrc 加入: PATH=$PATH:/opt/PostgresPlus/9.0AS/binexport PATH --L

金庸武功之“”左右互搏术“”postgresql 主从异步流复制配置

一.环境准备 a.关闭selinxu b.关闭iptables c.centos6.5 d.postgresql9.4.4 master:192.168.1.211 slave:  192.168.1.212 时间同步: #同步系统时间 [[email protected] ~]#  rm  -rf  /etc/localtime [[email protected] ~]#  ln  -s   /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

corosync+pacemaker实现pg流复制自动切换

一.环境 $ cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) node1: 192.168.111.128 node2: 192.168.111.129 vip-master: 192.168.111.228 vip-slave: 192.168.111.229 配置主机名 hostnamectl set-hostname postgres128 hostnamectl set-hostname postgres129 [

PGPool-II+PG流复制实现HA主备切换

基于PGPool的双机集群如下图所示:pg主节点和备节点实现流复制热备,pgpool1,pgpool2作为中间件,将主备pg节点加入集群,实现读写分离,负载均衡和HA故障自动切换.两pgpool节点可以委托一个虚拟ip节点作为应用程序访问的地址,两节点之间通过watchdog进行监控,当pgpool1宕机时,pgpool2会自动接管虚拟ip继续对外提供不间断服务. 1. 主机规划 192.168.20.201 redis01 192.168.20.202 redis02 192.168.20.2

postgresql异步流复制搭建

节点 IP 角色 citus-master 10.10.100.1 master citus-standby 10.10.100.2 standby master上创建流复制所需要的用户. CREATE ROLE replication WITH REPLICATION PASSWORD 'replication' LOGIN; 修改master的pg_hba.conf文件,设置replication用户远程访问权限 ## vim /data/pgsql/data/pg_hba.conf,追加下