Measure database health and capacity
How to Measure Live PostgreSQL Transactions per Second
Measure live PostgreSQL TPS from transaction counters, state what the rate counts, and keep it distinct from a pgbench result.

If you need to know how many transactions your PostgreSQL instance is finishing right now, sample its transaction counters twice and divide their changes by the seconds between samples. Report committed TPS and commit-plus-rollback TPS separately. Neither figure, by itself, tells you how many transactions wrote data or establishes a PostgreSQL transactions-per-second limit.
Sample the counters twice
Run this query, wait for an interval that captures the workload you care about, then run the same query again. Keep both rows and the conditions during that interval. The query sums the counters across rows in pg_stat_database, so label the result as a sum across databases, not as the rate for one named database.
SELECT clock_timestamp() AS sampled_at,
sum(xact_commit) AS commits,
sum(xact_rollback) AS rollbacks
FROM pg_stat_database;
The timestamp and transaction-counter approach follows a published pg_stat_database sampling example. Retain the timestamps rather than assuming that the intended wait was the exact elapsed time.
Calculate the two rates from the recorded rows:
elapsed_seconds = second sampled_at - first sampled_at, in seconds
committed_tps = (second commits - first commits) / elapsed_seconds
commit_plus_rollback_tps =
((second commits - first commits) +
(second rollbacks - first rollbacks)) / elapsed_seconds
If you want SQL to capture and calculate the samples in one session, the following temporary-table variant does that. Run the first INSERT, wait for the interval you want to observe, then run the second INSERT and the final SELECT. Do not run both inserts back-to-back if you intend to measure a longer interval. This is an example to run, not a reported measurement.
CREATE TEMP TABLE tps_samples (
sample_number integer PRIMARY KEY,
sampled_at timestamptz,
commits numeric,
rollbacks numeric
);
INSERT INTO tps_samples
SELECT 1, clock_timestamp(), sum(xact_commit), sum(xact_rollback)
FROM pg_stat_database;
-- Wait while the workload of interest is running.
INSERT INTO tps_samples
SELECT 2, clock_timestamp(), sum(xact_commit), sum(xact_rollback)
FROM pg_stat_database;
SELECT EXTRACT(EPOCH FROM (b.sampled_at - a.sampled_at)) AS elapsed_seconds,
(b.commits - a.commits)
/ EXTRACT(EPOCH FROM (b.sampled_at - a.sampled_at))
AS committed_tps,
((b.commits - a.commits) + (b.rollbacks - a.rollbacks))
/ EXTRACT(EPOCH FROM (b.sampled_at - a.sampled_at))
AS commit_plus_rollback_tps
FROM tps_samples AS a
JOIN tps_samples AS b ON a.sample_number = 1 AND b.sample_number = 2
WHERE b.sampled_at > a.sampled_at;
The final query returns no row if the second timestamp is not later than the first. Keep both raw samples as well as the calculated rate, so you can check the arithmetic and say exactly which interval was measured.
Say what the number counts
xact_commit and xact_rollback separate two transaction outcomes. The commit-only calculation counts committed outcomes per second; adding rollback deltas counts both outcomes per second. Labeling either one simply “TPS” hides a choice that matters when rollbacks occur. A monitoring dashboard that reports committed-transaction rate, for example, is not automatically reporting the same quantity as commit-plus-rollback TPS.
These outcome counters do not classify transactions by their read/write mix. Two intervals can have the same calculated TPS while representing different work. Record what application activity was running, which databases were included, the start and end timestamps, and whether the rate is commits only or commits plus rollbacks. If you need a rate for a particular application workload, an all-database sum may include other activity during the same interval.
Treat it as an observation, not a limit
A live sample answers “what outcome rate did these counters show during this interval?” It does not answer “what is the maximum TPS PostgreSQL supports?” Keep the sampling duration and workload conditions next to the number, especially when comparing two intervals. A higher observed rate might reflect a different mix of work rather than additional capacity; a lower one does not, on its own, establish a server ceiling.
Keep pgbench results distinct
PostgreSQL’s pgbench documentation describes a different measurement: pgbench repeatedly executes a defined SQL sequence, potentially through concurrent sessions, and reports an average transaction rate. Its default scenario is TPC-B-like and contains SELECT, UPDATE, and INSERT commands. For an explicitly identified benchmark workload, a command might look like this, after preparing a database for pgbench as described in its documentation:
pgbench -T 600 -c 10 your_benchmark_database
For this default workload with -c 10, initialize pgbench with a scale factor (-s) of at least 10. Otherwise, the test can mostly measure update contention rather than the workload you meant to assess.
Describe such a result as the rate for that pgbench workload, run duration, and client count, not as live application TPS. Check the report’s completed transaction count against its intended count: the documentation says they can differ if a run ends early or SQL commands fail. Also state whether a quoted rate includes connection establishment. A documented RDS pgbench run reports separate rates including and excluding it, illustrating why two bare TPS values need their measurement definitions attached. Neither that run nor your own pgbench result supplies a universal PostgreSQL capacity limit.
