pg_nanoid
pg_nanoid · PostgreSQL extension adding a NanoID type and NanoID generation functions.
Overview
PostgreSQL · 18
Usage
Sources:
pg_nanoid adds a nanoid identifier type plus generators for individual, custom-length, and batched Nano IDs. It is useful for compact application identifiers, but uniqueness remains probabilistic and should still be enforced with a primary key or unique constraint.
Core Workflow
Use nanoid_batch to amortize generation for a set of rows and nanoid_len when an application requires an explicitly chosen length.
Important Objects
nanoidis the extension’s identifier type.nanoid_batch(count)returns rows containing generated IDs.nanoid_len(length)returns a generated text ID of the requested length.
Inspect the installed function signatures before using APIs not shown in the pinned examples; the reviewed package declares version 0.0.0 rather than a stable semantic release.
Caveats
The reviewed manifest enables only the PostgreSQL 18 pgrx feature and requires superuser installation; other server majors need a separately built and tested artifact. The control file marks the extension untrusted and non-relocatable.
Size the identifier length and alphabet for the expected population and risk tolerance, retain database uniqueness constraints, and retry on a rare collision. Do not automatically treat generated IDs as authentication secrets: separately validate entropy source, alphabet, exposure lifetime, comparison, logging, and revocation requirements for security tokens.