postgres pgpool PIRT online recovery steps

本文详细介绍了如何使用pgpool-II在PostgreSQL 8.4环境下实现在线恢复,包括设置复制模式、负载均衡、基于PIRT的在线恢复流程、确保SSH无密码互访、配置pcp及脚本命令等关键步骤。通过pgpool控制多个节点完成备份、恢复、重启和加载操作,实现从手动到自动化的恢复过程。
部署运行你感兴趣的模型镜像
postgres+pgpool实现在线恢复,实际上说白了就是手动恢复变成自动恢复。通过调用命令和脚本,pgpool控制多个node实现备份,恢复,重启,加载。
background
postgres 8.4 
pgpool-II 3.4.2
复制模式+load balance
基于PIRT 实现在线恢复
安装好c语言函数
postgres实例都以archmod=on 模式运行
两台机器要实现postgres 用户ssh 无密码互访问
配置好pcp
配置好脚本,命令(脚本和命令参见pgpool手册,不过要小心调试)

from     192.168.0.10 
to          192.168.0.11 
1,准备,查看状态
#su - postgres
-bash-4.1$ psql -p 9999 -h 192.168.0.10 
Password:
psql (8.4.20)
Type "help" for help.

postgres=# show pool_nodes;
node_id |    hostname    | port | status | lb_weight |  role
---------+----------------+------+--------+-----------+--------
0       | 192.168.0.10   | 5433 | 2      | 0.500000  | master
1       | 192.168.0.11 | 5433 | 2      | 0.500000  | slave
(2 rows)
2,打开日志
[root@iZ2864nri9hZ ~]# tail -f /var/log/pgpool/pgpool.log

[root@iZ2864nri9hZ ~]# cd /data/
[root@iZ2864nri9hZ data]# tail -f archive/recovery.log
3,停掉192.168.0.10  的postgres,并删除实例
[root@iZ28bh1trh9Z data]# ./postgrestop.sh
[root@iZ28bh1trh9Z data]# ps -ef |grep postgres
root     26503 26432  0 09:23 pts/1    00:00:00 grep postgres

postgres=# show pool_nodes;
The connection to the server was lost. Attempting reset: Succeeded.
postgres=# show pool_nodes;
node_id |    hostname    | port | status | lb_weight |  role
---------+----------------+------+--------+-----------+--------
0       | 192.168.0.10   | 5433 | 2      | 0.500000  | master
1       | 192.168.0.11  | 5433 | 3      | 0.500000  | slave
(2 rows)
这里看到 pgpool连接会断掉,并且 detatch 1 node 为 status=3
同时,如果有web程序连接pgpool,连接也会断,不过web程序会自动重连,重连需要几秒钟,应该是可以配置的??


删除 pgdata_backup, pgdata.tar.gz
备份pgdata
root@iZ28bh1trh9Z data]# rm -rf pgdata_backup
[root@iZ28bh1trh9Z data]# mv pgdata pgdata_backup
[root@iZ28bh1trh9Z data]# rm pgdata.tar.gz

4,开始 online recovery
退出 pgpool的登录
postgres=# \q

运行命令
[root@iZ2864nri9hZ data]# pcp_recovery_node -d 50 localhost 9898 postgres postgres 1
DEBUG: send: tos="R", len=46
DEBUG: recv: tos="r", len=21, data=AuthenticationOK
DEBUG: send: tos="D", len=6
DEBUG: recv: tos="c", len=20, data=CommandComplete
DEBUG: send: tos="X", len=4
运行过程中要查看
/var/log/pgpool/pgpool.log 
/data/archive/recovery.log

5,结束检查
[root@iZ28bh1trh9Z data]# pwd
/alidata/data
[root@iZ28bh1trh9Z data]# ls
checkpgpool.sh  pgbackup.sh  pgdata  pgdata_backup  pgdata.tar.gz  pgpoolstart.sh  pgstartup.log  postgrestart.sh  postgrestop.sh

[root@iZ28bh1trh9Z data]# ps -ef |grep postgres
root     26550  1020  0 09:38 ?        00:00:00 sshd: postgres [priv]
postgres 26552 26550  0 09:38 ?        00:00:00 sshd: postgres@notty
postgres 26556     1  0 09:38 ?        00:00:00 /usr/bin/postgres -D /data/pgdata
postgres 26561 26556  0 09:38 ?        00:00:00 postgres: logger process
postgres 26577 26556  0 09:38 ?        00:00:00 postgres: writer process
postgres 26578 26556  0 09:38 ?        00:00:00 postgres: wal writer process
postgres 26579 26556  0 09:38 ?        00:00:00 postgres: autovacuum launcher process
postgres 26580 26556  0 09:38 ?        00:00:00 postgres: archiver process   last was 00000002.history
postgres 26581 26556  0 09:38 ?        00:00:00 postgres: stats collector process
postgres 26594 26556  0 09:40 ?        00:00:00 postgres: postgres postgres 192.168.0.10 (35555) idle
root     26609 26432  0 09:48 pts/1    00:00:00 grep postgres


-bash-4.1$ psql -p 9999 -h 192.168.0.10 
Password:
psql (8.4.20)
Type "help" for help.

postgres=# show pool_nodes;
node_id |    hostname    | port | status | lb_weight |  role
---------+----------------+------+--------+-----------+--------
0       | 192.168.0.10   | 5433 | 2      | 0.500000  | master
1       | 192.168.0.11  | 5433 | 2      | 0.500000  | slave
(2 rows)

可以看到 两个node都已经启动

6,清理现场

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值