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

本文涉及的产品
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS SQL Server,基础系列 2核4GB
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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
存储 关系型数据库 数据库
用Patroni配置PostgreSQL高可用集群
Patroni是Zalando开发的数据库高可用管理软件,用于编排和自动化PostgreSQL集群的管理过程。Patroni 需要一系列其他组件的支持,通过利用第三方分布式一致性软件,组建并实现数据库高可用方案。
用Patroni配置PostgreSQL高可用集群
|
消息中间件 存储 关系型数据库
PostgreSQL技术大讲堂 - 第33讲:并行查询管理
PostgreSQL从小白到专家,技术大讲堂 - 第33讲:并行查询管理
587 1
|
关系型数据库 MySQL Nacos
nacos数据库使用PostgreSQL及集群配置
从Nacos2.2版本开始,Nacos提供了数据源扩展插件,以便让需要进行其他数据库适配的用户自己编写插件来保存数据。
|
10月前
|
存储 关系型数据库 数据库
【赵渝强老师】PostgreSQL的数据库集群
PostgreSQL的逻辑存储结构涵盖了数据库集群、数据库、表、索引、视图等对象,每个对象都有唯一的oid标识。数据库集群是由单个PostgreSQL实例管理的所有数据库集合,共享同一配置和资源。集群的数据存储在一个称为数据目录的单一目录中,可通过-D选项或PGDATA环境变量指定。
147 3
|
存储 关系型数据库 网络安全
如何开通PostgreSQL的专属集群
本案例旨在展示如何开通PostgreSQL的专属集群。
|
关系型数据库 大数据 PostgreSQL
PostgreSQL16-新特性-并行聚合
PostgreSQL16-新特性-并行聚合
297 0
|
关系型数据库 测试技术 数据库
`pg_rewind` 是 PostgreSQL 数据库的一个工具,用于将一个数据库集群回退到指定的时间点
pg_rewind 是 PostgreSQL 数据库的一个工具,用于将一个数据库集群回退到指定的时间点。这对于恢复数据或解决某些问题非常有用。 简单来说,如果你有一个 PostgreSQL 数据库集群并且你知道在某个时间点它是健康的,但之后出现了问题,你可以使用 pg_rewind 来将数据库回退到那个时间点,从而恢复到已知的、健康的、一致的状态。 使用 pg_rewind 的基本步骤如下: 确定基准时间:首先,你需要确定一个基准时间点,知道在该时间点上数据库是健康的。 备份当前数据库:在执行 pg_rewind 之前,确保你已经备份了当前的数据库。 执行 pg_rewind:使用
440 1
|
存储 关系型数据库 数据库
PostgreSQL复制原理及高可用集群
文章来自: 朱贤文 | 成都文武信息技术有限公司 分析
534 1
|
消息中间件 关系型数据库 Kafka
TiDB实时同步数据到PostgreSQL(一) ---- 搭建kafka集群
TiDB实时同步数据到PostgreSQL的第一篇,主要介绍kafka集群的搭建。

相关产品

  • 云原生数据库 PolarDB
  • 云数据库 RDS PostgreSQL 版
  • 推荐镜像

    更多