PostgreSQL数据库提供了一款轻量级的压力测试工具pgbench。pgbench通常会开多个数据库 Session, 并且在测试最后形成测试报告,得出每秒平均事务数。pgbench可以测试 select,update,insert,delete 命令。
安装环境:CentOS 6.5 (Final),PostgreSQL9.2.24,virtualbox 5.2.18 。
1.下载源码包
[root@April ~]# wget https://ftp.postgresql.org/pub/source/v9.2.24/postgresql-9.2.24.tar.gz
2.解压
[root@April ~]# tar zxvf postgresql-9.2.24.tar.gz
3.进入pgbench安装包
[root@April ~]# cd postgresql-9.2.24/contrib/pgbench/
查看安装包内的文件
[root@April pgbench]# ll
total 152
-rw-r--r--. 1 1107 1107 538 Nov 7 2017 Makefile
-rwxr-xr-x. 1 root root 46789 Apr 2 15:16 pgbench
-rw-r--r--. 1 1107 1107 64397 Nov 7 2017 pgbench.c
-rw-r--r--. 1 root root 34880 Apr 2 15:09 pgbench.o
4.编译和安装
[root@April pgbench]# make all
[root@April pgbench]# make install
5.相关参数
[root@April pgbench]# ./pgbench --help
pgbench is a benchmarking tool for PostgreSQL.
Usage:
pgbench [OPTION]... [DBNAME]
Initialization options:
-i invokes initialization mode
-F NUM fill factor
-s NUM scaling factor
--index-tablespace=TABLESPACE
create indexes in the specified tablespace
--tablespace=TABLESPACE
create tables in the specified tablespace
--unlogged-tables
create tables as unlogged tables
Benchmarking options:
-c NUM number of concurrent database clients (default: 1)
-C establish new connection for each transaction
-D VARNAME=VALUE
define variable for use by custom script
-f FILENAME read transaction script from FILENAME
-j NUM number of threads (default: 1)
-l write transaction times to log file
-M simple|extended|prepared
protocol for submitting queries to server (default: simple)
-n do not run VACUUM before tests
-N do not update tables "pgbench_tellers" and "pgbench_branches"
-r report average latency per command
-s NUM report this scale factor in output
-S perform SELECT-only transactions
-t NUM number of transactions each client runs (default: 10)
-T NUM duration of benchmark test in seconds
-v vacuum all four standard tables before tests
Common options:
-d print debugging output
-h HOSTNAME database server host or socket directory
-p PORT database server port number
-U USERNAME connect as specified database user
-V, --version output version information, then exit
-?, --help show this help, then exit
Report bugs to <[email protected]>.