• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created almost 10 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A HA script for PostgreSQL with 2 HOST (one for primary, one for standby), Primary with one VIP, Standby with another VIP. Auto failover and failback.

PostgreSQL_HA_with_primary_standby_2vip

A HA script for PostgreSQL with 2 HOST (one for primary, one for standby), Primary with one VIP, Standby with another VIP. Auto failover and failback.

两台主机, 分别负责primary和standby;

2个虚拟IP, 分别对应primary和standby;

三种状态, primary, standby, primary_standby;

三种状态自由切换:

当1台主机异常时, 另一台主机承担primary_standby角色, 并启动2个虚拟IP.

正常情况下两台主机分别承担primary和standby角色, 分别启动一个虚拟IP.

应用程序连接虚拟IP, 其中一个虚拟IP对应的是primary, 另一个虚拟IP对应的是standby.

虚拟IP和角色的关系固定, 不会变化, 例如192.168.111.130对应primary角色, 那么不管怎么切换, 他们始终在一起(谁是primary,谁就会启动192.168.111.130).

部署视频参考:

http://www.tudou.com/programs/view/bIbZ85SrsHM/

http://www.tudou.com/programs/view/kdRPT6dSp_0/

http://www.tudou.com/programs/view/I6bxk2u3xdY/

=======================================

数据库角色转变和心跳原理 :

  1. 根据文件recovery.conf是否存在检测本地节点角色

    存在(standby), 不存在(master)

  2. 加载NFS对端归档目录

  3. 启动数据库 如果是standby 启动数据库 如果是master 如果其他主机未启动VIPM, 启动数据库

  4. 启动VIP 如果是standby 启动vips 如果是master 如果vipm已被其他节点启动 降级为standby 启动vips 如果vipm没有被其他节点启动 启动vipm

  5. 触发第一次心跳

  6. 循环心跳检测

=======================================

不同的角色, 循环逻辑不同:

======================================= master角色, 循环检查

  1. 网关检查, 反映本地网络状况

  2. 本地心跳检查, 反映本地数据库健康状态

  3. 本地角色对应IP检查

  4. 检查VIPS,PORT,数据库心跳

    如果本地健康,对端不健康

触发切换

1. 主节点fence standby

2. 主节点接管VIPS

3. 主节点转换master_standby角色

======================================= standby角色, 循环检查

  1. 网关检查, 反映本地网络状况

  2. 本地心跳检查, 反映本地数据库健康状态

  3. 本地角色对应IP检查

  4. 检查备延迟, 判断是否允许promote

  5. 检查VIPM,PORT,数据库心跳

如果本地健康,对端不健康

触发切换

1. 备节点fence master

2. 备节点停库

3. 备节点注释restore_command

4. 备节点启动数据库

5. 备节点激活数据库, 修改restore_command

6. 备节点接管VIPM

7. 备节点转换master_standby角色

======================================= master_standby角色, 循环检查

  1. 检查对端数据库心跳

如果对端数据库心跳正常

触发释放vips

1. 释放vips

2. 转换为master角色

图片

架构 架构 架构

主角 主角

备角 备角

主备合一角 主备合一

逻辑 逻辑1 逻辑2 逻辑3 逻辑4

Author : Digoal zhou

Email : [email protected]

Blog : http://blog.163.com/digoal@126/

More Repositories

1

blog

OpenSource,Database,Business,Minds. git clone --depth 1 https://github.com/digoal/blog
PLpgSQL
7,598
star
2

pgsql_admin_script

常用管理脚本
Shell
199
star
3

postgres_exam_lib

PostgreSQL 开放式题库, 搜集自stackoverflow , 社区 , bbs , 微信 , QQ等群体. 帮助大家了解PostgreSQL
53
star
4

sky_postgresql_cluster

PostgreSQL HA via three host, include two postgresql (primary and stream replication standby) and one vote host.
Shell
33
star
5

linux_performance_analyze

Linux's system activity information from sar, this project will use postgresql manage bulk Linux hosts. These hosts registed in postgresql, and every day load it's sar info into postgresql, and use postgresql's SQL analyze the hosts performance, like performance's system activity information and TOP resource consume's hosts, and so on.
Shell
21
star
6

gp_tpch

C
12
star
7

digoal.github.io

blog
Ruby
9
star
8

sysbench

sysbench for pg,mysql,oracle, support parallel load & prepared test & tablespace & UDF
Makefile
9
star
9

database_performance_tuning_cases

This project collect Database performance tuning cases from SKY-MOBI DBA Team. Contain mongoDB, PostgreSQL, Oracle, Redis, and so on... Created by Digoal zhou.
4
star
10

sky_monitor_api_by_postgresql

Use PostgreSQL function provide unique Application monitor interface. applications call postgresql function, send status message to it. nagios read the message from postgresql.
3
star
11

oracle_monitor

When we manage many oracle database, the database's status
Shell
2
star
12

postgresql_archive_cloud

When we have many and many PostgreSQL Databases, these database's wal archive manage will much complex. We must has a simple manage tool to do it, and it can help us find these databases archive history, analyze which database will use more and which database use few storage to record the wal files. And this tool must can manage these infomation and use storage properly.
Shell
2
star
13

postgresql_cloud_database

This project use BIND and PostgreSQL and WEB management TOOL create a large database cloud with PostgreSQL. It's not use OS's Virtual Machine, but Use PostgreSQL's Stream replication failover, so this cloud not depend on Shared Storage and storage's high availability. So it's really a PostgreSQL's cloud system.
2
star
14

postgres_finetuning_kb

PostgreSQL's knowledge base for LLM fine tuning.
1
star
15

VecDB-Exp

C
1
star
16

mongo_fdw

fork and modified by citusdb's mongo_fdw to support unix sock connection.
C
1
star
17

postgresql_docker_builder

Build PostgreSQL (with 200+ extenstions and tools) DuckDB MySQL and so on into One docker image. It used for learn database easily only.
1
star