PostgreSQL:运行 一次选择多个

PostgreSQL: run many selects at one time

怎么可能 运行 例如在 postgreSQL 中一次有 1000 个查询?我想测试我的数据库的性能和优化。我想 运行 多次选择并计算 运行ning 的时间。

使用 pgbench 会是个好主意。首先,创建一个 sql 文件并将您的测试查询放入其中。然后 运行 通过将 SQLFilePath、UserName 和 DatabaseName 替换为您的版本

以这种方式进行测试
pgbench.exe -c 10 -f SQLFilePath -j 10 -n -t 10 -U UserName DatabaseName

这是您可以调整的命令列表

-c = number of concurrent database clients
-f = script file path
-j = number of threads (the clients are evenly distributed among this number of threads)
-n = don't run VACUUM (docs require it be set in case of custom a script)
-t = number of transactions each client makes

您可以考虑使用 Apache JMeter, it supports PostgreSQL load testing via JDBC protocol

  1. Download Apache JMeter 并在某处解压
  2. 下载 Postgres JDBC Driver 并将 .jar 拖放到 JMeter 安装的 "lib" 文件夹中
  3. 运行 JMeter
  4. Thread Group 添加到测试计划,并在其中指定所需的线程数、测试持续时间、加速期。
  5. 添加 JDBC Connection Configuration 测试元素并在其中指定连接详细信息、凭据和其他参数。
  6. 添加 JDBC Request 采样器并在那里设置您的查询
  7. Run your test
  8. 使用 HTML Reporting Dashboard
  9. 分析结果

有关使用 Apache JMeter 进行数据库负载测试的更多信息,请参阅 The Real Secret to Building a Database Test Plan With JMeter 文章。