[转帖]PostgreSQL 压测工具pgbench

postgresql,工具,pgbench · 浏览次数 : 0

小编点评

# 1.初始化 su - postgres # 使用postgres作为测试库pgbench -i -d postgres # 使用默认参数创造的测试表,各表的数据量:pgbench_accounts:100000pg_branches:1pg_tellers:10 # 2.压力测试 (1)测试一个客户端session(用户) # 时间20秒,显示每个命令的平均延迟 pgbench -c 1 -T 20 -r -d postgres # 3.自定义脚本压力测试 # 创建测试表 create table test(id int primary key, info text, crt_time timestamp); # 创建脚本 vi test.sql\\set id random(1,100000000)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 # 4.自定义脚本压力测试 # 创建测试表 create table test(id int primary key, info text, crt_time timestamp); # 创建脚本 vi test.sql\\set id random(1,100000000)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 # 5.自定义脚本压力测试 # 创建测试表 create table test(id int primary key, info text, crt_time timestamp); # 创建脚本 vi test.sql\\set id random(1,100000000)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 # 6.归纳总结 以上内容,生成内容时需要带简单的排版

正文

1.命令

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  -n, --no-vacuum          do not run VACUUM after initialization  -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        Options to select what to run:      -b, --builtin=NAME[@W]   add builtin script NAME weighted at W (default: 1)                               (use "-b list" to list available scripts)      -f, --file=FILENAME[@W]  add script FILENAME weighted at W (default: 1)  测试脚本位置(可以自定义)      -N, --skip-some-updates  skip updates of pgbench_tellers and pgbench_branches                               (same as "-b simple-update")      -S, --select-only        perform SELECT-only transactions                               (same as "-b select-only")        Benchmarking options:      -c, --client=NUM         number of concurrent database clients (default: 1)  模拟客户端个数,相当于并发量  -C, --connect            establish new connection for each transaction  设定为每一个事务建一个新连接     -D, --define=VARNAME=VALUE                               define variable for use by custom script      -j, --jobs=NUM           number of threads (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)      -n, --no-vacuum          do not run VACUUM before tests      -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      -t, --transactions=NUM   number of transactions each client runs (default: 10)      -T, --time=NUM           duration of benchmark test in seconds   测试时间,单位:秒   -v, --vacuum-all         vacuum all four standard tables before tests      --aggregate-interval=NUM aggregate data over NUM seconds      --progress-timestamp     use Unix epoch timestamps for progress      --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
复制
 

2.初始化

su - postgres # 使用postgres作为测试库pgbench -i -d postgres # 使用默认参数创造的测试表,各表的数据量:pgbench_accounts:100000pg_branches:1pg_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);
复制
 
# 创建脚本
vi test.sql\set id random(1,100000000)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 --f ./test.sql -c 32 -j 32 -T 20 -d postgres
复制
 
  
 
文章知识点与官方知识档案匹配,可进一步学习相关知识
PostgreSQL技能树首页概览6104 人正在系统学习中

与[转帖]PostgreSQL 压测工具pgbench相似的内容:

[转帖]PostgreSQL 压测工具pgbench

1.命令 pgbench --help pgbench is a benchmarking tool for PostgreSQL. Usage: pgbench [OPTION]... [DBNAME] Initialization options: -i, --initialize invoke

[转帖]pgbench(postgresql压力测试工具)

pgbench 名称 pgbench -- 在PostgreSQL中执行基准线测试 大纲 pgbench -i [option...] [dbname] pgbench [option...] [dbname] 描述 pgbench是一个用于在PostgreSQL数据库中运行基准测试的简单程序。pg

[转帖]sysbench压测postgresql(mysql同理)

准备创建表和数据:sysbench --db-driver=pgsql --time=1 --threads=1000 --report-interval=5 --pgsql-host=192.168.1.35 --pgsql-port=5001 --pgsql-user=testpgs --pgs

[转帖]用sysbench压测mysql、postgresql(蟑螂db)对比

mysql: 准备创建表和数据: sysbench --db-driver=mysql --time=10 --threads=10 --report-interval=1 --mysql-host=172.18.44.84 --mysql-port=7999 --mysql-user=zl --m

[转帖]MySQL该使用哪种CPU架构服务器?

https://www.cnblogs.com/zhoujinyi/p/16880861.html 1. 摘要 近期,阿里云推出基于 ARM 架构的 RDS MySQL 和 RDS PostgreSQL 实例,现处于邀测阶段,阿里云宣传 ARM 架构的亮点是:在价格下降13%的基础上,平均性能 AR

[转帖]postgresql 编译选项 --with-uuid=e2fs、--with-uuid=ossp 的理解

postgresql 的 rpm 包使用的是 ‘–with-uuid=e2fs’ postgresql 源码 configure 的帮助选项有 uuid 的几个选项,有啥区别? # ./configure --help --with-uuid=LIB build contrib/uuid-ossp

[转帖]postgresql日志参数

https://www.jianshu.com/p/407c03aaa600 postgresql日志参数 logging_collector:这个参数启用日志收集器,它是一个捕捉被发送到stderr的日志消息的后台进程,并且它会将这些消息重定向到日志文件中;默认是OFF,修改参数需要重启。 log

[转帖]postgresql 的 pg_hba.conf 的行记录顺序

postgresql: 9.6 一直觉得 pg_hba.conf 的行记录与顺序无关,遵循细化优先的规则。今天在回顾 pg_hba.conf 文档时发现这种认识是错的。 下面这段话是从文档拷贝过来的: 因为每一次连接尝试都会顺序地检查pg_hba.conf记录,所以这些记录的顺序是非常关键的。通常,

[转帖]postgresql 的 .pgpass密码文件的使用

.pgpass 是 连接 postgresql 时使用的密码文件,通常位置为 ~/.pgpass。 在使用某些组件时还真的必须使用。具体的格式为: hostname:port:database:username:password 常见的使用如下: # su - postgres $ vi ~/.pg

[转帖]PostgreSQL进程结构

http://www.pgsql.tech/article_101_10000099 1、简介 本文简单的介绍了 PostgreSQL 的主要进程类型与功能。 2、PostgreSQL进程分为主进程与辅助进程。 2.1、主进程: PostMaster进程是整个数据库实例的总控进程,负责启动关闭该数据