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

标签

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 并行计算 优化器算法浅析》

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: postgresql10.0_x64-haosq.zip是一个文件名,它表示的是一个带有哈斯克编译器的64位PostgreSQL 10.0版本的压缩包。 PostgreSQL是一个功能强大且可扩展的开源关系数据库管理系统。它支持多种操作系统,包括Windows、Linux和Mac OS等。在这个压缩包中,"x64"表示支持64位操作系统,"haosq"可能是压缩包的创建者或者对该版本进行了某种修改。 要安装该版本的PostgreSQL,首先需要解压缩这个压缩包。然后,可以按照官方提供的安装指南进行安装和配置。在安装完成后,可以通过命令行或者可视化界面工具来管理和使用PostgreSQL数据库PostgreSQL 10.0版本在性能、安全性和功能方面有很多改进和新增的特性。其中包括改进的并行查询处理、逻辑复制、数据分区、JSONB索引等等。这些功能可以提升数据库的性能和灵活性,使其更适合处理复杂的数据工作负载。 总之,postgresql10.0_x64-haosq.zip是一个64位的PostgreSQL 10.0版本的压缩包,你可以使用它来安装和配置这个强大的开源数据库管理系统。 ### 回答2: postgresql10.0_x64-haosq.zip是一个PostgreSQL数据库的安装文件。PostgreSQL是一个开源的关系型数据库管理系统,具有高度稳定性和可靠性,广泛应用于各种规模的应用程序和网站开发中。 这个压缩文件中的x64表示适用于64位操作系统的安装版本。haosq是一个识别码,可能是某个发行版本的标识或个人定制版本的命名。 安装PostgreSQL通常需要以下步骤:首先,解压缩haosq.zip文件到你希望安装的目录。然后,运行安装文件来启动安装向导,按照向导的指示完成安装过程。在安装过程中,你可以选择安装的组件和配置选项,例如选择安装PostgreSQL服务器、客户端和相关工具、选择安装位置等。安装完成后,你需要配置数据库的初始设置,例如设置用户名、密码、监听地址和端口等。 安装完成后,你可以使用PostgreSQL提供的命令行工具或者可视化管理工具来管理数据库。你可以创建数据库、创建表和索引、执行SQL查询、导入导出数据等。PostgreSQL还支持事务和并发控制,提供了各种高级功能和扩展。 总之,postgresql10.0_x64-haosq.zip是一个PostgreSQL数据库的安装文件,通过它可以方便地安装和使用PostgreSQL数据库

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值