pgx_ulid

ulid type and methods

Overview

PackageVersionCategoryLicenseLanguage
pgx_ulid0.2.3FUNCMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
4510pgx_ulidNoYesYesYesNoNo-
Relatedpg_idkit pg_uuidv7 sequential_uuids uuid-ossp pg_hashids permuteseq

shared_preload_libraries = pgx_ulid is only required for gen_monotonic_ulid(); other functions work without it.

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.2.31817161514pgx_ulid-
RPMPIGSTY0.2.31817161514pgx_ulid_$v-
DEBPIGSTY0.2.31817161514postgresql-$v-pgx-ulid-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u22.x86_64
u22.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
u24.x86_64
u24.aarch64
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3
PIGSTY 0.2.3

Build

You can build the RPM / DEB packages for pgx_ulid using pig build:

pig build pkg pgx_ulid         # build RPM / DEB packages

Install

You can install pgx_ulid directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

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

Install the extension using pig or apt/yum/dnf:

pig install pgx_ulid;          # Install for current active PG version
pig ext install -y pgx_ulid -v 18  # PG 18
pig ext install -y pgx_ulid -v 17  # PG 17
pig ext install -y pgx_ulid -v 16  # PG 16
pig ext install -y pgx_ulid -v 15  # PG 15
pig ext install -y pgx_ulid -v 14  # PG 14
dnf install -y pgx_ulid_18       # PG 18
dnf install -y pgx_ulid_17       # PG 17
dnf install -y pgx_ulid_16       # PG 16
dnf install -y pgx_ulid_15       # PG 15
dnf install -y pgx_ulid_14       # PG 14
apt install -y postgresql-18-pgx-ulid   # PG 18
apt install -y postgresql-17-pgx-ulid   # PG 17
apt install -y postgresql-16-pgx-ulid   # PG 16
apt install -y postgresql-15-pgx-ulid   # PG 15
apt install -y postgresql-14-pgx-ulid   # PG 14

Preload:

shared_preload_libraries = 'pgx_ulid';

Create Extension:

CREATE EXTENSION pgx_ulid;

Usage

Sources: README, releases

pgx_ulid provides a native ulid type, generators, and casts to and from timestamp and uuid. The README documents binary storage and monotonic ULID support.

Enable the extension

CREATE EXTENSION ulid;
-- or CREATE EXTENSION pgx_ulid; if installed manually under that name

Generate ULIDs

SELECT gen_ulid();
SELECT gen_monotonic_ulid();

gen_monotonic_ulid() needs:

shared_preload_libraries = 'pgx_ulid'

The README explicitly says this preload requirement only affects gen_monotonic_ulid(); the rest of the extension works without it.

Use ulid as a primary key

CREATE TABLE users (
  id ulid NOT NULL DEFAULT gen_ulid() PRIMARY KEY,
  name text NOT NULL
);

SELECT * FROM users
WHERE id = '01ARZ3NDEKTSV4RRFFQ69G5FAV';

Casts and range queries

ALTER TABLE users
ADD COLUMN created_at timestamp GENERATED ALWAYS AS (id::timestamp) STORED;

SELECT * FROM users
WHERE id BETWEEN '2023-09-15'::timestamp::ulid
            AND '2023-09-16'::timestamp::ulid;

The README also documents casts between ulid and uuid.

Caveats

  • Monotonic ULIDs use shared memory plus an LWLock to keep the last generated value.
  • The README notes that monotonic generation can theoretically overflow and raise an error, although it treats this as negligible in practice.
  • Release v0.2.3 is current upstream as of 2026-04-19, but upstream did not publish separate user-facing release notes for it.

Last Modified 2026-04-19: update extension stub docs (9f178c3)