官网:http://www.postgres.cn/docs/12/pgbench.html
构造环境:
postgres=# create table test(
postgres(# id int8 primary key,
postgres(# info text default 'test',
postgres(# state int default 0,
postgres(# time1 timestamp default now(),
postgres(# time2 timestamp default now()
postgres(# );
CREATE TABLE
postgres=# insert into test select generate_series(1,10000000);
INSERT 0 10000000
构建脚本:
vi test.sql
/set id random(1,100000000)
select * from test where id=:id;
测试:
pg12@isdtest-> pgbench -M prepared -n -r -P 1 -f ./test.sql -c 32 -j 32 -T 60
...
...
transaction type: ./test.sql
scaling factor: 1
query mode: prepared
number of clients: 32
number of threads: 32
duration: 60 s
number of transactions actually processed: 4931686
latency average = 0.388 ms
latency stddev = 1.248 ms
tps = 82187.250560 (including connections establishing)
tps = 82200.894111 (excluding connections establishing)
statement latencies in milliseconds:
0.001 /set id random(1,10000000)
0.385 select * from test where id=:id;
TPS:82187
平均响应时间:0.388 毫秒