1.初始化:

  pgbench -i pgbench

  如果端口号有变化,需要先手动创建数据库,再执行。

  pgbench -i -s 10 -p 5433 pgbench

 重点:主要用到两个参数,-i:初始化模式,-s 插入的倍数,默认是1,即插入100000条;也就是执行多少次generate_series(1,100000)。

2.开始测试:

  pgbench -c 96  -j 12 -T 20 -r -p 5433 pgbench

-bash-4.1$ pgbench -c 96  -j 12 -T 20 -r -p 5433 pgbench
starting vacuum...end.
transaction type: TPC-B (sort of)
scaling factor:
query mode: simple
number of clients:
number of threads:
duration: s
number of transactions actually processed:
latency average: 1345.443 ms
tps = 71.351954 (including connections establishing)
tps = 71.400363 (excluding connections establishing)
statement latencies in milliseconds:
0.003744 \set nbranches * :scale
0.001051 \set ntellers * :scale
0.000855 \set naccounts * :scale
0.001345 \setrandom aid :naccounts
0.000850 \setrandom bid :nbranches
0.000680 \setrandom tid :ntellers
0.000797 \setrandom delta -
0.425127 BEGIN;
3.685616 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
0.189167 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
1144.710503 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
121.211975 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
0.194937 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
13.740971 END;

  主要参数:

  -c 总连接数,创建多少个连接到数据库,一般数据库接受连接数默认为100,其中需要预留3个左右的连接。

  -j 进程数量,每个进程创建n个连接,那么就存在如下关系:-c = -j *n。

  -T 测试持续时间,指定了-T就不能指定-t,每个连接执行的事物数量。即,要么指定测试多长时间,要么指定测试多少个事物。

  -r 显示每一步操作的平均时间。

  -f 指定测试脚本,不指定则使用默认脚本。

3.测试结果分析

  可以看看设置的参数,也可以看到TPS,当然可以算到QPS,也可以看到系统的读写更新的速度,知道该往哪方面优化。

4.pgbench初始化参数:

 

pgbench accepts the following command-line initialization arguments: 

-F fillfactor
Create the pgbench_accounts, pgbench_tellers and pgbench_branches tables with the given fillfactor. Default is . -i
Required to invoke initialization mode. -s scale_factor
Multiply the number of rows generated by the scale factor. For example, -s will create ,, rows in the pgbench_accounts table. Default is .

5.pgbench 压力测试参数:

pgbench accepts the following command-line benchmarking arguments: 

-c clients
Number of clients simulated, that is, number of concurrent database sessions. Default is . -C
Establish a new connection for each transaction, rather than doing it just once per client session. This is useful to measure the connection overhead. -d
Print debugging output. -D varname=value
Define a variable for use by a custom script (see below). Multiple -D options are allowed. -f filename
Read transaction script from filename. See below for details. -N, -S, and -f are mutually exclusive. -j threads
Number of worker threads within pgbench. Using more than one thread can be helpful on multi-CPU machines. The number of clients must be a multiple of the number of threads, since each thread is given the same number of client sessions to manage. Default is . -l
Write the time taken by each transaction to a log file. See below for details. -M querymode
Protocol to use for submitting queries to the server: simple: use simple query protocol. extended: use extended query protocol. prepared: use extended query protocol with prepared statements. The default is simple query protocol. (See Chapter for more information.) -n
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. -N
Do not update pgbench_tellers and pgbench_branches. This will avoid update contention on these tables, but it makes the test case even less like TPC-B. -s scale_factor
Report the specified scale factor in pgbench is output. With the built-in tests, this is not necessary; the correct scale factor will be detected by counting the number of rows in the pgbench_branches table. However, when testing custom benchmarks (-f option), the scale factor will be reported as unless this option is used. -S
Perform select-only transactions instead of TPC-B-like test. -t transactions
Number of transactions each client runs. Default is . -T seconds
Run the test for this many seconds, rather than a fixed number of transactions per client. -t and -T are mutually exclusive. -v
Vacuum all four standard tables before running the test. With neither -n nor -v, pgbench will vacuum the pgbench_tellers and pgbench_branches tables, and will truncate pgbench_history.

6.默认测试脚本:

\set nbranches :scale
\set ntellers * :scale
\set naccounts * :scale
\setrandom delta -
\setrandom aid :naccounts
\setrandom bid :nbranches
\setrandom tid :ntellers BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END; 备注:上面是 pgbench 自带的测试脚本,用户也可以自己编写测试脚本。

补充20190619:

7.在pg11上测试时,\setrandom报错,修改脚本:

\set nbranches :scale
\set ntellers * :scale
\set naccounts * :scale
\set delta random(-,)
\set aid random(,:naccounts)
\set bid random(,:nbranches)
\set tid random(,:ntellers) BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;

二、如果我们有绘图需要,一般可以这样解决:

1)使用pgbench 选用-P 选项,多少s报告一次进程的tps等信息,将这些信息可以放到excel或者Gnuplot、Matlab中绘图。

2)使用pgbench_tools来做综合测试,并给出一个趋势报告图。

下面是对pgbench_tools的介绍和使用:

https://github.com/kuang17/pgbench-tools

需要注意的是:

1)PG10修改了几个函数,例如pg_current_xlog_location变为了pg_current_wal_lsn。

2)在测试脚本中,\setrandom 需要对应的修改为\set xxx random(xxx, xxx)的方式。

3)在绘图时,需要先按照Gnuplot绘图工具及相关的字体。

yum install gnuplot -y

wget http://olea.org/paquetes-rpm//msttcore-fonts-2.0-6.noarch.rpm

rpm -ivh msttcore-fonts-2.0-6.noarch.rpm

修改/etc/profile或~/.bashrc,这样设置可以固定下来。

export GDFONTPATH="/usr/share/fonts/msttcore"

export GNUPLOT_DEFAULT_GDFONT="arial"

. /etc/profile

pgbench使用记录的更多相关文章

  1. [原创]使用benchmarksql和pgbench对PostgreSQL Plus Advanced Server进行性能测试

    一.测试环境 benchmarksql version:4.0.8 rhel 6.3 vmware esxi 二.理解benchmarksql性能测试原理TPC-C 1.理解TPC-C TPC-C模拟 ...

  2. 记一次debug记录:Uncaught SyntaxError: Unexpected token ILLEGAL

    在使用FIS3搭建项目的时候,遇到了一些问题,这里记录下. 这里是发布搭建代码: // 代码发布时 fis.media('qa') .match('*.{js,css,png}', { useHash ...

  3. nginx配置反向代理或跳转出现400问题处理记录

    午休完上班后,同事说测试站点访问接口出现400 Bad Request  Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...

  4. Kali对wifi的破解记录

    好记性不如烂笔头,记录一下. 我是在淘宝买的拓实N87,Kali可以识别,还行. 操作系统:Kali 开始吧. 查看一下网卡的接口.命令如下 airmon-ng 可以看出接口名称是wlan0mon. ...

  5. 2015 西雅图微软总部MVP峰会记录

    2015 西雅图微软总部MVP峰会记录 今年决定参加微软MVP全球峰会,在出发之前本人就已经写这篇博客,希望将本次会议原汁原味奉献给大家 因为这次是本人第一次写会议记录,写得不好的地方希望各位园友见谅 ...

  6. 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  7. 我是如何在SQLServer中处理每天四亿三千万记录的

    首先声明,我只是个程序员,不是专业的DBA,以下这篇文章是从一个问题的解决过程去写的,而不是一开始就给大家一个正确的结果,如果文中有不对的地方,请各位数据库大牛给予指正,以便我能够更好的处理此次业务. ...

  8. 前端学HTTP之日志记录

    前面的话 几乎所有的服务器和代理都会记录下它们所处理的HTTP事务摘要.这么做出于一系列的原因:跟踪使用情况.安全性.计费.错误检测等等.本文将谥介绍日志记录 记录内容 大多数情况下,日志的记录出于两 ...

  9. ASP.NET Core应用中如何记录和查看日志

    日志记录不仅对于我们开发的应用,还是对于ASP.NET Core框架功能都是一项非常重要的功能特性.我们知道ASP.NET Core使用的是一个极具扩展性的日志系统,该系统由Logger.Logger ...

随机推荐

  1. 35个例子学会find

    find的使用格式如下: $ find <指定目录> <指定条件> <指定动作> - <指定目录>: 所要搜索的目录及其所有子目录.默认为当前目录. - ...

  2. 关于shared pool的深入探讨(四)

    我们进一步来讨论一下shared pool的处理: 先进行相应查询,获得测试数据: [oracle@jumper udump]$ sqlplus "/ as sysdba" SQL ...

  3. Mahout学习路线图-张丹老师

    前言 Mahout是Hadoop家族中与众不同的一个成员,是基于一个Hadoop的机器学习和数据挖掘的分布式计算框架.Mahout是一个跨学科产品,同时也是我认为Hadoop家族中,最有竞争力,最难掌 ...

  4. 吴超老师课程---Hadoop的分布式集群安装

    1.hadoop的分布式安装过程 1.1 分布结构 主节点(1个,是hadoop0):NameNode.JobTracker.SecondaryNameNode            从节点(2个,是 ...

  5. Django:学习笔记(4)——请求与响应

    Django:学习笔记(4)——请求与响应 0.URL路由基础 Web应用中,用户通过不同URL链接访问我们提供的服务,其中首先经过的是一个URL调度器,它类似于SpringBoot中的前端控制器. ...

  6. BZOJ 3689: 异或之

    字典树可以$o(logn)查找第k大$ 使用$可持久化Trie 区间查找第k大,然后首先把每个数异或之后的最小丢进小根堆中,然后一个一个取出,取出后就再丢次小,一共取k次$ 总的时间复杂度为$O(kl ...

  7. POJ 1733 Parity game (带权并查集)

    题意:有序列A[1..N],其元素值为0或1.有M条信息,每条信息表示区间[L,R]中1的个数为偶数或奇数个,但是可能有错误的信息.求最多满足前多少条信息. 分析:区间统计的带权并查集,只是本题中路径 ...

  8. html基础 CSS样式表

    CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/此为注释语法 一.样式表 (一)样式表的分类 1.内联样式表 和HTML联合显示,控制精确, ...

  9. SQL char Nvarchar 详解

    Nvarchar :  可变长度的 , Unicode 编码.  长度 1-4000,  1个汉子 或者 字符 都是 2个字节. 支持多语言, 配合 大写 N 可以防止出现乱码. char:   固定 ...

  10. Gradle 引入本地定制 jar 包,而不使用坐标下载 jar 包的方法

    第 1 步:创建文件夹,拷贝 jar 包 在自己的 Gradle 项目里建立一个名为 “libs” (这个名字可以自己定义,不一定非要叫这个名字)的文件夹,把自己本地的 jar 包拷贝到这个文件夹中. ...