Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/craigpastro/pg_uuidv7
A Postgres extension to generate v7 UUIDs
https://github.com/craigpastro/pg_uuidv7
postgres postgres-extension postgresql rust uuidv7
Last synced: about 1 month ago
JSON representation
A Postgres extension to generate v7 UUIDs
- Host: GitHub
- URL: https://github.com/craigpastro/pg_uuidv7
- Owner: craigpastro
- License: mit
- Created: 2023-06-29T00:16:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-31T23:33:53.000Z (about 2 months ago)
- Last Synced: 2024-11-01T00:24:11.488Z (about 2 months ago)
- Topics: postgres, postgres-extension, postgresql, rust, uuidv7
- Language: Rust
- Homepage:
- Size: 201 KB
- Stars: 29
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg_uuidv7
This is an experimental Postgres extension to generate v7 UUIDs. Created with
[pgrx](https://github.com/tcdi/pgrx), it is a thin wrapper around the Rust
[uuid](https://docs.rs/uuid/latest/uuid/) crate.## Usage
```
postgres=# CREATE EXTENSION pg_uuidv7;
CREATE EXTENSIONpostgres=# SELECT uuid_generate_v7();
uuid_generate_v7
--------------------------------------
018c5732-17b3-7451-b61a-223e7ee65241
(1 row)postgres=# SELECT uuid_v7_to_timestamptz('018c5732-17b3-7451-b61a-223e7ee65241');
uuid_v7_to_timestamptz
----------------------------
2023-12-10 20:45:49.875-08
(1 row)
```## Docker
You can spin up a Postgres container with the `pg_uuidv7` extension installed
with `docker compose up -d`. Once the DB is up, you can connect to it using the
following connection string:```
postgres://postgres:password@localhost:28801/postgres
```## Installation
Requires [pgrx](https://github.com/pgcentralfoundation/pgrx). If you have `pgrx` installed then
```
cargo pgrx run pg16
```should drop you into a psql prompt:
```
psql (16.0)
Type "help" for help.pg_uuidv7=# CREATE EXTENSION pg_uuidv7;
CREATE EXTENSION
```## Benchmark
Benchmarks were run on my 2023 Apple MacBook Pro with an M2 Pro chip and 16GB of
memory.The benchmark I ran was
```console
$ pgbench -c 8 -j 8 -t 200000 -f ${TEST}.sql
```which I borrowed from
[fboulnois/pg_uuidv7](https://github.com/fboulnois/pg_uuidv7/blob/main/BENCHMARKS.md).From the results below this extension is faster than the native
`gen_random_uuid()` function.```
-- SELECT gen_random_uuid();
scaling factor: 1
query mode: simple
number of clients: 8
number of threads: 8
maximum number of tries: 1
number of transactions per client: 200000
number of transactions actually processed: 1600000/1600000
number of failed transactions: 0 (0.000%)
latency average = 0.103 ms
initial connection time = 11.973 ms
tps = 77810.710080 (without initial connection time)
``````
-- SELECT uuid_generate_v7();
scaling factor: 1
query mode: simple
number of clients: 8
number of threads: 8
maximum number of tries: 1
number of transactions per client: 200000
number of transactions actually processed: 1600000/1600000
number of failed transactions: 0 (0.000%)
latency average = 0.088 ms
initial connection time = 11.978 ms
tps = 90862.885067 (without initial connection time)
```## See also
- [fboulnois/pg_uuidv7](https://github.com/fboulnois/pg_uuidv7)