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

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

相关推荐
LCY13310 分钟前
spring 中的DAO是什么
运维·git·jenkins
爱写代码的小朋友22 分钟前
华三交换机配置常用命令
运维·服务器·网络
愿你天黑有灯下雨有伞44 分钟前
Docker 安装 Elasticsearch 教程
运维·elasticsearch·docker
遇见火星44 分钟前
自动化发布工具CI/CD实践Jenkins常用工具和插件的使用
运维·ci/cd·自动化·jenkins·自动化发布
低头不见1 小时前
一个服务器算分布式吗,分布式需要几个服务器
运维·服务器·分布式
小爬虫程序猿1 小时前
淘宝商品信息如何存储到数据库?
数据库·爬虫·php
麻芝汤圆1 小时前
使用 MapReduce 进行高效数据清洗:从理论到实践
大数据·linux·服务器·网络·数据库·windows·mapreduce
赋创小助手1 小时前
Gartner预计2025年AI支出达6440亿美元:数据中心与服务器市场的关键驱动与挑战
运维·服务器·人工智能·科技·架构
靠近彗星2 小时前
如何检查 HBase Master 是否已完成初始化?| 详细排查指南
大数据·数据库·分布式·hbase
郑梓妍2 小时前
ubuntu改用户权限
服务器·网络·数据库