展示 HN:Pgconverge – 一个实验性的 Go 语言多主 PostgreSQL 框架
2 分•作者: sobowalebukola•3 个月前
各位 HN:
在过去的几个月里,我一直在构建 pgconverge,这是一个用于操作多主 PostgreSQL 集群的实验性开源框架。
该项目最初是为了更好地理解分布式数据库而进行的学习练习,而不是为了取代 PostgreSQL 现有的复制模型。我的目标是探索如何让多个 PostgreSQL 节点独立接受写入,并最终在不依赖指定主数据库的情况下实现数据收敛。随着时间的推移,这个实验演变成了一个可用的开源框架。
我探索的一些领域包括:
* 全网状复制拓扑
* 使用“最后写入者获胜”(Last-Write-Wins)进行冲突解决
* 使用混合逻辑时钟(Hybrid Logical Clocks)对并发写入进行排序
* 将新节点引导到现有集群中
* 声明式集群配置
GitHub 链接:[https://github.com/sobowalebukola/pgconverge](https://github.com/sobowalebukola/pgconverge)
在此过程中,我在一个七部分的工程系列中记录了设计决策:
* 为什么选择多主?单写数据库的问题
[https://blog.stackademic.com/why-multi-master-the-problem-with-single-writer-databases-548470efe812](https://blog.stackademic.com/why-multi-master-the-problem-with-single-writer-databases-548470efe812)
* pgconverge 内部:驾驭全网状复制的 N × (N − 1) 复杂性
[https://blog.stackademic.com/inside-pgconverge-navigating-the-n-n-1-complexity-of-full-mesh-replication-ad023ab3a308](https://blog.stackademic.com/inside-pgconverge-navigating-the-n-n-1-complexity-of-full-mesh-replication-ad023ab3a308)
* 身份危机:pgconverge 如何使用 UUID、节点名称和分布式主键
[https://blog.stackademic.com/identity-crisis-how-pgconverge-uses-uuids-node-names-and-distributed-primary-keys-ad6797c2e1a7](https://blog.stackademic.com/identity-crisis-how-pgconverge-uses-uuids-node-names-and-distributed-primary-keys-ad6797c2e1a7)
* 最后写入者获胜:最简单的冲突解决及其在 pgconverge 中的局限性
[https://blog.stackademic.com/last-write-wins-the-simplest-conflict-resolution-and-its-limits-in-pgconverge-7b0f160a3b86](https://blog.stackademic.com/last-write-wins-the-simplest-conflict-resolution-and-its-limits-in-pgconverge-7b0f160a3b86)
* pgconverge 与混合逻辑时钟:当物理时钟不够用时
[https://blog.stackademic.com/pgconverge-with-hybrid-logical-clocks-when-wall-clocks-are-not-enough-907d63de5b41](https://blog.stackademic.com/pgconverge-with-hybrid-logical-clocks-when-wall-clocks-are-not-enough-907d63de5b41)
* pgconverge 中引导新节点:pg_basebackup 与 COPY 数据
[https://blog.stackademic.com/bootstrapping-new-nodes-in-pgconverge-pg-basebackup-vs-copy-data-47cc18384024](https://blog.stackademic.com/bootstrapping-new-nodes-in-pgconverge-pg-basebackup-vs-copy-data-47cc18384024)
* 使用 pgconverge 操作多主 PostgreSQL 集群
[https://blog.stackademic.com/operating-multi-master-postgresql-clusters-with-pgconverge-96df7857a91a](https://blog.stackademic.com/operating-multi-master-postgresql-clusters-with-pgconverge-96df7857a91a)
查看原文
Hi HN,<p>Over the past few months I've been building pgconverge, an experimental open-source framework for operating multi-master PostgreSQL clusters.<p>The project started as a learning exercise to better understand distributed databases rather than as an attempt to replace PostgreSQL's existing replication model. My goal was to explore what it would take for multiple PostgreSQL nodes to accept writes independently while eventually converging without relying on a designated primary database. Over time, the experiment evolved into a working open-source framework.<p>Some of the areas I explored include:<p>full-mesh replication topology
conflict resolution using Last-Write-Wins
Hybrid Logical Clocks for ordering concurrent writes
bootstrapping new nodes into an existing cluster
declarative cluster configuration<p>Github Link: <a href="https://github.com/sobowalebukola/pgconverge" rel="nofollow">https://github.com/sobowalebukola/pgconverge</a><p>Along the way I documented the design decisions in a seven-part engineering series:<p>Why Multi-Master? The Problem with Single-Writer Databases<p><a href="https://blog.stackademic.com/why-multi-master-the-problem-with-single-writer-databases-548470efe812" rel="nofollow">https://blog.stackademic.com/why-multi-master-the-problem-wi...</a><p>Inside pgconverge: Navigating the N × (N − 1) Complexity of Full-Mesh Replication<p><a href="https://blog.stackademic.com/inside-pgconverge-navigating-the-n-n-1-complexity-of-full-mesh-replication-ad023ab3a308" rel="nofollow">https://blog.stackademic.com/inside-pgconverge-navigating-th...</a><p>Identity Crisis: How pgconverge Uses UUIDs, Node Names, and Distributed Primary Keys<p><a href="https://blog.stackademic.com/identity-crisis-how-pgconverge-uses-uuids-node-names-and-distributed-primary-keys-ad6797c2e1a7" rel="nofollow">https://blog.stackademic.com/identity-crisis-how-pgconverge-...</a><p>Last-Write-Wins: The Simplest Conflict Resolution and Its Limits in pgconverge<p><a href="https://blog.stackademic.com/last-write-wins-the-simplest-conflict-resolution-and-its-limits-in-pgconverge-7b0f160a3b86" rel="nofollow">https://blog.stackademic.com/last-write-wins-the-simplest-co...</a><p>pgconverge with Hybrid Logical Clocks: When Wall Clocks Are Not Enough<p><a href="https://blog.stackademic.com/pgconverge-with-hybrid-logical-clocks-when-wall-clocks-are-not-enough-907d63de5b41" rel="nofollow">https://blog.stackademic.com/pgconverge-with-hybrid-logical-...</a><p>Bootstrapping New Nodes in pgconverge: pg_basebackup vs COPY Data<p><a href="https://blog.stackademic.com/bootstrapping-new-nodes-in-pgconverge-pg-basebackup-vs-copy-data-47cc18384024" rel="nofollow">https://blog.stackademic.com/bootstrapping-new-nodes-in-pgco...</a><p>Operating Multi-Master PostgreSQL Clusters with pgconverge<p><a href="https://blog.stackademic.com/operating-multi-master-postgresql-clusters-with-pgconverge-96df7857a91a" rel="nofollow">https://blog.stackademic.com/operating-multi-master-postgres...</a>