PostgreSQL 10.0 preview 多核并行增强 - 控制集群并行度

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

标签

PostgreSQL , 多核并行 , 集群并行度 , SQL并行度 , NODE并行度


背景

PostgreSQL 9.6引入多核并行,一条SQL可以使用多个CPU核,提升SQL性能。

但是多核并行一定不要滥用,因为CPU资源有限,如果单个QUERY把CPU都用光了,其他QUERY就会因为缺乏CPU资源造成性能抖动。

9.6刚出来的时候,可以控制单个gather的并行度,比如全表扫描,扫描节点算一个gather,一个gather下面会fork 一些worker process执行并行任务。

9.6通过max_worker_processes参数控制整个集群的并行度,同时运行的QUERY,同时启动的worker process总数不能超过max_worker_processes设置的值。

但是系统中还有其他功能还需要fork worker process,比如pg_base_basckup,比如standby,都会用到worker process。

那么多核计算很可能会影响这些应用。

10.0 新增了一个控制多核并行的参数max_parallel_workers,用于控制整个集群允许开启的用于多核计算的worker process.

这样就可以控制用于并行的workers不会占满所有的max_worker_processes。

设置max_parallel_workers后,可以大幅提升开启并行计算后的数据库OLTP稳定性。

建议的配置

比如64核的机器

max_parallel_workers_per_gather(8) < max_parallel_workers(48) < max_worker_processes(64)

相关参数

1. max_worker_processes (integer)

设置集群允许fork的最大worker process数目

Sets the maximum number of background processes that the system can support. This parameter can only be set at server start. The default is 8.    
    
When running a standby server, you must set this parameter to the same or higher value than on the master server. Otherwise, queries will not be allowed in the standby server.    
    
When changing this value, consider also adjusting max_parallel_workers and max_parallel_workers_per_gather.    

2. max_parallel_workers_per_gather (integer)

设置QUERY中单个gather node允许开启的worker process数目

Sets the maximum number of workers that can be started by a single Gather node.     
    
Parallel workers are taken from the pool of processes established by max_worker_processes, limited by max_parallel_workers.     
    
Note that the requested number of workers may not actually be available at runtime.     
    
If this occurs, the plan will run with fewer workers than expected, which may be inefficient.     
    
The default value is 2. Setting this value to 0 disables parallel query execution.    
    
Note that parallel queries may consume very substantially more resources than non-parallel queries,     
    
because each worker process is a completely separate process which has roughly the same impact on the system as an additional user session.     
    
This should be taken into account when choosing a value for this setting, as well as when configuring other settings that control resource utilization,     
    
such as work_mem. Resource limits such as work_mem are applied individually to each worker,     
    
which means the total utilization may be much higher across all processes than it would normally be for any single process.     
    
For example, a parallel query using 4 workers may use up to 5 times as much CPU time, memory, I/O bandwidth, and so forth as a query which uses no workers at all.    
    
For more information on parallel query, see Chapter 15, Parallel Query.    

3. max_parallel_workers (integer)

设置整个数据库集群,允许同时开启的用于多核计算的worker process数目

Sets the maximum number of workers that the system can support for parallel queries. The default value is 8.     
    
When increasing or decreasing this value, consider also adjusting max_parallel_workers_per_gather.     
    
Also, note that a setting for this value which is higher than max_worker_processes will have no effect, since parallel workers are taken from the pool of worker processes established by that setting.    

除此之外,PostgreSQL的并行度是如何计算,如何控制并行度的?请参考

《PostgreSQL 9.6 并行计算 优化器算法浅析》

后续优化

1. 按时间段配置并行度,比如0点到8点,并行度开到最大。平时降一半。

这种配置可以用于OLAP+OLTP的混合场景,例如晚上用于统计,白天用于OLTP,白天即使有多核并行的QUERY,由于现在了集群级别的并行度,所以对OLTP也不会有影响。

2. 如果你要设置单个会话的最大并行度,可以设置会话级别的max_parallel_workers参数,如果你要设置单个QUERY的最大并行度,则设置max_parallel_workers或者max_parallel_workers_per_gather即可

参考

https://www.postgresql.org/docs/devel/static/runtime-config-resource.html

《PostgreSQL 9.6 并行计算 优化器算法浅析》

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
5月前
|
消息中间件 存储 关系型数据库
PostgreSQL技术大讲堂 - 第33讲:并行查询管理
PostgreSQL从小白到专家,技术大讲堂 - 第33讲:并行查询管理
289 1
|
4月前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL版并行查询技术探索与实践
PolarDB MySQL版并行查询技术探索与实践 PolarDB MySQL版在企业级查询加速特性上进行了深度技术探索,其中并行查询作为其重要组成部分,已经在线稳定运行多年,持续演进。本文将详细介绍并行查询的背景、挑战、方案、特性以及实践。
108 2
|
6月前
|
存储 关系型数据库 数据库
用Patroni配置PostgreSQL高可用集群
Patroni是Zalando开发的数据库高可用管理软件,用于编排和自动化PostgreSQL集群的管理过程。Patroni 需要一系列其他组件的支持,通过利用第三方分布式一致性软件,组建并实现数据库高可用方案。
515 4
用Patroni配置PostgreSQL高可用集群
|
1月前
|
存储 Kubernetes 分布式数据库
利用Helm在K8S上部署 PolarDB-X 集群(详细步骤--亲测!!!)
利用Helm在K8S上部署 PolarDB-X 集群(详细步骤--亲测!!!)
84 0
|
7月前
|
存储 关系型数据库 网络安全
如何开通PostgreSQL的专属集群
本案例旨在展示如何开通PostgreSQL的专属集群。
69 1
|
3月前
|
安全 关系型数据库 分布式数据库
在PolarDB中能否申请集群的公网地址?
在PolarDB中能否申请集群的公网地址?
40 2
|
3月前
|
弹性计算 关系型数据库 MySQL
设置PolarDB MySQL版集群IP白名单教程
设置PolarDB MySQL版集群IP白名单教程 内容: 在创建PolarDB MySQL版数据库集群后,为了保证集群的安全性,您需要设置集群的IP白名单。只有添加到白名单中的IP地址或安全组中的ECS实例才能访问该集群。本文将详细介绍如何设置IP白名单。
119 2
|
3月前
|
存储 关系型数据库 分布式数据库
在PolarDB中,集群地址对应一个代理服务器,主地址也是对应一个代理服务器吗?
在PolarDB中,集群地址对应一个代理服务器,主地址也是对应一个代理服务器吗?
32 0
|
4月前
|
SQL 关系型数据库 分布式数据库
深度解析PolarDB数据库并行查询技术
深度解析PolarDB数据库并行查询技术:加速SQL执行的关键问题和核心技术 随着数据规模的不断扩大,用户SQL的执行时间越来越长,这不仅对数据库的优化能力提出更高的要求,并且对数据库的执行模式也提出了新的挑战。为了解决这个问题,许多数据库系统,包括Oracle、SQL Server等,都开始提供并行查询引擎的支持,以充分利用系统资源,达到加速SQL执行的效果。本文将深入探讨基于代价进行并行优化、并行执行的云数据库的并行查询引擎的关键问题和核心技术。
123 2
|
6月前
|
消息中间件 关系型数据库 Kafka
TiDB实时同步数据到PostgreSQL(一) ---- 搭建kafka集群
TiDB实时同步数据到PostgreSQL的第一篇,主要介绍kafka集群的搭建。
137 0

相关产品

  • 云原生数据库 PolarDB