Skip to content

Snowflake

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

Upstream reference for Snowflake 2.6.1. Mimus 19.0.1 integrates Spock 5.0.15. Compatibility of Snowflake with Mimus is unverified.

Source version

The English source is v2.6.1, pinned at 9506e1bd5c1f. A Chinese edition of this snapshot is available. Check versions and sources before deploying.

Using a Snowflake sequence 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 that simplify creating a new Snowflake sequence or converting an existing sequence.

Continue reading


Upstream source · 9506e1bd5c1f · Copyright (c) 2023–2026, pgEdge, Inc.; portions Copyright the PostgreSQL Global Development Group and The Regents of the University of California. PostgreSQL License.

PG.CENTER edition

All notable changes to the Snowflake extension are documented here.

You can query the following Snowflake functions at the psql command line to return useful information about tables that use Snowflake sequences.