gpt4 book ai didi

sql - 运行用户定义的 SQL 脚本的 postgresql pgBench 工具

转载 作者:行者123 更新时间:2023-11-29 11:36:17 28 4
gpt4 key购买 nike

请帮我澄清一下,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>

SQL 脚本 bench_script.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 official doc

PgBench,我爱你! :)

祝大家好;)

最佳答案

“事务类型:TPC-B(某种程度上)”意味着它没有处理 -f 选项来运行您的自定义 sql 脚本,而是运行默认查询。

在 Windows 版本上,getopt 似乎会在到达第一个不以连字符开头的选项(即“bench_dbname”)时停止解析选项。所以确保 -f 在此之前出现。

关于sql - 运行用户定义的 SQL 脚本的 postgresql pgBench 工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17997070/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com