Contents
Benchmarks
Summary
On average, pg_uuidv7 is as fast as the native gen_random_uuid() function in
Postgres. In a worst case scenario it was up to 2% slower, however run-to-run
variations of pgbench were ~2%, which likely means that in a real system the
performance impact of pg_uuidv7 is negligible.
Methods
Performance benchmarks were evaluated using Postgres 19 and pgbench. The
following functions were benchmarked:
- the native
gen_random_uuid()function which is built in since Postgres 13 - the
uuid_generate_v7()function from this extension (pg_uuidv7) - a pure sql version of
uuid_generate_v7()from kjmph - the native
uuidv7()function which is built in since Postgres 18
See the benchmark directory for the implementation.
Results
pgbench --client=8 --jobs=8 --transactions=200000 --file=${TEST}.sql
-- 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.128 ms
initial connection time = 4.532 ms
tps = 62278.158388 (without initial connection time)
-- pg_uuidv7 C extension
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.129 ms
initial connection time = 4.190 ms
tps = 61887.672250 (without initial connection time)
-- sql function r28
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.138 ms
initial connection time = 4.224 ms
tps = 57876.656670 (without initial connection time)
-- SELECT uuidv7();
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.129 ms
initial connection time = 4.339 ms
tps = 62145.899462 (without initial connection time)