Skip to content

pg_slug_gen

Generate cryptographically secure timestamp-based slugs

pg_slug_gen · Generate cryptographically secure timestamp-based slugs

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4560pg_slug_genpg_slug_gen1.0.0FUNCMITC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.0.019 18 17 16 15pg_slug_gen-
RPMPIGSTY1.0.019 18 17 16 15pg_slug_gen_$v-
DEBPIGSTY1.0.019 18 17 16 15postgresql-$v-pg-slug-gen-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el8.aarch64N/APIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el9.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el9.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el10.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
el10.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d12.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d12.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d13.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
d13.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u22.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u22.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u24.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u24.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u26.x86_64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
u26.aarch64PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0PIGSTY 1.0.0
PackageVersionOSORGSIZEFile URL
pg_slug_gen_191.0.0el9.x86_64pigsty21.1 KiBpg_slug_gen_19-1.0.0-1PGSTY.el9.x86_64.rpm
pg_slug_gen_191.0.0el9.aarch64pigsty21.2 KiBpg_slug_gen_19-1.0.0-1PGSTY.el9.aarch64.rpm
pg_slug_gen_191.0.0el10.x86_64pigsty21.1 KiBpg_slug_gen_19-1.0.0-1PGSTY.el10.x86_64.rpm
pg_slug_gen_191.0.0el10.aarch64pigsty21.2 KiBpg_slug_gen_19-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-slug-gen1.0.0d12.x86_64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-slug-gen1.0.0d12.aarch64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-slug-gen1.0.0d13.x86_64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-slug-gen1.0.0d13.aarch64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-slug-gen1.0.0u22.x86_64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-slug-gen1.0.0u22.aarch64pigsty12.1 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-slug-gen1.0.0u24.x86_64pigsty12.4 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-slug-gen1.0.0u24.aarch64pigsty12.2 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-slug-gen1.0.0u26.x86_64pigsty12.5 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-slug-gen1.0.0u26.aarch64pigsty12.5 KiBpostgresql-19-pg-slug-gen_1.0.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_slug_gen_181.0.0el8.x86_64pigsty20.8 KiBpg_slug_gen_18-1.0.0-1PGSTY.el8.x86_64.rpm
pg_slug_gen_181.0.0el8.aarch64pigsty20.9 KiBpg_slug_gen_18-1.0.0-1PGSTY.el8.aarch64.rpm
pg_slug_gen_181.0.0el9.x86_64pigsty21.1 KiBpg_slug_gen_18-1.0.0-1PGSTY.el9.x86_64.rpm
pg_slug_gen_181.0.0el9.aarch64pigsty21.2 KiBpg_slug_gen_18-1.0.0-1PGSTY.el9.aarch64.rpm
pg_slug_gen_181.0.0el10.x86_64pigsty21.2 KiBpg_slug_gen_18-1.0.0-1PGSTY.el10.x86_64.rpm
pg_slug_gen_181.0.0el10.aarch64pigsty21.2 KiBpg_slug_gen_18-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-slug-gen1.0.0d12.x86_64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-slug-gen1.0.0d12.aarch64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-slug-gen1.0.0d13.x86_64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-slug-gen1.0.0d13.aarch64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-slug-gen1.0.0u22.x86_64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-slug-gen1.0.0u22.aarch64pigsty12.1 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-slug-gen1.0.0u24.x86_64pigsty12.4 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-slug-gen1.0.0u24.aarch64pigsty12.2 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-slug-gen1.0.0u26.x86_64pigsty12.5 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-slug-gen1.0.0u26.aarch64pigsty12.5 KiBpostgresql-18-pg-slug-gen_1.0.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_slug_gen_171.0.0el8.x86_64pigsty20.8 KiBpg_slug_gen_17-1.0.0-1PGSTY.el8.x86_64.rpm
pg_slug_gen_171.0.0el8.aarch64pigsty20.9 KiBpg_slug_gen_17-1.0.0-1PGSTY.el8.aarch64.rpm
pg_slug_gen_171.0.0el9.x86_64pigsty21.0 KiBpg_slug_gen_17-1.0.0-1PGSTY.el9.x86_64.rpm
pg_slug_gen_171.0.0el9.aarch64pigsty21.1 KiBpg_slug_gen_17-1.0.0-1PGSTY.el9.aarch64.rpm
pg_slug_gen_171.0.0el10.x86_64pigsty21.1 KiBpg_slug_gen_17-1.0.0-1PGSTY.el10.x86_64.rpm
pg_slug_gen_171.0.0el10.aarch64pigsty21.1 KiBpg_slug_gen_17-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-slug-gen1.0.0d12.x86_64pigsty12.1 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-slug-gen1.0.0d12.aarch64pigsty12.1 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-slug-gen1.0.0d13.x86_64pigsty12.0 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-slug-gen1.0.0d13.aarch64pigsty12.0 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-slug-gen1.0.0u22.x86_64pigsty12.4 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-slug-gen1.0.0u22.aarch64pigsty12.4 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-slug-gen1.0.0u24.x86_64pigsty12.3 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-slug-gen1.0.0u24.aarch64pigsty12.2 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-slug-gen1.0.0u26.x86_64pigsty12.4 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-slug-gen1.0.0u26.aarch64pigsty12.5 KiBpostgresql-17-pg-slug-gen_1.0.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_slug_gen_161.0.0el8.x86_64pigsty20.8 KiBpg_slug_gen_16-1.0.0-1PGSTY.el8.x86_64.rpm
pg_slug_gen_161.0.0el8.aarch64pigsty20.9 KiBpg_slug_gen_16-1.0.0-1PGSTY.el8.aarch64.rpm
pg_slug_gen_161.0.0el9.x86_64pigsty21.0 KiBpg_slug_gen_16-1.0.0-1PGSTY.el9.x86_64.rpm
pg_slug_gen_161.0.0el9.aarch64pigsty21.1 KiBpg_slug_gen_16-1.0.0-1PGSTY.el9.aarch64.rpm
pg_slug_gen_161.0.0el10.x86_64pigsty21.1 KiBpg_slug_gen_16-1.0.0-1PGSTY.el10.x86_64.rpm
pg_slug_gen_161.0.0el10.aarch64pigsty21.1 KiBpg_slug_gen_16-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-slug-gen1.0.0d12.x86_64pigsty12.1 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-slug-gen1.0.0d12.aarch64pigsty12.1 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-slug-gen1.0.0d13.x86_64pigsty12.0 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-slug-gen1.0.0d13.aarch64pigsty12.1 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-slug-gen1.0.0u22.x86_64pigsty12.4 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-slug-gen1.0.0u22.aarch64pigsty12.4 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-slug-gen1.0.0u24.x86_64pigsty12.3 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-slug-gen1.0.0u24.aarch64pigsty12.2 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-slug-gen1.0.0u26.x86_64pigsty12.4 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-slug-gen1.0.0u26.aarch64pigsty12.5 KiBpostgresql-16-pg-slug-gen_1.0.0-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_slug_gen_151.0.0el8.x86_64pigsty20.8 KiBpg_slug_gen_15-1.0.0-1PGSTY.el8.x86_64.rpm
pg_slug_gen_151.0.0el8.aarch64pigsty20.9 KiBpg_slug_gen_15-1.0.0-1PGSTY.el8.aarch64.rpm
pg_slug_gen_151.0.0el9.x86_64pigsty21.1 KiBpg_slug_gen_15-1.0.0-1PGSTY.el9.x86_64.rpm
pg_slug_gen_151.0.0el9.aarch64pigsty21.1 KiBpg_slug_gen_15-1.0.0-1PGSTY.el9.aarch64.rpm
pg_slug_gen_151.0.0el10.x86_64pigsty21.1 KiBpg_slug_gen_15-1.0.0-1PGSTY.el10.x86_64.rpm
pg_slug_gen_151.0.0el10.aarch64pigsty21.1 KiBpg_slug_gen_15-1.0.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-slug-gen1.0.0d12.x86_64pigsty12.1 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-slug-gen1.0.0d12.aarch64pigsty12.1 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-slug-gen1.0.0d13.x86_64pigsty12.0 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-slug-gen1.0.0d13.aarch64pigsty12.0 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-slug-gen1.0.0u22.x86_64pigsty12.4 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-slug-gen1.0.0u22.aarch64pigsty12.4 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-slug-gen1.0.0u24.x86_64pigsty12.3 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-slug-gen1.0.0u24.aarch64pigsty12.2 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-slug-gen1.0.0u26.x86_64pigsty12.4 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-slug-gen1.0.0u26.aarch64pigsty12.5 KiBpostgresql-15-pg-slug-gen_1.0.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_slug_gen;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_slug_gen;		# install by package name

pig install pg_slug_gen -v 19;   # install for PG 19
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 15

Create this extension with:

CREATE EXTENSION pg_slug_gen;

Usage

Sources:

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: seconds
  • 13: milliseconds
  • 16: microseconds, also the default
  • 19: nanoseconds

Precision And Format

Each precision maps to a timestamp width and a fixed slug shape:

  • 10 digits: 5-5 format, 11 characters total
  • 13 digits: 6-7 format, 14 characters total
  • 16 digits: 8-8 format, 17 characters total
  • 19 digits: 9-10 format, 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 PGXN release specifies PostgreSQL 12 as its minimum requirement.

Table reader