PostgreSQL
Databases & messagingLoad-test PostgreSQL directly: the parameterised query is the request, bound safely with $1, $2… and pooled per VU. Install with loadr plugin install postgres.
Browse all 52 demos 12 categories
No demos match.
$ loadr run examples/27-postgres.yaml
# PostgreSQL load test, driven by the `loadr-plugin-postgres` native protocol
# plugin.
#
# PostgreSQL support is NOT built into loadr core — it is a runtime-loadable
# plugin that ships the heavy `sqlx` Rust driver on its own (with ONLY the
# `postgres` feature, so it carries no `rsa` advisory). The plugin declares the
# `postgres://`/`postgresql://` URL schemes, so once it is installed a request
# to one of those URLs routes straight to it; no explicit `protocol:` needed.
#
# Each request runs one configured query as the "request"; loadr records query
# latency in `postgres_req_duration`, the number of rows returned (SELECT) or
# affected (INSERT/UPDATE/DELETE) in `postgres_rows`, and any database error
# fails the request (status 1 = ok, status 0 = DB/transport error). Positional
# parameters are bound safely by the driver with `$1, $2, ...` placeholders.
#
# Build + install the plugin, then run:
# cargo build -p loadr-plugin-postgres --release
# mkdir -p dist && cp plugins/loadr-plugin-postgres/plugin.toml dist/ \
# && cp target/release/libloadr_plugin_postgres.so dist/
# loadr plugin install dist
# loadr run examples/27-postgres.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly (below).
name: postgres
description: Parameterised SELECT/INSERT against PostgreSQL via loadr-plugin-postgres
plugins:
# Resolve `postgres` by name from the plugins dir (after `loadr plugin install`).
# To run straight from a build tree instead, set:
# path: target/release/libloadr_plugin_postgres.so
- name: postgres
scenarios:
# Read-mostly traffic with an occasional write.
postgres_reads:
executor: constant-vus
vus: 10
duration: 30s
flow:
- request:
name: pg list products
url: postgres://loadr:loadr@db.example.com:5432/loadr
sql:
query: SELECT id, name, price FROM products WHERE price < $1 ORDER BY price
params: ["50"]
checks:
- { type: status, equals: 1 } # 1 = ok, 0 = DB error
- { type: duration, name: query is fast, max: 250ms }
- request:
name: pg lookup by id
url: postgres://loadr:loadr@db.example.com:5432/loadr
sql:
query: SELECT name FROM products WHERE id = $1
params: ["${vu}"]
checks:
- { type: status, equals: 1 }
- request:
name: pg insert order
url: postgres://loadr:loadr@db.example.com:5432/loadr
sql:
query: INSERT INTO products (name, price, stock) VALUES ($1, $2, $3)
params: ["vu-${vu}-item", "1.23", "5"]
assert:
- { type: status, equals: 1 }
thresholds:
checks: [ "rate>0.99" ]
postgres_req_duration: [ "p(95)<300ms" ]
postgres_reqs: [ "count>0" ]View raw: examples/27-postgres.yaml
What it shows
- ▸Parameterised SQL
- ▸Per-VU connection pool
- ▸Runtime plugin — not in the binary
Key metrics: postgres_reqs · postgres_req_duration.