postgres=# CREATE EXTENSION pg_idkit;
CREATE EXTENSION
postgres=# SELECT idkit_uuidv7_generate();
idkit_uuidv7_generate
--------------------------------------
018c106f-9304-79bb-b5be-4483b92b036c
pg_idkit
is a Postgres extension for generating many popular types of identifiers:
idkit_uuidv6_generate()
uuidv6
UUID v6 (RFC 4122) idkit_uuidv6_generate_uuid()
idkit_uuidv6_extract_timestamptz(TEXT)
UUID v7 idkit_uuidv7_generate()
uuid7
UUID v7 (RFC 4122) idkit_uuidv7_generate_uuid()
idkit_uuidv7_extract_timestamptz(TEXT)
nanoid idkit_nanoid_generate()
nanoid
NanoID, developed by Andrey Sitnik idkit_nanoid_custom_generate_text()
nanoid
NanoID with a custom length and alphabet ksuid idkit_ksuid_generate()
svix-ksuid
Created by Segment idkit_ksuid_extract_timestamptz(TEXT)
idkit_ksuidms_generate()
svix-ksuid
Same as ksuid
but with millisecond precision idkit_ksuidms_extract_timestamptz(TEXT)
ulid idkit_ulid_generate()
ulid
Unique, lexicographically sortable identifiers idkit_ulid_extract_timestamptz(TEXT)
Timeflake idkit_timeflake_generate()
timeflake-rs
Twitter's Snowflake + Instagram's ID + Firebase's PushID idkit_timeflake_extract_timestamptz(TEXT)
PushID idkit_pushid_generate()
pushid
Google Firebase's PushID xid idkit_xid_generate()
xid
XID idkit_xid_extract_timestamptz(TEXT)
cuid (deprecated) idkit_cuid_generate()
cuid
CUID idkit_cuid_extract_timestamptz(TEXT)
cuid2 idkit_cuid2_generate()
cuid2
CUID2
This Postgres extension is made possible thanks to [pgrx
][pgrx].
You can try out pg_idkit
incredibly quickly by using docker
, and a previously released package of pg_idkit
:
docker run \ --rm \ -e POSTGRES_PASSWORD=replace_this \ -p 5432 \ --name pg_idkit \ ghcr.io/vadosware/pg_idkit:0.3.0-pg17.5-alpine3.21.3-amd64
Warning
Currently only amd64 (x86_64) images are present/supported (See pg_idkit
packages).
Work to support more platforms is described in issue #30
Once the postgres server is running, open another shell and connect to the dockerized Postgres instance running on port 5432
:
➜ docker exec -it pg_idkit psql -U postgres psql (17.5) Type "help" for help. postgres=# CREATE EXTENSION pg_idkit; CREATE EXTENSION postgres=# SELECT idkit_uuidv7_generate(); idkit_uuidv7_generate -------------------------------------- 018c106f-9304-79bb-b5be-4483b92b036c (1 row)📃 From Source
To build pg_idkit
from source, clone this repository and run the following:
cargo install cargo-get cargo-pgrx just just package
After running these commands you should see the following directory structure in target/release/pg_idkit-pg17
:
target/release/pg_idkit-pg16
├── home
│ └── <user>
│ └── .pgrx
│ └── 17.5
│ └── pgrx-install
│ ├── lib
│ │ └── postgresql
│ │ └── pg_idkit.so
│ └── share
│ └── postgresql
│ └── extension
│ ├── pg_idkit--0.3.0.sql
│ └── pg_idkit.control
└── usr
├── lib
│ └── postgresql
│ └── pg_idkit.so
└── share
└── postgresql
└── extension
└── pg_idkit.control
24 directories, 8 files
As the installation of the extension into a specific version of postgres uses your local installation of pgrx-managed Postgres by default (normally at $HOME/.pgrx
), cargo pgrx package
reproduces the directory structure in target/release
. You can safely ignore the shorter usr/lib
/user/share
tree.
In the example above, the files you need for a Postgres extension are:
target/release/home/<user>/.pgrx/17.5/pgrx-install/lib/postgresql/pg_idkit.so
target/release/home/<user>/.pgrx/17.5/pgrx-install/share/postgresql/extension/pg_idkit--0.3.0.sql
target/release/home/<user>/.pgrx/17.5/pgrx-install/share/postgresql/extension/pg_idkit.control
Install these files in the relevant folders for your Postgres installation -- note that exactly where these files should go can can differ across linux distributions and containerized environments.
💽 From BinaryIf running a custom version of locally/globally manually installed Postgres, you may download (and verify the checksum of) a shared library version from the releases, and add it as one of your shared_preload_libraries
in postgresql.conf
.
Assuming you have downloaded the pg_idkit-vX.X.X.so
file to /etc/postgresql/extensions
, you might change the file like this:
postgresql.conf
shared_preload_libraries = '/etc/postgresql/extensions/pg_idkit-vX.X.X.so'
Once your postgres instance is started up, you should be able to CREATE EXTENSION
:
postgres=# CREATE EXTENSION pg_idkit;
CREATE EXTENSION
postgres=# SELECT idkit_uuidv7_generate();
idkit_uuidv7_generate
--------------------------------------
018c106f-9304-79bb-b5be-4483b92b036c
🐳 Dockerfile
To use pg_idkit
easily from a containerized environment, you can use the pg_idkit
image, built from postgres
:
docker run \ --rm \ -e POSTGRES_PASSWORD=replace_this \ -p 5432 \ --name pg_idkit \ ghcr.io/vadosware/pg_idkit:0.3.0-pg17.5-alpine3.18-amd64
From another terminal, you can exec into the pg_idkit
container and enable pg_idkit
:
➜ docker exec -it pg_idkit psql -U postgres psql (17.5) Type "help" for help. postgres=# CREATE EXTENSION pg_idkit; CREATE EXTENSION postgres=# SELECT idkit_uuidv7_generate(); idkit_uuidv7_generate -------------------------------------- 018c106f-9304-79bb-b5be-4483b92b036c (1 row)
📦 Debian (RPM)[!WARNING] Currently only amd64 (x86_64) images are present/supported (See
pg_idkit
packages).Work to support more platforms is described in issue #30
RPMs are produced upon every official release of pg_idkit
.
Grab a released version of the RPM (or build one yourself by running just build-rpm
after setting up local development).
For example, with an RPM named pg_idkit-0.3.0-pg17.x86_64.rpm
, you should be able to run:
dnf install pg_idkit-0.3.0-pg17.x86_64.rpm
There are some other projects in the Postgres ecosystem that implement alternative UUID generation mechanisms.
Here are some you may or may not have heard of:
scoville/pgsql-ulid
pg-xid
geckoboard/pgulid
fabiolimace
for generating UUIDv6Interested in contributing on the project? Set up your local development environment w/ docs/local-development.md
.
Contributions are welcome!
If you find a bug or an impovement that should be included in pg_idkit
, create an issue.
If you'd like to contribute code, get started by:
feat: new awesome feature
)pgXX
is not managed by pgrx
If you find this, you're likely using a version of cargo-pgrx
that is too old.
cargo install --locked cargo-pgrx
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4