Author 晓兵

weixin: ssbandjl

公众号: 云原生云

云原生云

匍匐枝-PostgreSQL云原生高可用方案

stolon - PostgreSQL cloud native High Availability

stolon is a cloud native PostgreSQL manager for PostgreSQL high availability. It’s cloud native because it’ll let you keep an high available PostgreSQL inside your containers (kubernetes integration) but also on every other kind of infrastructure (cloud IaaS, old style infrastructures etc…) 其他基础设施

For an introduction to stolon you can also take a look at this post stolon诞生背景

Features 功能

  • Leverages PostgreSQL streaming replication. 使用PostgrSQL流复制
  • Resilient to any kind of partitioning. While trying to keep the maximum availability, it prefers consistency over availability. 能够适应任何类型的分区. 在试图保持最大可用性的同时,相比可用性, 它更倾向一致性.
  • kubernetes integration letting you achieve postgreSQL high availability. 集成到k8s中, 从而获得高可用
  • Uses a cluster store like etcd, consul or kubernetes API server as an high available data store and for leader election 使用集群存储, 选主
  • Asynchronous (default) and synchronous replication. 支持异步(默认)和同步复制
  • Full cluster setup in minutes. 分分钟部署全套集群
  • Easy cluster administration 使用stolonctl轻松管理集群
  • Can do point in time recovery integrating with your preferred backup/restore tool. 结合您的备份/恢复工具, 支持基于时间点恢复
  • Standby cluster (for multi site replication and near zero downtime migration). 热备集群, 适用于多站点复本和几乎零停机迁移
  • Automatic service discovery and dynamic reconfiguration (handles postgres and stolon processes changing their addresses). 自动服务发现和动态重新配置(处理postgres和stolon进程改变他们的地址)
  • Can use pg_rewind for fast instance resynchronization with current master. 可以使用pg_rewind工具快速与当前主节点同步数据

Architecture 架构

image-20210419181525708

Stolon is composed of 3 main components 三大组件

  • keeper: it manages a PostgreSQL instance converging to the clusterview computed by the leader sentinel. 保持者, 它管理一个PostgreSQL实例,该实例收敛到由哨兵首领计算的集群视图
  • sentinel: it discovers and monitors keepers and proxies and computes the optimal clusterview. 哨兵, 发现并监控保持者和代理, 并计算最佳集群视图
  • proxy: the client’s access point. It enforce connections to the right PostgreSQL master and forcibly closes connections to old masters. 代理, 客户端访问入口, 它强制连接到正确的PostgreSQL主节点,并强制关闭到旧主的连接

For more details and requirements see Stolon Architecture and Requirements

Stolon architecture

Documentation

Documentation Index

Installation

Stolon is available in brew. It is unofficial and not supported by the project. So check the version before installing using brew.

Step to install using brew

Quick start and examples

Project Status

Stolon is under active development and used in different environments. Probably its on disk format (store hierarchy and key contents) will change in future to support new features. If a breaking change is needed it’ll be documented in the release notes and an upgrade path will be provided. 匍匐茎正在积极开发,并在不同的环境中使用。可能它的磁盘格式(存储层次结构和关键内容)将在未来改变以支持新特性。如果需要一个破坏性的变更,它将被记录在发布说明中,并提供一个升级路径。

Anyway it’s quite easy to reset a cluster from scratch keeping the current master instance working and without losing any data. 无论如何,从零开始重置集群非常容易,可以保持当前主实例的工作,而不会丢失任何数据

Requirements

  • PostgreSQL 12, 11, 10 or 9 (9.4, 9.5, 9.6)

  • etcd2 >= v2.0, etcd3 >= v3.0, consul >= v0.6 or kubernetes >= 1.8 (based on the store you’re going to use)

  • OS: currently stolon is tested on GNU/Linux (with reports of people using it also on Solaris, *BSD and Darwin)

build

To build stolon we usually test and support the latest two major versions of Go like in the Go release policy.

make

High availability

Stolon tries to be resilient to any partitioning problem. The cluster view is computed by the leader sentinel and is useful to avoid data loss (one example over all avoid that old dead masters coming back are elected as the new master). 斯托伦试图适应任何分区问题。集群视图是由leader sentinel计算的,可以避免数据丢失(一个例子可以避免旧的死去的主人回来时被选为新的主人)。

There can be tons of different partitioning cases. The primary ones are covered (and in future more will be added) by various integration tests

FAQ

See here for a list of faq. If you have additional questions please ask.

Contributing to stolon

stolon is an open source project under the Apache 2.0 license, and contributions are gladly welcomed! To submit your changes please open a pull request.

Contacts

  • For general discussion about using and developing stolon, join the stolon forum
  • For bugs and feature requests file an issue