# Snowflake

> Using a Snowflake sequence allows you to take full advantage of the benefits offered by a distributed, multi-master replication solution.

---

LLMS index: [llms.txt](/llms.txt)

---

> Upstream reference for Snowflake 2.6.1. Mimus 19.0.1 integrates [Spock 5.0.15](/docs/spock/). Compatibility of Snowflake with Mimus is unverified.

> [!NOTE] Source version
> The English source is **v2.6.1**, pinned at `9506e1bd5c1f`. A Chinese edition of this snapshot is available. Check [versions and sources](/docs/spock/upstream/about/attribution/) before deploying.


Using a [`Snowflake` sequence](https://github.com/pgEdge/snowflake?tab=readme-ov-file#snowflake-sequences-for-postgresql) allows you to take full advantage of the benefits offered by a distributed, multi-master replication solution. Snowflake is a Postgres extension that provides an int8 and sequence based unique ID solution to optionally replace the Postgres built-in bigserial data type. 

Internally, snowflakes are 64 bit integers represented externally as bigint values. The 64 bits are divided into bit fields:

* bit  63    - unused (sign of int8)
* bits 22-62 - timestamp with millisecond precision
* bits 12-21 - unique pgEdge Distributed Postgres node number
* bits 0-11   - counter within one millisecond
* The timestamp is a 41-bit unsigned value representing millisecond precision and an epoch of 2023-01-01.
* The counter is a 12-bit unsigned value that increments per ID allocation. This provides for 4096 unique IDs per millisecond, or 4 million IDs per second.
* The node number is a 10-bit unique identifier for the Postgres instance inside a global cluster. This value is set with the `snowflake.node` GUC in the `postgresql.conf` file.

Snowflake sequences let you:

* add or modify data in different regions while ensuring a unique transaction sequence.
* preserve unique transaction identifiers without manual/administrative management of a numbering scheme.
* compare ID generation times across nodes. Clock skew and the interval between ID generation and commit can affect the observed order.

Snowflake sequences also alleviate concerns that network lag could disrupt sequences in distributed transactions.

A Snowflake sequence is made up of a timestamp, a counter, and a unique node identifier; these components are sized to ensure over 18 trillion unique sequence numbers. The extension supports versatile commands and [functions](/docs/spock/upstream/snowflake/snowflake-functions/) that simplify [creating a new Snowflake sequence](/docs/spock/upstream/snowflake/creating/) or [converting an existing sequence](/docs/spock/upstream/snowflake/converting/).

## Continue reading {#continue-reading}

- [Changelog](/docs/spock/upstream/snowflake/changelog/)
- [Converting a PostgreSQL Sequence to a Snowflake Sequence](/docs/spock/upstream/snowflake/converting/)
- [Creating a Snowflake Sequence in a New Cluster](/docs/spock/upstream/snowflake/creating/)
- [Reviewing Sequence Definitions in your Table Meta-data](/docs/spock/upstream/snowflake/review-seq/)
- [Snowflake Functions](/docs/spock/upstream/snowflake/snowflake-functions/)

---

[Upstream source](https://github.com/pgEdge/snowflake/blob/9506e1bd5c1f8f8c22df43bdc3efd2b00398ddd8/docs/index.md) · `9506e1bd5c1f` · Copyright (c) 2023–2026, pgEdge, Inc.; portions Copyright the PostgreSQL Global Development Group and The Regents of the University of California. [PostgreSQL License](/docs/spock/upstream/about/license/).

[PG.CENTER edition](https://github.com/pgsty/doc.pg.center/blob/4410c32dc9186a22859008303f474b72a779f583/content/pgedge/snowflake/_index.md)

---

Section pages:

- [Changelog](/docs/spock/upstream/snowflake/changelog/): All notable changes to the Snowflake extension are documented here.
- [Converting a PostgreSQL Sequence to a Snowflake Sequence](/docs/spock/upstream/snowflake/converting/): You cannot directly create a snowflake sequence; you must first create a sequence in Postgres and then convert it.
- [Creating a Snowflake Sequence in a New Cluster](/docs/spock/upstream/snowflake/creating/): Before you use Snowflake sequences, each node in your cluster must have a unique snowflake.node identifier.
- [Reviewing Sequence Definitions in your Table Meta-data](/docs/spock/upstream/snowflake/review-seq/): If you query the table meta-data before performing a sequence conversion with the \d+ orders command, the PostgreSQL sequence is defined in the Default column:
- [Snowflake Functions](/docs/spock/upstream/snowflake/snowflake-functions/): You can query the following Snowflake functions at the psql command line to return useful information about tables that use Snowflake sequences.

---

Backlinks:

- [pgEdge · Spock](/docs/spock/)
- [pgEdge upstream manuals](/docs/spock/upstream/)
