PostgreSQL启动报错“could not map anonymous shared memory: Cannot allocate memory”

PostgreSQL启动报错"could not map anonymous shared memory: Cannot allocate memory"

bash 复制代码
基础信息
OS版本:Red Hat Enterprise Linux Server release 7.9 (Maipo)
DB版本:16.2
pg软件目录:/home/pg16/soft
pg数据目录:/home/pg16/data
端口:5777

报错

bash 复制代码
[pg16@test ~]$ pg_ctl start
waiting for server to start....2024-06-01 22:20:02.156 PDT [68668] DEBUG:  registering background worker "logical replication launcher"
2024-06-01 22:20:02.157 PDT [68668] DEBUG:  loaded library "pg_stat_statements"
2024-06-01 22:20:02.157 PDT [68668] FATAL:  could not map anonymous shared memory: Cannot allocate memory
2024-06-01 22:20:02.157 PDT [68668] HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 295698432 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
2024-06-01 22:20:02.157 PDT [68668] LOG:  database system is shut down
 stopped waiting
pg_ctl: could not start server
Examine the log output.

PostgreSQL 请求的共享内存段超出了当前可用的内存、交换空间或大页内存 (huge pages)。当前请求的内存大小为 295,698,432 字节(约 282 MB)。

分析记录

bash 复制代码
[pg16@test ~]$ cat data/postgresql.conf |grep shared
shared_buffers = 256MB                  # min 128kB
#shared_memory_type = mmap              # the default is the first option
dynamic_shared_memory_type = posix      # the default is usually the first option
#min_dynamic_shared_memory = 0MB        # (change requires restart)
#wal_buffers = -1                       # min 32kB, -1 sets based on shared_buffers
shared_preload_libraries = 'pg_stat_kcache,pg_stat_statements,auto_explain'     # (change requires restart)
[pg16@test ~]$ cat /proc/meminfo |grep Huge
AnonHugePages:    942080 kB
HugePages_Total:     150
HugePages_Free:        7
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

发现空闲的大页只有7个,不满足pg的启动需求,故报错。最终发现是其它数据库进程占用了,停了之后pg可以正常启动。

解决

bash 复制代码
[pg16@test log]$ pg_ctl start
waiting for server to start....2024-06-02 06:43:45.043 PDT [3636] DEBUG:  registering background worker "logical replication launcher"
2024-06-02 06:43:45.043 PDT [3636] DEBUG:  loaded library "pg_stat_statements"
2024-06-02 06:43:45.051 PDT [3636] LOG:  redirecting log output to logging collector process
2024-06-02 06:43:45.051 PDT [3636] HINT:  Future log output will appear in directory "log".
 done
server started

谨记:心存敬畏,行有所止。

相关推荐
淡水猫.8 分钟前
Fakelocation Server服务器/专业版 ubuntu
运维·服务器·ubuntu
wenyue112115 分钟前
Ease Monitor 会把基础层,中间件层的监控数据和服务的监控数据打通,从总体的视角提供监控分析
运维·中间件·监控
时光の尘24 分钟前
C语言菜鸟入门·关键字·float以及double的用法
运维·服务器·c语言·开发语言·stm32·单片机·c
我们的五年28 分钟前
【Linux课程学习】:进程描述---PCB(Process Control Block)
linux·运维·c++
The_Ticker44 分钟前
CFD平台如何接入实时行情源
java·大数据·数据库·人工智能·算法·区块链·软件工程
Elastic 中国社区官方博客1 小时前
Elasticsearch 开放推理 API 增加了对 IBM watsonx.ai Slate 嵌入模型的支持
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
运维老司机1 小时前
Jenkins修改LOGO
运维·自动化·jenkins
企鹅侠客1 小时前
ETCD调优
数据库·etcd
Json_181790144801 小时前
电商拍立淘按图搜索API接口系列,文档说明参考
前端·数据库
D-海漠1 小时前
基础自动化系统的特点
运维·自动化