Cady Motyka: Introducing Snowflake Sequences in a Postgres Extension

原文英文,约900词,阅读约需4分钟。发表于:

In a PostgreSQL database, sequences provide a convenient way to generate a unique identifier, and are often used for key generation. From the community, PostgreSQL provides functions and SQL language to help manage sequence generation, but the sequences themselves are not without limitations in a multi-master environment. Snowflake sequences from pgEdge work seamlessly in a multi-master PostgreSQL cluster to remove those limitations so your data can thrive at the network edge. Why are Sequences an Issue? In a distributed multi-master database system, sequences can get complicated. Ensuring consistency and uniqueness across the nodes in your cluster is a problem if you use PostgreSQL sequences; the Snowflake extension steps up to automatically mitigate this issue.PostgreSQL sequence values are prepared for assignment in a table in your PostgreSQL database; as each sequence value is used, the next sequence value is incremented. Changes to the next available sequence value are not replicated to the other nodes in your replication cluster. In a simple example, you might have a table on node , with 10 rows, each with a primary key that is assigned a sequence value from 1 to 10; the next prepared sequence value on will be 11. Rows are replicated from  to  without issue until you add a row on . The PostgreSQL sequence value table on  has not been incrementing sequence values in step with the sequence value table on . When you add a row on , it will try to use the next available sequence value ( will be 1 if you haven't added a row on ), and the  will fail because a row with the primary key value of 1 already exists. This disorder can be monitored and corrected by manually coordinating the PostgreSQL sequences between nodes in the cluster, but that quickly becomes complicated and potentially impacts the user experience as you add more nodes to the cluster.  Introducing Snowflake Sequences An alternative to using PostgreSQL sequences is to use a guaranteed unique Snowflake sequence. Snowflake sequences are repre[...]

在分布式多主数据库系统中,使用PostgreSQL序列可能会变得复杂。Snowflake序列可以解决这个问题,确保在集群中的节点之间保持一致性和唯一性。

Cady Motyka: Introducing Snowflake Sequences in a Postgres Extension
相关推荐 去reddit讨论