pgbench并发测试 postgresql
·
根据领导要求,需要对生产环境的大表进行并发处理测试验证SQL的执行耗时。
经过巡检好友的推荐,使用pgbench工具进行测试验证。
创建并发测试表:
[postgres@oradb ~]$ pgbench -h 127.0.0.1 -p 5432 -U postgres --initialize
NOTICE: table "pgbench_history" does not exist, skipping
NOTICE: table "pgbench_tellers" does not exist, skipping
NOTICE: table "pgbench_accounts" does not exist, skipping
NOTICE: table "pgbench_branches" does not exist, skipping
creating tables...
100000 of 100000 tuples (100%) done (elapsed 0.05 s, remaining 0.00 s).
vacuum...
set primary keys...
done.
200个客户端,10个线程,将事务写入日志文件,每5秒报告进度,每个客户端100个事务,测试前清空标准的测试表
--指定自定义的脚本进行测试
pgbench -d -n -f aa.sql -c 120 -j 120 -t 100 db_psis_prod
-i -s 1:初始化 pgbench 测试环境(如果你使用的是自定义表而不是 pgbench 默认表,可以跳过这一步)。
-f custom_script.sql:指定自定义 SQL 脚本。
-c 4:使用 4 个并发客户端。
-j 4:使用 4 个工作线程(通常等于 CPU 核心数)。
-t 1000:每个客户端执行 1000 次事务。
-U your_user:指定数据库用户名。
-d testdb:指定数据库名称。
编写脚本:
$ cat aa.sql
select count(*) from checkk tpbc WHERE tpbc.saa = 'LX' and tpbc._code = 'M5' and tpbc.ation = 'xxx' and tpbc.create_time >= '2024-12-18 00:00:00' and tpbc.create_time <= '2024-12-24 00:00:00';
最后反馈结果:
transaction type: Custom query
scaling factor: 1
query mode: simple
number of clients: 120
number of threads: 120
number of transactions per client: 100
number of transactions actually processed: 12000/12000
tps = 364.468722 (including connections establishing)
tps = 364.806701 (excluding connections establishing)
[postgres@dbbak ~]$
更多推荐

所有评论(0)