openGauss维护管理之重启WARNING

时间:2023-03-30 18:15:04

一、概述

1、概述
因为虚拟机内存16g,所以安装openguass的时候没有设置内存参数,直接使用的默认参数
可以在安装的时候指定参数
gs_install -X /opt/software/openGauss/clusterconfig.xml
–gsinit-parameter="–encoding=UTF8" --dn-guc="max_process_memory=2GB"
–dn-guc="shared_buffers=128MB" --dn-guc="bulk_write_ring_size=128MB"
–dn-guc="cstore_buffers=16MB"

2、重启问题
[omm@gsdb01 dn01]$ gs_om -t restart
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
Starting cluster.
=========================================
[SUCCESS] gsdb01
2023-06-28 22:10:10.136 649c3f42.1 [unknown] 140016556824128 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-06-28 22:10:10.136 649c3f42.1 [unknown] 140016556824128 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-06-28 22:10:10.140 649c3f42.1 [unknown] 140016556824128 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (4813 Mbytes) is larger.
=========================================
Successfully started.

二、问题梳理

1、socket问题

could not create any HA TCP/IP sockets
前两个报错根据百度查询是主备复制时使用
当前opengauss是单机版,报这个警告可以忽略

2、memory问题

Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (4813 Mbytes) is larger.
Failed to initialize the memory protect #无法初始化内存保护

1、postgresql.conf分析
#enable_memory_limit = true #默认能够限制内存
max_process_memory = 5GB    #opengauss服务能使用的内存大小
#这俩参数凑一起才能满足内存限制
shared_buffers = 1GB                    # min 128kB
cstore_buffers = 1GB         #min 16MB

官网还有一句解释enable_memory_limit
若max_process_memory –shared memory -cstore_buffers小于2G,opengauss强制把enable_memory_limit设置为false
可以理解为当max_process_memory –shared memory -cstore_buffers小于2G时,enable_memory_limit为false,无法限制opengauss内存使用
也就无法初始化内存保护

2、解决办法
办法一:将max_process_memory调大,让max_process_memory –shared memory -cstore_buffers大于2G就不会报错
办法二:如果不需要列存储缓存,可以将cstore_buffers参数调低
办法三:将shared_buffers调低,这个参数对shared memory的影响非常大

3、分析shared memory和cstore_buffers对启动的影响

1、当max_process_memory –shared memory -cstore_buffers大于2G
enable_memory_limit限制内存参数生效

2、当max_process_memory –shared memory -cstore_buffers小于2G
enable_memory_limit限制内存参数失效

3、当max_process_memory –shared memory -cstore_buffers大于系统内存
直接报错,opengauss启动失败
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (15444 Mbytes) is larger.
FATAL:  could not create shared memory segment: Cannot allocate memory
DETAIL:  Failed system call was shmget(key=26000001, size=16194554184, 03600).
HINT:  This error usually means that openGauss's request for a shared memory segment exceeded available memory or 
swap space, or exceeded your kernel's SHMALL parameter.  You can either reduce the request size or reconfigure the 
kernel with larger SHMALL.  To reduce the request size (currently 16194554184 bytes), reduce openGauss's shared 
memory usage, perhaps by reducing shared_buffers.
        The openGauss documentation contains more information about shared memory configuration.
LOG:  FiniNuma allocIndex: 0.
[gs_ctl]: waitpid 3343028 failed, exitstatus is 256, ret is 2
[gs_ctl]: stopped waiting
[gs_ctl]: could not start server

4、试验shared_buffers对shared memory影响

1、shared_buffers参数调整
shared_buffers = 256kB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (1835 Mbytes) is larger.
shared_buffers = 512kB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (1835 Mbytes) is larger.
#当shared_buffers为kB时,共享内存稳定在1835M附近
shared_buffers = 256MB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (2471 Mbytes) is larger.
shared_buffers = 512MB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (3252 Mbytes) is larger.
#当shared_buffers为MB时,共享内存稳定在(2G左右+shared_buffers)
shared_buffers = 1GB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (4814 Mbytes) is larger.
shared_buffers = 2GB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (5877 Mbytes) is larger.
shared_buffers = 10GB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (14382 Mbytes) is larger.
shared_buffers = 11GB
Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1064 Mbytes) or shared memory (15444 Mbytes) is larger.
#当shared_buffers为GB时,共享内存稳定在(4G左右+shared_buffers)

三、附录内存参数

1、max_process_memory: 
该参数与 enable_memory_limit 配合使用,用于限制一个 openGauss 实例可用的最大内存。需要将该参数值与宿主机系统的内存总量进行匹配,
将宿主机用于操作系统正常运行所需的内存刨除后,剩下的内存空间就可以尽可能多地划分给 openGauss实例使用了。否则,openGauss 为了避免造
成 OOM 问题,会通过该参数限制数据库允许使用的最大内存。因此,如果在客户端或者日志中出现类似“memory usage reach the 
max_dynamic_memory”的报错时,一般是由于该参数值太小导致的。

2、enable_memory_limit = true 
启用逻辑内存管理模块
若max_process_memory –shared memory -cstore_buffers小于2G,opengauss强制把enable_memory_limit设置为false

3、shared_buffers #和share memory有关
shared_buffers:数据库系统使用的缓存池大小。一般来说,综合来看对数据库影响最大的参数就是它了,因为如果该参数设置得过小,会导致缓存不
足,从而产生大量的磁盘 I/O. 该参数在 openGauss上 的默认值很小,只有 1GB,对于绝大多数的生产场景是不够的。一般的经验值是设置为系统
内存的 25%, 甚至在某些场景中还可以再大一点。不过 openGauss 的 buffer 没有通过 DirectIO 实现,仍然使用了系统缓存(cache),所以
一般认为超过系统内存的 40% 也起不到再好的效果了。与此同时,checkpoint_segments 参数也需要随着 shared_buffers 的调大跟着变大一些。

4、work_mem:
显式指定内排序和哈希表能使用的内存空间大小,如果该值设得比较小,会向磁盘写入更多的临时文件。因此,我们可以适当地增加该值的大小。但是
需要注意的是,业务系统可能存在并行执行的复杂语句,如果这些语句都占用非常多的 work_mem 大小的资源,则可能会导致内存使用占满(如前文
所述,openGauss 存在内存管控机制,一般不至于由于 OOM 导致系统重启)。故而,该值设置得很大的时候要关注系统的并发问题。该参数对 
ORDER BY, DISTINCT, JOIN (merge join, hash join), HASH Agg, 基于 hash 的 IN 子查询都有影响。

5、cstore_buffers
设置列存和HDFS所使用的共享缓冲区的大小
列存表使用cstore_buffers设置的共享缓冲区,几乎不用shared_buffers。

6、bulk_write_ring_size #该参数和共享内存无关
数据并行导入使用的环形缓冲区大小。 该参数主要影响入库性能,建议导入压力大的场景增加DN上的该参数配置

7、wal_buffers #预写日志(wal)缓冲区 #和share memory有关
WAL(预写日志)记录写入缓冲区,然后将这些缓冲区刷新到磁盘。
由wal_buffers定义的缓冲区的默认大小为16MB,但如果有大量并发连接的话,则设置为一个较高的值可以提供更好的性能
正常情况下,wal_buffers设置为-1的时候,wal_buffers的大小为shared_buffers的1/32

8、maintenance_work_mem
是用于维护任务的内存设置。默认值为64MB。设置较大的值对于VACUUM,RESTORE,CREATE INDEX,ADD FOREIGN KEY和ALTER TABLE等操作的性能提升效果显著