← 返回命令列表

Linux command

pgbench 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Initialize benchmark database

pgbench -i [database]

Run benchmark

pgbench -c [10] -t [100] [database]

Run benchmark for duration

pgbench -c [10] -T [60] [database]

Run with custom script

pgbench -f [script.sql] [database]

Run read-only benchmark

pgbench -S -c [10] -T [30] [database]

Run with multiple threads

pgbench -c [20] -j [4] -T [60] [database]

Initialize with scale factor

pgbench -i -s [10] [database]

说明

pgbench runs TPC-B-like benchmarks on PostgreSQL databases. It measures transaction throughput under concurrent load. Initialization (-i) creates benchmark tables. Scale factor multiplies data size: scale 10 creates 1 million rows. Larger scales test different workload characteristics. The benchmark simulates banking transactions: updates to accounts, tellers, and branches. It measures transactions per second (TPS) under concurrent client load. Client count affects concurrency. More clients test parallel execution and locking. Thread count should match available CPU cores. Custom scripts test specific workloads. They can use variables, conditionals, and multiple statements to simulate application behavior. Progress output shows real-time TPS and latency. Final report includes average TPS, latency distribution, and any errors.

参数

-i
Initialize benchmark tables.
-s _SCALE_
Scale factor for initialization.
-c _CLIENTS_
Number of concurrent clients.
-t _TRANSACTIONS_
Transactions per client (default: 10).
-T _SECONDS_
Duration in seconds.
-j _THREADS_
Number of threads.
-f _FILE_
Custom SQL script.
-S
Select-only (read-only). Shorthand for -b select-only.
-N
Skip updates to pgbench_tellers and branches. Shorthand for -b simple-update.
-b _scriptname@weight_
Built-in script: tpcb-like, simple-update, select-only. Optional weight for mixing.
-C
Establish a new connection for each transaction (measures connection overhead).
-M _protocol_
Query protocol: simple, extended, or prepared (default: simple).
-R _rate_
Target transaction rate in TPS. Adds sleep to maintain rate.
-L _limit_
Report transactions exceeding _limit_ milliseconds as late.
-r
Report latency per statement.
-P _SECONDS_
Show progress every N seconds.
-l
Log transactions to file.
-n
Skip vacuuming before running the test.
-I _steps_
Initialization steps to perform (default: dtgvp). Characters: d=drop, t=tables, g=generate, v=vacuum, p=primary keys, f=foreign keys.
-h _HOST_
Database host.
-p _PORT_
Database port.
-U _USER_
Database user.

FAQ

What is the pgbench command used for?

pgbench runs TPC-B-like benchmarks on PostgreSQL databases. It measures transaction throughput under concurrent load. Initialization (-i) creates benchmark tables. Scale factor multiplies data size: scale 10 creates 1 million rows. Larger scales test different workload characteristics. The benchmark simulates banking transactions: updates to accounts, tellers, and branches. It measures transactions per second (TPS) under concurrent client load. Client count affects concurrency. More clients test parallel execution and locking. Thread count should match available CPU cores. Custom scripts test specific workloads. They can use variables, conditionals, and multiple statements to simulate application behavior. Progress output shows real-time TPS and latency. Final report includes average TPS, latency distribution, and any errors.

How do I run a basic pgbench example?

Run `pgbench -i [database]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i do in pgbench?

Initialize benchmark tables.