benchmarksql测试postgresql快速上手
Benchmarksql 测试流程
benchmarksql的测试流程基本是:配置postgresql -> 配置benchmarksql -> 启动测试
PostgreSQL 安装与配置
- 通过yum源下载:
yum search postgresql
查找postgresql版本,需要装postgresql与postgresql-server。
yum install postgresql postgresql-server
安装postgresql - 通过apt源下载:
apt search postgresql
apt install postgresql postgresql-server
系统内源一般将命令安装至/usr/bin/目录下,但是postgresql-11版本的命令在/usr/lib/postgresql/11/bin/下。本教程以/usr/bin/为例
- 数据库下载好后会生成一个postgres用户管理数据库,该用户默认无密码用
su postgres
切换即可。切换成postgres用户后以下sudo -u postgres
命令不用再敲。 - 先创建一个目录用以盛放数据,以/home/postgresql/data/为例:
-
初始化数据库:
sudo -u postgres /usr/bin/initdb -D /home/postgresql/data/
或者用:
sudo -u postgres /usr/bin/pg_ctl init -D /home/postgresql/data/
-
修改数据库配置,在配置文件postgresql.conf最后追加如下参数:
postgresql.conf:
listen_addresses = ‘*’
max_connections = 3000maintenance_work_mem = 1GB
checkpoint_timeout = 30min
max_wal_size = 20GB
min_wal_size = 1GB
checkpoint_completion_target = 0.9管理用户socket修改pg_hba.conf,在如下两栏里添加所需要的IP段:
#IPv4 local connections:
host all all 192.168.0.0/16 md5
#Allow replication connections from localhost, by a user with the replication privilege.
host replication all 192.168.0.0/16 md5 -
启动数据库服务:
sudo -u postgres /usr/bin/pg_ctl start -D /home/postgresql/data
-
创建所需库及用户:
sudo -u postgres /usr/bin/psql -c "create user benchmarks with password '*';" sudo -u postgres /usr/bin/psql -c "create database benchmarksql;"
-
放通服务端防火墙:
firewall-cmd --add-port=5432/tcp --permanent firewall-cmd --reload
Benchmarksql 配置
- 在网盘分享中下载修改好的benchmarksql 5.0,密码z1x2。
或从SourceForge中获取软件。 - 确认编译环境ant存在。
Benchmarksql大致介绍
- 解压开压缩包会看到build,dist,doc,lib,run,src几个目录和build.xml,HOW-TO-RUN.txt,README.md三个文件,其中dist目录存放了软件的驱动,lib存放了链接数据库的驱动,src是源码目录,run类似与bin,我们测试主要在run目录中执行命令。或可参考HOW-TO-RUN.txt文档,里面解释了如何快速启动一个benchmarksql测试用例。
Benchmarksql测试流程
- 测试首先要有测试配置,命名规范为props.xx,xx为数据库名称。benchmarksql原生支持pg,所以配置文件已经给出名为props.pg。
- 测试流程大致为:建表 -> 测试 -> 清除脏数据,再循环。
-
修改配置文件props.pg为:
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://localhost:5432/benchmarksql
user=benchmarks
password=123456warehouses=100
loadWorkers=50
terminals=100runTxnsPerTerminal=0
runMins=10
limitTxnsPerMin=0terminalWarehouseFixed=true
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4resultDirectory=pg_result_%tY-%tm-%td_%tH%tM%tS
该配置在本地测试时可以直接使用,以该配置为例介绍配置文件主要参数:
参数 解释 db 数据库名称 driver 数据库驱动,测试pg不用管,默认即可。 conn 链接方式,格式为驱动格式:驱动包名称://IP/Socket:端口号/被测库名 user 链接用户名 password 用户名密码,本地测试不用管,远程测试需注意。 warehouses 数据仓数,关系到数据量大小,一般用100。 loadWorkers 加载数据的客户端数,对速度影响不大,默认即可。 terminals 并发数,一般使用100、300、500,越高对系统压力越大。 runMins 测试时间,可以适当调小,10mins比较合适。runTxnsPerTerminal必须为0 resultDirectory 按照需求更改结果目录名称。 -
建表并插入数据:
bash ./run/runDatabaseBuild.sh props.pg
中间无报错且最后显示vacuum analyze就是成功了。 -
启动测试:
bash ./run/runBenchmark.sh props.pg
看到tpmC每秒刷新一次即为开始测试,按示例脚本测试时间为10分钟。 -
清除脏数据:
./run/runDatabaseDestroy.sh props.pg
没有报错即为成功。
- 远程测试注意事项:
- 配置文件中的conn参数要将localhost修改成要链接的数据库IP。
- 一定要配置pg_hba.conf文件,确保服务端可以接受客户端的请求。若是客户端启动后再配置的hba文件,则要
pg_ctl restart
服务一遍。 - 注意要放通防火墙端口。并进行reload操作。
- 注意网卡尽量用光口,TPCC读写频繁,对网络带宽有一定要求,同轴线带宽偏低。
Benchmarksql测试常见问题解决
-
测试MySQL出现死锁怎么办?
benchmarksql不支持mysql是有原因的。它其中的长语句和update语法不被mysql支持,所以会出现死锁现象。 -
要测试的数据库不支持怎么办?
首先确定要测试的数据库支持pg或oracle语法的,然后参考benchmarksql添加人大金仓这篇文章来添加其他数据库,数据库驱动一般在库内cp。 -
建仓过程中出现乱码,建仓失败怎么办?
出现此类问题首要排查配置是否有问题,用户是否创建,IP是否写对,用户密码是否写对,要测试的数据库在不在等;远程测试还要排查链接是否畅通等,hba文件是否放行,防火墙是否放行等。 -
建仓、测试过程中出现链接失败怎么办?
第一要参考上一问题的解决方案,另外如果是远程测试要确保链路畅通,防火墙放过了5432端口或者特定的监听端口。