pg_oltp_bench
pg_oltp_bench · Helper function and pgbench scripts for a sysbench-style OLTP benchmark.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100141 | pg_oltp_bench | pg_oltp_bench | 1.0 | FEAT | Unknown | C |
Usage
Sources:
- Official extension SQL
- Official initialization script
- Official read-only workload
- Official read-write workload
pg_oltp_bench combines one random-string helper with pgbench scripts that approximate a sysbench-style OLTP workload. It is a benchmark fixture, not an application schema or a standardized score by itself.
Prepare the Fixture
Create the extension, then run the upstream initialization script in a disposable benchmark database:
In sb_rand_str(text), each ASCII # is replaced with a random digit and each ASCII @ with a random lowercase letter; other bytes are preserved. The shipped oltp_init.sql drops and recreates sbtest, inserts ten million rows, and builds an index on k.
oltp_ro.sql runs ten point lookups and four range/aggregate/order queries per transaction script. oltp_rw.sql adds updates, a delete, and a replacement insert inside an explicit transaction.
Benchmark Discipline
oltp_init.sqlbegins withDROP TABLE IF EXISTS sbtest; never point it at a database containing a table you need to preserve.- The scripts hard-code
table_sizeas ten million andrange_sizeas 100. If the fixture size changes, update the scripts consistently or random IDs and range bounds no longer describe the data set. - Record PostgreSQL settings, hardware, client count, threads, duration, warm-up, data scale, durability, and whether data fits in memory. Results without those controls are not comparable.
- Run read-only and read-write workloads separately, monitor saturation and errors, and validate table state after failures. The read-write script can leave workload-dependent churn and consumes WAL and storage.
sb_rand_stris volatile and uses the extension’s simple pseudo-random generation. It is suitable for benchmark filler, not secrets, identifiers, or cryptographic material.