HTAP数据库 PostgreSQL 场景与性能测试之 45 - (OLTP) 数据量与性能的线性关系(10亿+无衰减), 暨单表多大需要分区

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

标签

PostgreSQL , HTAP , OLTP , OLAP , 场景与性能测试


背景

PostgreSQL是一个历史悠久的数据库,历史可以追溯到1973年,最早由2014计算机图灵奖得主,关系数据库的鼻祖Michael_Stonebraker 操刀设计,PostgreSQL具备与Oracle类似的功能、性能、架构以及稳定性。

pic

PostgreSQL社区的贡献者众多,来自全球各个行业,历经数年,PostgreSQL 每年发布一个大版本,以持久的生命力和稳定性著称。

2017年10月,PostgreSQL 推出10 版本,携带诸多惊天特性,目标是胜任OLAP和OLTP的HTAP混合场景的需求:

《最受开发者欢迎的HTAP数据库PostgreSQL 10特性》

1、多核并行增强

2、fdw 聚合下推

3、逻辑订阅

4、分区

5、金融级多副本

6、json、jsonb全文检索

7、还有插件化形式存在的特性,如 向量计算、JIT、SQL图计算、SQL流计算、分布式并行计算、时序处理、基因测序、化学分析、图像分析 等。

pic

在各种应用场景中都可以看到PostgreSQL的应用:

pic

PostgreSQL近年来的发展非常迅猛,从知名数据库评测网站dbranking的数据库评分趋势,可以看到PostgreSQL向上发展的趋势:

pic

从每年PostgreSQL中国召开的社区会议,也能看到同样的趋势,参与的公司越来越多,分享的公司越来越多,分享的主题越来越丰富,横跨了 传统企业、互联网、医疗、金融、国企、物流、电商、社交、车联网、共享XX、云、游戏、公共交通、航空、铁路、军工、培训、咨询服务等 行业。

接下来的一系列文章,将给大家介绍PostgreSQL的各种应用场景以及对应的性能指标。

环境

环境部署方法参考:

《PostgreSQL 10 + PostGIS + Sharding(pg_pathman) + MySQL(fdw外部表) on ECS 部署指南(适合新用户)》

阿里云 ECS:56核,224G,1.5TB*2 SSD云盘

操作系统:CentOS 7.4 x64

数据库版本:PostgreSQL 10

PS:ECS的CPU和IO性能相比物理机会打一定的折扣,可以按下降1倍性能来估算。跑物理主机可以按这里测试的性能乘以2来估算。

场景 - 数据量与性能的线性关系(10亿+无衰减), 暨单表多大需要分区 (OLTP)

1、背景

这个测试回答用户一个问题,PostgreSQL在单表可以管理多大的数据量性能不会衰减。

单表多大需要分区。

单表记录数在不同的级别(如千万、亿、十亿、百亿),查询,更新,写入吞吐 分别是什么样的性能。

2、设计

单表记录数:千万、亿、十亿。

分别测试写入吞吐、查询tps,更新TPS。

3、准备测试表

create unlogged table test(id int primary key, info text, crt_time timestamp);    
    
create unlogged table test1(id int primary key, info text, crt_time timestamp);    
    
create unlogged table test3(id int primary key, info text, crt_time timestamp);    

4、准备测试函数(可选)

5、准备测试数据

postgres=# insert into test select generate_series(1,10000000), 'test', now();    
INSERT 0 10000000    
Time: 17197.822 ms (00:17.198)    
    
postgres=# insert into test1 select generate_series(1,100000000), 'test', now();    
INSERT 0 100000000    
Time: 187844.576 ms (03:07.845)    
    
for ((i=1;i<=100;i++)) ; do psql -c "insert into test3 select generate_series(($i-1)*10000000+1, $i*10000000),'test', now();" & done    
写入10亿 耗时 615秒    

6、准备测试脚本

1、查询测试

-- 1000万    
vi test.sql    
    
\set id random(1,10000000)    
select * from test where id=:id;    
    
-- 1亿    
vi test1.sql    
    
\set id random(1,100000000)    
select * from test1 where id=:id;    
    
    
-- 10亿    
vi test3.sql    
    
\set id random(1,1000000000)    
select * from test3 where id=:id;    

2、更新测试

-- 1000万    
vi test.sql    
    
\set id random(1,10000000)    
update test set crt_time=now() where id=:id;    
    
-- 1亿    
vi test1.sql    
    
\set id random(1,100000000)    
update test1 set crt_time=now() where id=:id;    
    
    
-- 10亿    
-- 第三个CASE,虽然记录数10亿,但是频繁被更新的数据假设在1亿内。测试时被访问的数据依旧在10亿的范围。    
vi test3.sql    
    
\set id random(1,100000000)    
\set id1 random(1,1000000000)    
with tmp as (select * from test3 where id=:id1)    
update test3 set crt_time=now() where id=:id ;    

7、测试

测试脚本

CONNECTS=48     
TIMES=120      
export PGHOST=$PGDATA      
export PGPORT=1921      
export PGUSER=postgres      
export PGPASSWORD=postgres      
export PGDATABASE=postgres      
      
pgbench -M prepared -n -r -P 5 -f ./test.sql -c $CONNECTS -j $CONNECTS -T $TIMES      
pgbench -M prepared -n -r -P 5 -f ./test1.sql -c $CONNECTS -j $CONNECTS -T $TIMES      
pgbench -M prepared -n -r -P 5 -f ./test3.sql -c $CONNECTS -j $CONNECTS -T $TIMES      

8、测试结果

1、查询测试TPS

pgbench -M prepared -n -r -P 1 -f ./test.sql -c 48 -j 48 -T 120    
    
transaction type: ./test.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 80378275    
latency average = 0.072 ms    
latency stddev = 0.012 ms    
tps = 669810.772760 (including connections establishing)    
tps = 669876.004400 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.001  \set id random(1,10000000)    
         0.071  select * from test where id=:id;    
    
pgbench -M prepared -n -r -P 1 -f ./test1.sql -c 48 -j 48 -T 120    
    
transaction type: ./test1.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 76078076    
latency average = 0.076 ms    
latency stddev = 0.010 ms    
tps = 633977.716555 (including connections establishing)    
tps = 634041.588175 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.001  \set id random(1,100000000)    
         0.074  select * from test1 where id=:id;    
    
pgbench -M prepared -n -r -P 1 -f ./test3.sql -c 48 -j 48 -T 120    
    
transaction type: ./test3.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 72746181    
latency average = 0.079 ms    
latency stddev = 0.019 ms    
tps = 606203.459638 (including connections establishing)    
tps = 606259.356671 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.001  \set id random(1,1000000000)    
         0.078  select * from test3 where id=:id;    

2、更新测试TPS

pgbench -M prepared -n -r -P 1 -f ./test.sql -c 48 -j 48 -T 120    
transaction type: ./test1.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 27703709    
latency average = 0.208 ms    
latency stddev = 0.126 ms    
tps = 230828.616797 (including connections establishing)    
tps = 230853.344303 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.002  \set id random(1,100000000)    
         0.207  update test1 set crt_time=now() where id=:id;    
    
    
pgbench -M prepared -n -r -P 1 -f ./test1.sql -c 48 -j 48 -T 120    
    
    
transaction type: ./test1.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 29387603    
latency average = 0.196 ms    
latency stddev = 0.110 ms    
tps = 244891.957430 (including connections establishing)    
tps = 244917.399306 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.001  \set id random(1,100000000)    
         0.195  update test1 set crt_time=now() where id=:id;    
    
pgbench -M prepared -n -r -P 1 -f ./test3.sql -c 48 -j 48 -T 120    
    
transaction type: ./test3.sql    
scaling factor: 1    
query mode: prepared    
number of clients: 48    
number of threads: 48    
duration: 120 s    
number of transactions actually processed: 28026501    
latency average = 0.205 ms    
latency stddev = 0.110 ms    
tps = 233533.801692 (including connections establishing)    
tps = 233554.689137 (excluding connections establishing)    
script statistics:    
 - statement latencies in milliseconds:    
         0.002  \set id random(1,100000000)    
         0.001  \set id1 random(1,1000000000)    
         0.203  with tmp as (select * from test3 where id=:id1)    

索引深度的差别:

postgres=# explain (analyze,verbose,timing,costs,buffers) select * from test where id=1;
                                                       QUERY PLAN                                                       
------------------------------------------------------------------------------------------------------------------------
 Index Scan using test_pkey on public.test  (cost=0.43..2.85 rows=1 width=44) (actual time=0.074..0.075 rows=1 loops=1)
   Output: id, info, crt_time
   Index Cond: (test.id = 1)
   Buffers: shared read=4
 Planning time: 0.215 ms
 Execution time: 0.102 ms
(6 rows)

postgres=# explain (analyze,verbose,timing,costs,buffers) select * from test1 where id=1;
                                                        QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
 Index Scan using test1_pkey on public.test1  (cost=0.57..2.98 rows=1 width=44) (actual time=0.094..0.094 rows=1 loops=1)
   Output: id, info, crt_time
   Index Cond: (test1.id = 1)
   Buffers: shared read=5
 Planning time: 0.217 ms
 Execution time: 0.119 ms
(6 rows)

postgres=# explain (analyze,verbose,timing,costs,buffers) select * from test3 where id=1;
                                                        QUERY PLAN                                                        
--------------------------------------------------------------------------------------------------------------------------
 Index Scan using test3_pkey on public.test3  (cost=0.57..2.99 rows=1 width=44) (actual time=0.054..0.055 rows=1 loops=1)
   Output: id, info, crt_time
   Index Cond: (test3.id = 1)
   Buffers: shared hit=5
 Planning time: 0.413 ms
 Execution time: 0.080 ms
(6 rows)

性能小结

数据量 写入吞吐 查询tps 更新tps
1000万 58万行/s 67万 23.1万
1亿 53.2万行/s 63.4万 24.5万
10亿 162.6万行/s 60.6万 23.4万

表分区建议

单表多大需要分区?

1、非常频繁更新的表(考虑到autovacuum的速度)

2亿

指表中频繁被更新的记录数在2亿以内,表本身的记录数可以更多。

2、更新、删除不频繁或毫无的表(考虑到设计rewrite的DDL,建索引,逻辑备份等的速度)

20亿(还需要考虑单行大小,直接影响DDL rewrite table的开销)

参考

《PostgreSQL、Greenplum 应用案例宝典《如来神掌》 - 目录》

《数据库选型之 - 大象十八摸 - 致 架构师、开发者》

《PostgreSQL 使用 pgbench 测试 sysbench 相关case》

《数据库界的华山论剑 tpc.org》

https://www.postgresql.org/docs/10/static/pgbench.html

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
8天前
|
SQL 关系型数据库 MySQL
stream-query多数据库进行CI测试
stream-query多数据库进行CI测试
15 0
|
1月前
|
安全 测试技术
BOSHIDA DC电源模块的安全性能评估与测试方法
BOSHIDA DC电源模块的安全性能评估与测试方法
 BOSHIDA DC电源模块的安全性能评估与测试方法
|
1月前
|
安全
DC电源模块的安全性能评估与测试方法
DC电源模块的安全性能评估与测试方法 DC电源模块的安全性能评估与测试方法应包括以下几个方面: 1. 输入安全性测试:包括输入电压范围、输入电压稳定性、输入电流范围、输入电流保护等方面的测试。测试方法可以是逐步增加输入电压或输入电流,观察模块的工作状态和保护功能。
DC电源模块的安全性能评估与测试方法
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB PostgreSQL版:Oracle兼容的高性能数据库
PolarDB PostgreSQL版是一款高性能的数据库,具有与Oracle兼容的特性。它采用了分布式架构,可以轻松处理大量的数据,同时还支持多种数据类型和函数,具有高可用性和可扩展性。它还提供了丰富的管理工具和性能优化功能,为企业提供了可靠的数据存储和处理解决方案。PolarDB PostgreSQL版在数据库领域具有很高的竞争力,可以满足各种企业的需求。
|
1月前
|
存储 关系型数据库 MySQL
TiDB与MySQL、PostgreSQL等数据库的比较分析
【2月更文挑战第25天】本文将对TiDB、MySQL和PostgreSQL等数据库进行详细的比较分析,探讨它们各自的优势和劣势。TiDB作为一款分布式关系型数据库,在扩展性、并发性能等方面表现突出;MySQL以其易用性和成熟性受到广泛应用;PostgreSQL则在数据完整性、扩展性等方面具有优势。通过对比这些数据库的特点和适用场景,帮助企业更好地选择适合自己业务需求的数据库系统。
|
1月前
|
弹性计算 分布式计算 DataWorks
DataWorks报错问题之ecs自建数据库连通性测试报错如何解决
DataWorks是阿里云提供的一站式大数据开发与管理平台,支持数据集成、数据开发、数据治理等功能;在本汇总中,我们梳理了DataWorks产品在使用过程中经常遇到的问题及解答,以助用户在数据处理和分析工作中提高效率,降低难度。
|
1月前
|
算法 Java 测试技术
性能工具之代码级性能测试工具ContiPerf
【2月更文挑战第23天】性能工具之代码级性能测试工具ContiPerf
266 1
性能工具之代码级性能测试工具ContiPerf
|
1月前
|
NoSQL 算法 测试技术
图数据库基准测试 LDBC SNB 系列讲解:Schema 和数据生成的机制
作为大多数图数据库性能测试标配的 LDBC SNB 它是如何保障不同系统环境之间的测评比较公平且基准测试结果可重复的呢?本文从数据和 Schema 生成入手同你讲解它的原理。
36 2
图数据库基准测试 LDBC SNB 系列讲解:Schema 和数据生成的机制
|
9月前
|
SQL Cloud Native 关系型数据库
ADBPG(AnalyticDB for PostgreSQL)是阿里云提供的一种云原生的大数据分析型数据库
ADBPG(AnalyticDB for PostgreSQL)是阿里云提供的一种云原生的大数据分析型数据库
730 1
|
9月前
|
数据可视化 关系型数据库 MySQL
将 PostgreSQL 迁移到 MySQL 数据库
将 PostgreSQL 迁移到 MySQL 数据库
1052 2

相关产品

  • 云原生数据库 PolarDB