snowflake
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
snowflake | 2.5.0 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4590 | snowflake | No | Yes | No | Yes | No | No | snowflake |
works on pgedge kernel fork. Set snowflake.node (1..1023) before using snowflake.nextval().
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.5.0 | 1817161514 | snowflake | - |
| RPM | PIGSTY | 18.4 | 1817161514 | pgedge-$v | - |
| DEB | PIGSTY | 18.4 | 1817161514 | pgedge-$v | - |
Build
You can build the RPM / DEB packages for snowflake using pig build:
Install
You can install snowflake directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
- snowflake v2.5.0 README
- Creating a Snowflake sequence
- Converting PostgreSQL sequences
- Function reference
- v2.5.0 changelog
snowflake generates distributed bigint identifiers from a timestamp, a per-node identifier, and an in-millisecond counter. Existing PostgreSQL sequences can be converted so table defaults continue using nextval(...) while producing Snowflake IDs.
Configuration
Assign every writable node a distinct identifier in postgresql.conf, then reload PostgreSQL:
Reusing a node identifier on concurrently writable servers can generate duplicate IDs.
Convert a Sequence
Create a normal PostgreSQL sequence, then convert its definition. Existing values in referencing columns are not rewritten.
Functions
| Function | Description |
|---|---|
snowflake.nextval([sequence regclass]) | Generate the next Snowflake ID (uses internal sequence if none specified) |
snowflake.currval([sequence regclass]) | Return the current value of the sequence |
snowflake.get_epoch(snowflake int8) | Extract the timestamp as epoch (seconds since 2023-01-01) |
snowflake.get_count(snowflake int8) | Extract the count part (resets per millisecond) |
snowflake.get_node(snowflake int8) | Extract the node identifier |
snowflake.format(snowflake int8) | Return a JSONB with node, ts, and count fields |
Examples
Review and Upgrade
Review converted table defaults with psql \d+ or the PostgreSQL catalogs. They should call snowflake.nextval(...) rather than the original nextval(...):
Version 2.5.0 fixes dump/restore of converted sequences whose MAXVALUE was left at the normal bigint maximum. It also repairs conversion SQL for affected sequences and adds PostgreSQL 18 support.
Caveats
- Conversion changes the sequence definition, not IDs already stored in table rows.
- A Snowflake generator can emit at most 4096 counter values per millisecond. Do not configure a sequence increment above 4096.
- Keep the node identifier stable and unique for the lifetime of concurrent writers; record it as part of cluster provisioning and failover procedures.
- Install the same extension version on every node before logical replication or rolling changes involving converted sequence definitions.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)