PostgreSQL pgBench工具运行用户定义的SQL脚本

8

请帮我澄清一下,pgbench工具是否可以以并行方式执行我的自定义SQL场景?通过谷歌搜索和本地搜索都没有找到肯定的结果。

我运行了脚本,没有出现任何错误。但是在执行后,我没有看到任何迹象表明我的脚本实际上已经执行。pgbench是否使用我的SQL脚本提交事务?

以下是我收到的输出:

C:\Program Files\PostgreSQL\9.2\bin>pgbench.exe -n -h dbserverhost -U postgres -
T 10 -c 64 -j 8 bench_dbname -f c:\Dev\bench_script.sql

transaction type: TPC-B (sort of)
scaling factor: 1
query mode: simple
number of clients: 64
number of threads: 8
duration: 10 s
number of transactions actually processed: 1020
tps = 95.846561 (including connections establishing)
tps = 103.387127 (excluding connections establishing)

C:\Program Files\PostgreSQL\9.2\bin>

bench_script.sql 是一个 SQL 脚本:

--comment here
begin;
  insert into schm.log values ( 'pgbench test', current_timestamp );
end;

解决方案

pgBench Windows版本对传递给实用程序的参数顺序很敏感:

"bench_dbname"参数必须是行中的最后一个参数。

这是pgbench Windows版本命令行的正确示例:

pgbench.exe -d -r -h 127.0.0.1 -U postgres -T 5 -f C:\Dev\bench_script.sql -c 64 -j 8 postgres

我最有用的参数如下:
  • -T 60(运行脚本的时间,单位为秒)
  • -t 100(每个客户端的交易金额)
  • -d(将详细的调试信息输出到输出中)
  • -r(在摘要中包含为脚本的每个操作计算的延迟值)
  • -f(以基准测试模式运行用户定义的SQL脚本)
  • -c(客户端数量)
  • -j(线程数量) pgBench官方文档 PgBench,我爱你! :)
    祝大家好运!;)
2个回答

4
"transaction type: TPC-B(某种类型)"意味着它没有处理-f选项来运行你的自定义SQL脚本,而是运行了默认查询。在Windows版本上,getopt似乎会在遇到第一个不以连字符开头的选项时停止解析选项,即"bench_dbname"。因此,请确保在其前面加上-f选项。

没错,pgbench Windows版本对参数顺序比较敏感。在获得经验后,我会编辑这个主题。 - xacinay

2

如果您正在使用自定义脚本,我猜您也需要使用-n选项?

-n

--no-vacuum

Perform no vacuuming before running the test. 
This option is necessary if you are running a custom test scenario 
that does not
include the standard tables pgbench_accounts, pgbench_branches,
pgbench_history, and pgbench_tellers.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接