pgbench测试:
 
pg9.6.2的pgbench报错:
[thunisoft@localhost ~]$ pgbench -S -c 8 -t 60 pgbenchdb
Segmentation fault (core dumped):
 
1简介
 
PG数据库提供了一款轻量级的压力测试工具叫pgbench, 测试模型是TPC-B.
 
2安装
 
 
3.参数介绍
 
[postgres@localhost bin]$ pgbench --help
 
pgbench is a benchmarking tool for PostgreSQL.
 
Usage: pgbench [OPTION]... [DBNAME]
 
Initialization options:
 
-i, --initialize invokes initialization mode(调用初始化模式)
 
-F, --fillfactor=NUM set fill factor(填充因子-对表的填充因子,类似oracle的pctfree作用)
 
-n, --no-vacuum do not run VACUUM after initialization(初始化完成后不VACUUM)
 
-q, --quiet quiet logging (one message each 5 seconds)
 
-s, --scale=NUM scaling factor(比例因子-控制表的数据大小)
 
--foreign-keys create foreign key constraints between tables(表之间创建外键约束)
 
--index-tablespace=TABLESPACE create indexes in the specified tablespace(索引创建在指定表空间)
 
--tablespace=TABLESPACE create tables in the specified tablespace(表创建在指定表空间)
 
--unlogged-tables create tables as unlogged tables(创建表为unlogged表)
 
Benchmarking options:
 
-c, --client=NUM number of concurrent database clients (default: 1) 客户端个数(默认: 1)
 
-C, --connect establish new connection for each transaction为每一个事务建立一个新的连接
 
-D, --define=VARNAME=VALUE define variable for use by custom script通过客户脚本为用户定义变量
 
-f, --file=FILENAME read transaction script from FILENAME指定测试脚本的位置,不指定为自带的默认脚本
 
-j, --jobs=NUM number of threads (default: 1) 启动线程数(default: 1)
 
-l, --log write transaction times to log file向日志文件中输入每个事务时间
 
-L, --latency-limit=NUM count transactions lasting more than NUM ms as late
 
-M, --protocol=simple|extended|prepared
 
protocol for submitting queries (default: simple) 向服务器提交查询的协议 (default: simple)
 
-n, --no-vacuum do not run VACUUM before tests测试前不执行VACUUM
 
-N, --skip-some-updates skip updates of pgbench_tellers and pgbench_branches不执行update操作
 
-P, --progress=NUM show thread progress report every NUM seconds
 
-r, --report-latencies report average latency per command报告中显示每个命令的平均延迟
 
-R, --rate=NUM target rate in transactions per second
 
-s, --scale=NUM report this scale factor in output报告中显示每个命令的平均延迟
 
-S, --select-only perform SELECT-only transactions只执行查询的事务
 
-t, -transactions=NUM number of transactions each client runs (default: 10) 每个客户端执行的事务次数(default: 10)
 
-T, --time=NUM duration of benchmark test in seconds测试时间,单位为秒
 
-v, --vacuum-all vacuum all four standard tables before tests测试前对库中默认的4个基准表进行vacuum操作
 
--aggregate-interval=NUM aggregate data over NUM seconds
 
--sampling-rate=NUM fraction of transactions to log (e.g. 0.01 for 1%)
 
Common options:
 
-d, --debug print debugging output
 
-h, --host=HOSTNAME database server host or socket directory
 
-p, --port=PORT database server port number
 
-U, --username=USERNAME connect as specified database user
 
-V, --version output version information, then exit
 
-?, --help show this help, then exit
 
4测试方式
 
1采用默认基准表默认脚本测试
 
(1)创建名为pgbench数据库:create database pgbench;
 
(2)初始化测试数据[postgres@pg2 ~]$pgbench -i -F 100 -s 500 -h localhost -U dba -d pgbench
 
(3)检查初始化之后的pgbench数据库
 
pgbench=# select count(1) from pgbench_accounts;
 
pgbench=# select count(1) from pgbench_branches;
 
pgbench=# select count(1) from pgbench_history;
 
pgbench=# select count(1) from pgbench_tellers;
 
pgbench=# \d+ pgbench_accounts
 
pgbench=# \d+ pgbench_branches
 
pgbench=# \d+ pgbench_history
 
pgbench=# \d+ pgbench_tellers
 
查数据库大小:pgbench=# select pg_database_size('pgbench')/1024/1024||'M';
 
(4)利用基准表,默认脚本测试
 
自带脚本
 
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只读
 
nohup pgbench -c 50 -j 10 -M prepared -n -s 500 -S -T 120 -r -h localhost -p 5432 -U dba -d pgbench> /pgdb/pgbenchtest/readonly.out 2>&1
 
2更新,查询,插入
 
nohup pgbench -c 50 -j 10 -M prepared -n -s 500 -T 120 -r -h localhost -p 5432 -U dba -d pgbench> /pgdb/pgbenchtest/all.out 2>&1
 
3不执行更新
 
nohup pgbench -c 50 -j 10 -M prepared -n -N -s 500 -T 120 -r -h localhost -p 5432 -U dba -d pgbench> /pgdb/pgbenchtest/noupdate.out 2>&1
 
说明:我们主要关心的是最后的输出报告中的两个TPS值,一个是包含网络开销(including),另一个是不包含网络开销的 (excluding),这个值是反映的是每秒处理的事务数,反过来也可以查出每个事务数所消耗的平均时间,一般认为能将硬件用到极致,速度越快越好。
 
2利用默认基准表,自定义脚本测试
 
分别测试3种脚本:(只读,读写,读写函数)
 
2.1只读测试
 
--脚本内容
 
vi /pgdb/pgbenchtest/read.sql
 
\set naccounts 100000 * :scale
 
\setrandom aid 1 :naccounts
 
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
 
--测试时间段内的操作系统负载
 
Linux命令top
 
--测试语句
 
[postgres@pg2 ~]$pgbench -c 50 -j 10 -M prepared -n -s 500 -T 120 -f /pgdb/pgbenchtest/read.sql -h localhost -p 5432 -U dba -d pgbench>/pgdb/pgbenchtest/readonly.out 2>&1
 
2.2读写测试
 
--脚本内容
 
vi /pgdb/pgbenchtest/readwrite.sql
 
\set nbranches :scale
 
\set ntellers 10 * :scale
 
\set naccounts 100000 * :scale
 
\setrandom aid 1 :naccounts
 
\setrandom bid 1 :nbranches
 
\setrandom tid 1 :ntellers
 
\setrandom delta -5000 5000
 
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, CLOCK_TIMESTAMP());
 
END;
 
--测试时间段内的操作系统负载
 
Linux命令top
 
--测试语句
 
[postgres@pg2 ~]$pgbench -c 50 -j 10 -M prepared -n -s 500 -T 120 -f /pgdb/pgbenchtest/readwrite.sql -h localhost -p 5432 -U dba -d pgbench>/pgdb/pgbenchtest/readwrite.out 2>&1
 
2.3读写函数的测试
 
--主要是为了对比调用函数和直接使用SQL的性能差别
 
--创建如下函数
 
pgbench=# create or replace function pgbench(i_aid int,i_bid int,i_tid int,i_delta int) returns setof int as $BODY$
 
declare
 
begin
 
UPDATE pgbench_accounts SET abalance = abalance + i_delta WHERE aid = i_aid;
 
UPDATE pgbench_tellers SET tbalance = tbalance + i_delta WHERE tid = i_tid;
 
UPDATE pgbench_branches SET bbalance = bbalance + i_delta WHERE bid = i_bid;
 
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (i_tid, i_bid, i_aid, i_delta, CURRENT_TIMESTAMP);
 
return query SELECT abalance FROM pgbench_accounts WHERE aid = i_aid;
 
end;
 
$BODY$ language plpgsql;
 
--脚本内容
 
vi /pgdb/pgbenchtest/readwritefunction.sql
 
\set nbranches :scale
 
\set ntellers 10 * :scale
 
\set naccounts 100000 * :scale
 
\setrandom aid 1 :naccounts
 
\setrandom bid 1 :nbranches
 
\setrandom tid 1 :ntellers
 
\setrandom delta -5000 5000
 
select pgbench(:aid,:bid,:tid,:delta);
 
--测试时间段内的操作系统负载
 
Linux命令top
 
--测试语句
 
[postgres@pg2 ~]$ pgbench -c 50 -j 10 -M prepared -n -s 500 -T 120 -f /pgdb/pgbenchtest/readwritefunction.sql -h localhost -p 5432 -U dba -d pgbench>/pgdb/pgbenchtest/readwritefunction.out 2>&1
 
3自定义测试表,数据与脚本
 
3.1测试查询
 
--表准备
 
pgbench=#create table testtb1(id int,name text);
 
pgbench=#insert into testtb1(id,name) select n,n||'_test' from generate_series(1,5000000) n;
 
pgbench=#alter table testtb1 add primary key(id);
 
--测试脚本 SQL
 
[postgres@pg2 ~]$ cat /pgdb/pgbenchtest/testtb1.sql
 
\setrandom v_id 1 5000000
 
select name from testtb1 where id=:v_id;
 
--测试语句
 
pgbench -c 2 -T 20 -n -M prepared -d pgbench -U dba -f /pgdb/pgbenchtest/ testtb1.sql >/pgdb/pgbenchtest/testtb1.out 2>&1
 
2测试插入
 
--表准备
 
pgbench=#create table testintodata(data text);
 
--测试脚本 SQL内容:
 
[postgres@pg2 ~]$ cat /pgdb/pgbenchtest/testintodata.sql
 
insert into testintodata (data) values (repeat('xyz',:scale));
 
--测试语句
 
pgbench -s 100 -c 50 -j 10 -M prepared -T 120 -f /pgdb/pgbenchtest/testintodata.sql -h localhost -p 5432 -U dba -d pgbench>/pgdb/pgbenchtest/testintodata.out 2>&1
 
完成。
---------------------
作者:treacle田
来源:CSDN
原文:https://blog.csdn.net/sunziyue/article/details/50997867
版权声明:本文为博主原创文章,转载请附上博文链接!

postgresql-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. 使用pgbench测试PostgreSQL

    pgbench –help 初始化选项: -i            调用初始化模式 -F NUM  填充因子 -s NUM   规模因子(与产生数据量大小有关) Benchmarking选项: -c ...

  3. PostgreSQL配置优化

    硬件和系统配置 操作系统 Ubuntu13.04 系统位数 64 CPU Intel(R) Core(TM)2 Duo CPU 内存 4G 硬盘 Seagate ST2000DM001-1CH164 ...

  4. 使用pgstatspack分析PostgreSQL数据库性能

    pgstatspack [root@test01 soft]# wget http://pgfoundry.org/frs/download.php/3151/pgstatspack_version_ ...

  5. PostgreSQL单机、同步复制、异步复制性能测试对比

    测试环境: •测试机:PC •内存:8GB •CPU:Intel(R) Core(TM) i5-3450 3.10GHz •硬盘:HDD •数据量:20GB •测试工具:pgbench •Postgr ...

  6. PostgreSQL Performance Monitoring Tools

    PostgreSQL Performance Monitoring Tools https://github.com/CloudServer/postgresql-perf-tools This pa ...

  7. PostgreSQL Insight Monitor pgstat

    PostgreSQL Insight Monitor  pgstat pgstat 是一个连接到数据库并获取数据库的活动状态的命令行工具. PostgreSQL有许多状态: archiver for ...

  8. PostgreSQL Monitor pg_view

    PostgreSQL Monitor pg_view https://github.com/zalando/pg_view Requirements Linux 2.6, python 2.6, ps ...

  9. PostgreSQL Monitor pg_activity

    PostgreSQL Monitor pg_activity Command line tool for PostgreSQL server activity monitoring. https:// ...

  10. PostgreSQL pg_dump pg_dumpall and restore

    pg_dump dumps a database as a text file or to other formats. Usage: pg_dump [OPTION]... [DBNAME] Gen ...

随机推荐

  1. String拼接

    1. String[] members=ArrayDATA_IDS; String usernames = ""; for(String id :members) { userna ...

  2. 表单提交textarea内容,第一次获取不到值,第二次才能获取到的解决方法:

    因为KindEditor的可视化操作在新创建的iframe上执行,代码模式下的textarea框也是新创建的,所以最后提交前需要执行 sync() 将HTML数据设置到原来的textarea. Kin ...

  3. PHP源码编译安装

    cd php-5.6.0yum -y install libcurl-devel bzip2-devel zlib-devel libjpeg-devel libpng-devel freetype- ...

  4. s4-7 生成树协议

    Spanning Tree :为了可靠,采用冗余结构:但是透明网桥 会产生无休止循环的问题 冗余交换拓扑可能带来的问题  广播风暴  多帧传送  MAC地址库不稳定 生成树协议  STP:sp ...

  5. 音频管理器(AudioManager)

    MainActivity.java package com.wwj.serviceandboardcast;   import android.app.Activity; import android ...

  6. location位置操作

    使用location对象可以通过很多方式来改变浏览器的位置. location.assign('http://www.klkx.com') 传入一个URL地址 这样可以立即打开一个新的URL并在浏览器 ...

  7. 开源javacsv读取csv文件

    一.下载地址:https://sourceforge.net/projects/javacsv/ 读取示例: public static void main(String[] args) { // 1 ...

  8. PuTTY乱码问题解决办法

    原文链接:http://www.henshiyong.com/archives/403.html 使用PuTTY 时,遇到了乱码问题,查看了别人介绍的信息,解决掉了. 方法其实很简单,现在分享出来. ...

  9. jquery扩展实现input框字符长度限制中文2个字符,英文1个字符

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. Java数组、集合

    Vector类     类似C#的ArrayList.可扩展的数组,带有一些特定方法   Hashtable类     与C#的类似   Enumeration接口     类似C#的枚举器