麒麟信创系统安装pgsql-15.4 报错 popen failure: Cannot allocate memory
[root@iZbp1jchymfq9318t02m5wZ pgsql]# docker-compose up
[+] Running 11/14
[+] Running 14/14⣿⣿⣿⣿⣿⣿⣿⣿⠀⣿⣿⣿⠀] Pulling 15.9✔ pgsql-15.4 Pulled 42.5s ✔ 578acb154839 Pull complete 7.9s ✔ 9abc159edb5f Pull complete 8.0s ✔ b742e0d9e952 Pull complete 8.2s ✔ 8d6c67b42441 Pull complete 8.3s ✔ 4ddc08bac214 Pull complete 8.7s ✔ cf5a0484b6d9 Pull complete 8.8s ✔ 1b4a0642b63d Pull complete 8.9s ✔ 2f2829f664a0 Pull complete 9.0s ✔ 7877975bfbf0 Pull complete 41.8s ✔ e4b736138f60 Pull complete 41.9s ✔ 2ce63fdb79b4 Pull complete 41.9s ✔ 5734338d16e4 Pull complete 42.0s ✔ 0a84e9353ffb Pull complete 42.1s
[+] Running 1/1✔ Container pgsql-15.4 Created 1.6s
Attaching to pgsql-15.4
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 exited with code 1
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
pgsql-15.4 | popen failure: Cannot allocate memory
pgsql-15.4 | initdb: error: program "postgres" is needed by initdb but was not found in the same directory as "/usr/lib/postgresql/15/bin/initdb"
1、创建诊断脚本
cat > diagnose_docker_postgres.sh << 'EOF'
#!/bin/bashecho "======================================"
echo "PostgreSQL Docker 问题诊断脚本"
echo "======================================"
echo ""# 1. 系统基本信息
echo "【1. 系统信息】"
echo "内核版本: $(uname -r)"
echo "系统版本: $(cat /etc/redhat-release 2>/dev/null || cat /etc/os-release | grep PRETTY_NAME)"
echo "CPU核心数: $(nproc)"
free -h
echo ""# 2. 内存相关参数
echo "【2. 内存相关内核参数】"
echo "overcommit_memory: $(cat /proc/sys/vm/overcommit_memory)"
echo "overcommit_ratio: $(cat /proc/sys/vm/overcommit_ratio)"
echo "max_map_count: $(cat /proc/sys/vm/max_map_count)"
echo "swappiness: $(cat /proc/sys/vm/swappiness)"
echo ""# 3. Docker 信息
echo "【3. Docker 信息】"
docker version
echo ""
docker info | grep -E "Storage Driver|Cgroup Driver|Cgroup Version|Operating System|Kernel Version"
echo ""# 4. 检查 cgroup 限制
echo "【4. Cgroup 限制检查】"
if [ -d /sys/fs/cgroup/memory/docker ]; thenecho "Memory cgroup 配置:"cat /sys/fs/cgroup/memory/docker/memory.limit_in_bytes 2>/dev/null || echo "无法读取"cat /sys/fs/cgroup/memory/docker/memory.memsw.limit_in_bytes 2>/dev/null || echo "无法读取"
fi
echo ""# 5. 检查 Docker 存储
echo "【5. Docker 存储空间】"
df -h | grep -E "Filesystem|/var/lib/docker|overlay"
echo ""
docker system df
echo ""# 6. 测试容器内存分配
echo "【6. 测试简单容器运行】"
echo "运行测试容器..."
docker run --rm alpine sh -c "echo '容器可以正常运行'; free -m" 2>&1
echo ""# 7. 测试 PostgreSQL 容器内部
echo "【7. 测试 PostgreSQL 镜像内部】"
echo "检查 postgres 程序是否存在..."
docker run --rm postgres:15.4 sh -c "ls -la /usr/lib/postgresql/15/bin/postgres 2>&1; which postgres 2>&1"
echo ""# 8. 测试内存限制的容器
echo "【8. 测试带内存限制的 PostgreSQL】"
echo "尝试以 512MB 内存限制运行..."
timeout 10 docker run --rm -m 512m \-e POSTGRES_PASSWORD=test123 \postgres:15.4 2>&1 | head -20
echo ""# 9. 检查 SELinux
echo "【9. SELinux 状态】"
getenforce 2>/dev/null || echo "SELinux 未安装"
echo ""# 10. 检查资源限制
echo "【10. 系统资源限制】"
ulimit -a
echo ""# 11. 检查 dmesg 错误
echo "【11. 最近的内核错误(OOM/内存相关)】"
dmesg | grep -i -E "out of memory|oom|kill|memory" | tail -20
echo ""# 12. 尝试修复建议
echo "======================================"
echo "【尝试以下修复方案】"
echo "======================================"
echo ""
echo "方案1: 调整内核参数"
echo "----------------------------------------"
echo "sudo sysctl -w vm.overcommit_memory=1"
echo "sudo sysctl -w vm.max_map_count=262144"
echo ""
echo "方案2: 修改 docker-compose.yml 添加配置"
echo "----------------------------------------"
cat << 'COMPOSE'
services:pgsql-15.4:container_name: pgsql-15.4image: postgres:15.4restart: alwaysports:- "5432:5432"environment:TZ: Asia/ShanghaiPOSTGRES_USER: pgvectorPOSTGRES_PASSWORD: bCK27cNKp4Ypafi75volumes:- ./data:/var/lib/postgresql/data# 添加以下配置shm_size: '256mb'security_opt:- seccomp:unconfinedtmpfs:- /tmp- /run
networks:default:external: truename: shgbitai-network
COMPOSE
echo ""
echo "方案3: 不使用 volume,测试是否是权限问题"
echo "----------------------------------------"
echo "docker run -d --name test-pg -e POSTGRES_PASSWORD=test123 postgres:15.4"
echo ""EOF
添加执行权限
chmod +x diagnose_docker_postgres.sh
运行诊断
bash./diagnose_docker_postgres.sh > diagnostic_report.txt 2>&1
cat diagnostic_report.txt
同时,立即尝试这个快速测试
# 测试1: 不挂载 volume,直接运行
echo "测试1: 不使用 volume"
docker run -d --name test-pg-no-volume \-e POSTGRES_PASSWORD=test123 \postgres:15.4sleep 5
docker logs test-pg-no-volume
docker rm -f test-pg-no-volumeecho ""
echo "================================"
echo ""# 测试2: 调整内核参数后运行
echo "测试2: 调整内核参数"
sysctl -w vm.overcommit_memory=1
sysctl -w vm.max_map_count=262144# 修改 docker-compose.yml
cat > docker-compose-test.yml << 'EOF'
services:pgsql-15.4:container_name: pgsql-15.4-testimage: postgres:15.4restart: "no"ports:- "5432:5432"environment:TZ: Asia/ShanghaiPOSTGRES_USER: pgvectorPOSTGRES_PASSWORD: bCK27cNKp4Ypafi75volumes:- ./data:/var/lib/postgresql/datashm_size: '256mb'security_opt:- seccomp:unconfined
networks:default:external: truename: shgbitai-network
EOF
docker-compose -f docker-compose-test.yml up
