pg_slug_gen
pg_slug_gen : Generate cryptographically secure timestamp-based slugs
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4550 | pg_slug_gen
|
pg_slug_gen
|
1.0.0 |
FUNC
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d-r
|
No
|
Yes
|
No
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | pg_hashids
sequential_uuids
uuid-ossp
pg_uuidv7
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
pg_slug_gen |
- |
| RPM | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
pg_slug_gen_$v |
- |
| DEB | PIGSTY
|
1.0.0 |
18
17
16
15
14
|
postgresql-$v-pg-slug-gen |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
el8.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
el9.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
el9.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
el10.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
el10.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
d12.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
d12.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
d13.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
d13.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u22.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u22.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u24.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u24.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u26.x86_64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
u26.aarch64
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
PIGSTY 1.0.0
|
MISS
|
Source
pig build pkg pg_slug_gen; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_slug_gen; # install via package name, for the active PG version
pig install pg_slug_gen -v 18; # install for PG 18
pig install pg_slug_gen -v 17; # install for PG 17
pig install pg_slug_gen -v 16; # install for PG 16
pig install pg_slug_gen -v 15; # install for PG 15Create this extension with:
CREATE EXTENSION pg_slug_gen;Usage
Sources: official PGXN release page, official release README, official release SQL, official release metadata
pg_slug_gen generates timestamp-based slugs with cryptographic randomness. The official 1.0.0 release describes it as a secure, URL-friendly short ID generator where the requested length selects the timestamp precision.
CREATE EXTENSION pg_slug_gen;
SELECT gen_random_slug();
SELECT gen_random_slug(13);Function
gen_random_slug(slug_length int DEFAULT 16) returns text
The release SQL comment and README document these supported values:
10: seconds13: milliseconds16: microseconds, also the default19: nanoseconds
Precision And Format
Each precision maps to a timestamp width and a fixed slug shape:
10digits:5-5format, 11 characters total13digits:6-7format, 14 characters total16digits:8-8format, 17 characters total19digits:9-10format, 20 characters total
The README states the collision-free window is bounded by timestamp precision: at most 1 insert per second, millisecond, microsecond, or nanosecond respectively.
Examples
SELECT gen_random_slug();
SELECT gen_random_slug(10);
SELECT gen_random_slug(16);
CREATE TABLE products (
id serial PRIMARY KEY,
name text NOT NULL,
slug text DEFAULT gen_random_slug() UNIQUE
);How It Works
The official README describes this algorithm:
- take the current timestamp at the chosen precision
- map each digit to a QWERTY-based character bucket
- choose one random character from that bucket with
pg_strong_random() - insert a hyphen at the midpoint
Caveats
- This is a secure short-ID generator, not a text transliteration or title-to-URL slugifier.
- Same-timestamp collisions are still possible; upstream only claims uniqueness when inserts do not exceed one per chosen time unit.
- The official release metadata still points to
https://github.com/fernandoolle/pg_slug_gen, but that repo URL currently returns 404.