openclaw本地部署报错“password authentication failed”或“database 'openclaw_prod' does not exist”,说明postgresql服务已启动但数据库未初始化或database_url配置错误;需确保容器内使用服务名postgres而非localhost、密码与postgres_password一致、手动创建数据库openclaw_prod并配置pg_hba.conf允许容器间host连接。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

OpenClaw本地部署时提示“password authentication failed for user 'openclaw'”或“database 'openclaw_prod' does not exist”,说明PostgreSQL服务虽已启动,但数据库初始化未完成或连接凭据不匹配,必须修正DATABASE_URL格式并确保数据库实例存在且权限正确。
确认PostgreSQL服务是否真正运行
执行 docker ps | grep postgres 查看容器状态。如果容器未运行,先启动它:docker-compose up -d postgres。
若容器显示“healthy”但连接仍失败,进入容器内部验证服务可访问性:docker exec -it openclaw-postgres psql -U openclaw -d postgres。能成功登录说明服务正常;若报错“psql: error: connection to server on socket... refused”,则PostgreSQL进程未监听默认端口或配置了错误的host绑定。
检查并修正DATABASE_URL环境变量
打开 .env 文件,定位 DATABASE_URL 行。常见错误是写成 postgres://openclaw:password@localhost:5432/openclaw_prod —— 这在Docker Compose环境下必然失败,因为容器内localhost指向自身而非宿主机PostgreSQL。
【必须改为容器网络内可解析的地址】:若使用docker-compose.yml定义了postgres服务,则URL应为 postgres://openclaw:your_password@postgres:5432/openclaw_prod,其中postgres是服务名,不是IP或localhost。
密码字段必须与postgres服务配置中定义的POSTGRES_PASSWORD完全一致。检查docker-compose.yml中该服务的environment块,确认POSTGRES_USER设为openclaw、POSTGRES_DB设为openclaw_prod。
手动初始化缺失的数据库
第一步:进入PostgreSQL容器执行命令:docker exec -it openclaw-postgres bash。
本次更新实现飞书插件 npm 独立分发,新增 Ollama 本地模型配置及 openclaw 命令别名。引入 SQLite 持久化队列,支持断点续传。全面集成飞书、钉钉、企业微信及 QQ 官方渠道,优化阿里云百炼模型选择。修复多 Agent 路由、定时任务校验及配对授权等关键问题,提升系统稳定性与兼容性。
第二步:切换到postgres用户并启动psql:su - postgres -c "psql"。
第三步:创建数据库(若不存在):CREATE DATABASE openclaw_prod OWNER openclaw;。
第四步:退出psql后,执行exit返回宿主机终端。
这一步不可跳过——OpenClaw不会自动创建数据库,只会在已有库上建表。若跳过此步,后续迁移将报错database "openclaw_prod" does not exist。
验证pg_hba.conf访问控制规则
方法一:在容器内检查配置文件路径:docker exec openclaw-postgres cat /var/lib/postgresql/data/pg_hba.conf | grep -E "(local|host)"。
关键行应包含:host all all all md5 或至少覆盖openclaw_prod库和openclaw用户。若只有local all all peer而无host规则,则远程连接(包括来自其他容器)会被拒绝。
方法二:临时放宽权限(仅测试用)——向pg_hba.conf末尾追加:host all all 0.0.0.0/0 md5,然后重启PostgreSQL容器:docker restart openclaw-postgres。









