使用pgbench测试PostgreSQL

时间:2022-11-26 11:23:01

pgbench –help

初始化选项:

-i            调用初始化模式

-F NUM  填充因子

-s NUM   规模因子(与产生数据量大小有关)

Benchmarking选项:

-c NUM    数据库客户端并发数(默认:1)

-C (为每个事务建立新的连接)

-D VARNAME=VALUE 通过客户脚本为用户定义变量

-f FILENAME 从文件FILENAME读取事务脚本

-j NUM  线程数(默认:1)

-i  写事务时间到日志文件

-M{simple|extended|prepared} 给服务器提交查询的协议

-n 在测试之前不运行VACUUM

-N 不更新表“pgbench_tellers” “pgbench_branches”

-r 报告每条命令的平均延迟

-s NUM 在输出中报告规模因子

-S      执行 SELECT-only事务

-t NUM 每个客户端运行的事务数(默认:10)

-T NUM benchmark测试时间(单位:秒)

-v 在测试前清空所有的四个标准表

常用选项:

-d 输出打印调试信息

-h HOSTNAME 数据库服务器主机或socket 目录

-U USERNAME 指定数据库用户的连接

--help 显示帮助信息,然后退出

--version 输出版本信息,然后退出

生成数据

postgres=# create user benchmarksql with superuser password '123456';

CREATE ROLE

postgres=# create database benchmarksql owner benchmarksql;

CREATE DATABASE

[postgres@DELL-R720 bin]$ ./pgbench -i -F 100 -s 714 -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql #10GB dataset

[postgres@DELL-R720 bin]$ ./pgbench -i -F 100 -s 1428 -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql #20GB dataset

[postgres@DELL-R720 bin]$ ./pgbench -i -F 100 -s 5712 -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql #80GB dataset

[postgres@DELL-R720 bin]$ ./pgbench -i -F 100 -s 11424 -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql #160GB dataset

连接的数据

[postgres@DELL-R720 bin]$ ./psql -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql

查看数据库大小

select pg_database_size('benchmarksql')/1024/1024/1024|| 'GB';

or

select pg_size_pretty(pg_database_size('benchmarksql'));

开始测试

[postgres@DELL-R720 bin]$ ./pgbench -c 10 –j –t  -r  -T 1800 -h 127.0.0.1 -p 6432 -U benchmarksql

transaction type: TPC-B (sort of)

scaling factor: 1428

query mode: prepared

number of clients: 10

number of threads: 10

duration: 1800 s

number of transactions actually processed: 1294479

latency average: 13.905 ms

tps = 715.507310 (including connections establishing)

tps = 715.510043 (excluding connections establishing)

statement latencies in milliseconds:

0.002768 \set nbranches 1 * :scale

0.000647 \set ntellers 10 * :scale

0.000562 \set naccounts 100000 * :scale

0.000823 \setrandom aid 1 :naccounts

0.000640 \setrandom bid 1 :nbranches

0.000684 \setrandom tid 1 :ntellers

0.000615 \setrandom delta -5000 5000

0.054656 BEGIN;

6.063291 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;

0.092079 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;

2.897447 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;

2.026997 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;

1.640868 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);

1.184043 END;

[postgres@DELL-R720 bin]$ ./pgbench -c 20 -j 20 -M prepared -n -s 1428 -T 1800 -r -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql

transaction type: TPC-B (sort of)

scaling factor: 1428

query mode: prepared

number of clients: 20

number of threads: 20

duration: 1800 s

number of transactions actually processed: 1503569

latency average: 23.943 ms

tps = 829.034591 (including connections establishing)

tps = 829.038294 (excluding connections establishing)

statement latencies in milliseconds:

0.003509 \set nbranches 1 * :scale

0.001146 \set ntellers 10 * :scale

0.000805 \set naccounts 100000 * :scale

0.001075 \setrandom aid 1 :naccounts

0.000881 \setrandom bid 1 :nbranches

0.000874 \setrandom tid 1 :ntellers

0.000881 \setrandom delta -5000 5000

0.077150 BEGIN;

9.083130 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;

0.123980 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;

6.025891 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;

3.595181 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;

3.098900 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);

2.098509 END;

transaction type: TPC-B (sort of)

scaling factor: 1428

query mode: prepared

number of clients: 30

number of threads: 10

duration: 1800 s

number of transactions actually processed: 1468864

latency average: 36.763 ms

tps = 815.178087 (including connections establishing)

tps = 815.184313 (excluding connections establishing)

statement latencies in milliseconds:

0.003654 \set nbranches 1 * :scale

0.001164 \set ntellers 10 * :scale

0.001123 \set naccounts 100000 * :scale

0.001288 \setrandom aid 1 :naccounts

0.001202 \setrandom bid 1 :nbranches

0.001106 \setrandom tid 1 :ntellers

0.001129 \setrandom delta -5000 5000

0.154459 BEGIN;

13.228743        UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;

0.212691 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;

9.070507 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;

4.904218 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;

5.595383 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);

3.612066 END;

[postgres@DELL-R720 bin]$ ./pgbench -c 50 -j 50 -M prepared -n -s 1428 -T 1800 -r -h 127.0.0.1 -p 6432 -U benchmarksql benchmarksql

transaction type: TPC-B (sort of)

scaling factor: 1428

query mode: prepared

number of clients: 50

number of threads: 50

duration: 1800 s

number of transactions actually processed: 1641175

latency average: 54.839 ms

tps = 901.460449 (including connections establishing)

tps = 901.475075 (excluding connections establishing)

statement latencies in milliseconds:

0.005079 \set nbranches 1 * :scale

0.001588 \set ntellers 10 * :scale

0.001257 \set naccounts 100000 * :scale

0.001768 \setrandom aid 1 :naccounts

0.001328 \setrandom bid 1 :nbranches

0.001424 \setrandom tid 1 :ntellers

0.001316 \setrandom delta -5000 5000

0.256724 BEGIN;

19.791906        UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;

0.284488 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;

13.638615        UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;

8.232851 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;

7.664059 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);

5.561957 END;