1.命令


  1. pgbench --help
  2. pgbench is a benchmarking tool for PostgreSQL.
  3. Usage:
  4.   pgbench [OPTION]... [DBNAME]
  5. Initialization options:
  6.   -i, --initialize         invokes initialization mode 初始化模式
  7.   -F, --fillfactor=NUM     set fill factor
  8.   -n, --no-vacuum          do not run VACUUM after initialization
  9.   -q, --quiet              quiet logging (one message each 5 seconds)
  10.   -s, --scale=NUM          scaling factor
  11.   --foreign-keys           create foreign key constraints between tables    
  12.   --index-tablespace=TABLESPACE    
  13.                            create indexes in the specified tablespace    
  14.   --tablespace=TABLESPACE  create tables in the specified tablespace    
  15.   --unlogged-tables        create tables as unlogged tables    
  16.     
  17. Options to select what to run:    
  18.   -b, --builtin=NAME[@W]   add builtin script NAME weighted at W (default: 1)    
  19.                            (use "-b list" to list available scripts)    
  20.   -f, --file=FILENAME[@W]  add script FILENAME weighted at W (default: 1)  测试脚本位置(可以自定义)    
  21.   -N, --skip-some-updates  skip updates of pgbench_tellers and pgbench_branches    
  22.                            (same as "-b simple-update")    
  23.   -S, --select-only        perform SELECT-only transactions    
  24.                            (same as "-b select-only")    
  25.     
  26. Benchmarking options:    
  27.   -c, --client=NUM         number of concurrent database clients (default: 1)  模拟客户端个数,相当于并发量
  28.   -C, --connect            establish new connection for each transaction  设定为每一个事务建一个新连接   
  29.   -D, --define=VARNAME=VALUE    
  30.                            define variable for use by custom script    
  31.   -j, --jobs=NUM           number of threads (default: 1)    启动线程数
  32.   -l, --log                write transaction times to log file    
  33.   -L, --latency-limit=NUM  count transactions lasting more than NUM ms as late    
  34.   -M, --protocol=simple|extended|prepared    
  35.                            protocol for submitting queries (default: simple)    
  36.   -n, --no-vacuum          do not run VACUUM before tests    
  37.   -P, --progress=NUM       show thread progress report every NUM seconds    每隔数秒显示线程进度报告
  38.   -r, --report-latencies   report average latency per command    报告每个命令的平均延迟
  39.   -R, --rate=NUM           target rate in transactions per second    
  40.   -s, --scale=NUM          report this scale factor in output    
  41.   -t, --transactions=NUM   number of transactions each client runs (default: 10)    
  42.   -T, --time=NUM           duration of benchmark test in seconds   测试时间,单位:秒 
  43.   -v, --vacuum-all         vacuum all four standard tables before tests    
  44.   --aggregate-interval=NUM aggregate data over NUM seconds    
  45.   --progress-timestamp     use Unix epoch timestamps for progress    
  46.   --sampling-rate=NUM      fraction of transactions to log (e.g., 0.01 for 1%)    
  47. Common options:
  48.   -d, --debug              print debugging output    
  49.   -h, --host=HOSTNAME      database server host or socket directory    
  50.   -p, --port=PORT          database server port number    
  51.   -U, --username=USERNAME  connect as specified database user    
  52.   -V, --version            output version information, then exit
  53.   -?, --help               show this help, then exit
 

2.初始化


  1. su - postgres
  2. # 使用postgres作为测试库
  3. pgbench -i -d postgres
  4. # 使用默认参数创造的测试表,各表的数据量:
  5. pgbench_accounts:100000
  6. pg_branches:1
  7. pg_tellers:10
 
# 设置自定测试数据量,将测试数据扩大100倍,测试总数1000万,并且实时显示创建数据量
pgbench -i -F 100 -s 100 -d postgres
压测结果:
 
 

3.压力测试

(1)测试一个客户端session(用户)

# 时间20秒,显示每个命令的平均延迟
pgbench -c 1 -T 20 -r -d postgres
 

(2)测试30个客户端session(用户)

pgbench -c 30 -T 20 -r -d postgres

4.自定义脚本压力测试

# 创建测试表
create table test(id int primary key, info text, crt_time timestamp);
 
# 创建脚本


  1. vi test.sql
  2. \set id random(1,100000000)
  3. insert into test (id,info,crt_time) values (:id, md5(random()::text), now()) on conflict (id) do update set info=excluded.info, crt_time=excluded.crt_time;
 
# 压力测试
pgbench -M prepared -r  -f ./test.sql -c 32 -j 32 -T 20 -d postgres
 
  
 

文章知识点与官方知识档案匹配,可进一步学习相关知识
PostgreSQL技能树首页概览6104 人正在系统学习中

[转帖]PostgreSQL 压测工具pgbench的更多相关文章

  1. super-smack压测工具

    简介 super-smack是一款开源压测工具,支持MySQL.PostgreSQL.Oracle.本篇主要介绍一下使用super-smack压测MySQL体会. 1.SQL定义 2.数据字典定义 3 ...

  2. Http压测工具wrk使用指南

    用过了很多压测工具,却一直没找到中意的那款.最近试了wrk感觉不错,写下这份使用指南给自己备忘用,如果能帮到你,那也很好. 安装 wrk支持大多数类UNIX系统,不支持windows.需要操作系统支持 ...

  3. web压测工具http_load原理分析

    一.前言 http_load是一款测试web服务器性能的开源工具,从下面的网址可以下载到最新版本的http_load: http://www.acme.com/software/http_load/ ...

  4. [软件测试]网站压测工具Webbench源码分析

    一.我与webbench二三事 Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能.Webbench ...

  5. Http压测工具wrk使用指南【转】

    用过了很多压测工具,却一直没找到中意的那款.最近试了wrk感觉不错,写下这份使用指南给自己备忘用,如果能帮到你,那也很好. 安装 wrk支持大多数类UNIX系统,不支持windows.需要操作系统支持 ...

  6. python服务端多进程压测工具

    本文描述一个python实现的多进程压测工具,这个压测工具的特点如下: 多进程 在大多数情况下,压测一般适用于IO密集型场景(如访问接口并等待返回),在这种场景下多线程多进程的区分并不明显(详情请参见 ...

  7. 内存压测工具Memtester

    在做压力测试时,发现一个内存压测工具Memtester,可以随意设置内存占用大小,非常方便 下载地址:http://pyropus.ca/software/memtester/old-versions ...

  8. Http 压测工具 wrk 基本使用

    Http 压测工具 wrk 基本使用 Intro wrk 是一款现代HTTP基准测试工具,能够在单个多核CPU上运行时产生显着负载.它将多线程设计与可扩展事件通知系统(如epoll和kqueue)结合 ...

  9. 压测工具使用(vegeta)

    一.压测工具vegeta 1.介绍 Vegeta 是一个用 Go 语言编写的多功能的 HTTP 负载测试工具,它提供了命令行工具和一个开发库. 官方地址:https://github.com/tsen ...

  10. 003_ab http压测工具

    一. ab -r -k -c 20000 -n 25000000 https://www.uuwatch.me/abtest #ab压测工具单机最大并发为20000,可以在多台机器上执行以增大并发 y ...

随机推荐

  1. MySQL优化:12种提升SQL执行效率的有效方法

    在数据库管理和优化的世界里,MySQL作为一个流行的关系型数据库管理系统,其性能优化是任何数据密集型应用成功的关键.优化MySQL数据库不仅可以显著提高SQL查询的效率,还能确保数据的稳定性和可靠性. ...

  2. LeetCode 图篇

    743. 网络延迟时间 有 N 个网络节点,标记为 1 到 N. 给定一个列表 times,表示信号经过有向边的传递时间. times[i] = (u, v, w),其中 u 是源节点,v 是目标节点 ...

  3. 为什么浏览器会提示网站“不安全”?一文读懂https协议与SSL证书

    [摘要] 为什么浏览器会提示网站"不安全"?从浏览器的"不安全"提示来详细了解https与SSL证书.我们打开很多http网站时候,会看到浏览器提示" ...

  4. 一图看懂华为云CodeArts Link六大特性

    本文分享自华为云社区<一图看懂华为云CodeArts Link六大特性,带你体验一站式跨平台数据互联>,作者:华为云PaaS服务小智 . 能够打破不同研发工具之间的壁垒,实现数据的无缝集成 ...

  5. 简化业务代码开发:看Lambda表达式如何将代码封装为数据

    摘要:在云服务业务开发中,善于使用代码新特性,往往能让开发效率大大提升,这里简单介绍下lambad表达式及函数式接口特性. 1.Lambda 表达式 Lambda表达式也被称为箭头函数.匿名函数.闭包 ...

  6. 手把手教你写一个spring IOC容器

    摘要:spring框架的基础核心和起点毫无疑问就是IOC,IOC作为spring容器提供的核心技术,成功完成了依赖的反转:从主类的对依赖的主动管理反转为了spring容器对依赖的全局控制.今天就带大家 ...

  7. 手把手带你做LiteOS的树莓派移植

    摘要:树莓派是英国的慈善组织"Raspberry Pi 基金会"开发的一款基于arm的微型电脑主板.本文介绍基于LiteOS的树莓派移植过程. 本文分享自华为云社区<2021 ...

  8. 基于Serverless的端边云一体化媒体网络

    摘要:视频在边缘的创新方向在哪?下一代视频云平台什么样? 本文分享自华为云社区<探讨视频云与边缘云平台的竞争力--基于Serverless的端边云一体化媒体网络>,作者/卢志航,整理 / ...

  9. vite/storybook/rollup搭建一个自己的组件库

    构建测试项目 首先vite 初始化一个项目 vue create story-book-demo ## 或者 vue create story-book-demo 然后添加storybook ,具体参 ...

  10. iOS上架报错:无法添加以供审核

    ​ 无法提交以供审核 要开始审核流程 必须提供以下项目 您必须为要添加的 app 提供版权信息. 您在提交 app 审核时遇到的问题是因为需要提供版权信息,而您的 app 缺少相关的版权信息.以下是解 ...