You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Chef的PostgreSQL cookbook遇recipe不存在及扩展安装错误

问题1:postgresql cookbook找不到default recipe报错解决

报错原因

你使用的较新版本sous-chefs postgresql cookbook已废弃默认recipe,整体转型为资源型cookbook,仅提供封装好的postgresql操作资源,不提供开箱即用的默认部署逻辑,因此不存在default.rb文件,直接调用include_recipe 'postgresql'必然触发找不到recipe的报错。

解决步骤

  • 移除所有include_recipe 'postgresql'的调用代码,包括你自行添加的用于调用该默认recipe的冗余default.rb文件
  • 按照你的部署需求,调用cookbook提供的对应资源完成安装配置,基础部署流程示例如下:
# 安装指定版本postgresql服务
postgresql_install 'postgresql' do
  version '14' # 替换为你需要的版本号
  action :install
end

# 启动并启用postgresql服务
postgresql_service 'postgresql' do
  version '14'
  action [:enable, :start]
end

# 配置postgres超级用户密码
postgresql_user 'postgres' do
  password '自定义的postgres用户密码'
  superuser true
  action :create
end

问题2:postgresql_extension资源调用nil报错解决

报错原因

该错误是因为调用postgresql_extension资源时缺少必要的前置依赖配置,资源无法获取到postgresql的运行参数、连接信息,导致读取到nil值后调用[]方法触发报错。

解决步骤

  • 确保调用postgresql_extension之前,已经完成postgresql的安装、服务启动、目标数据库(此处为postgres库)的初始化
  • 给postgresql_extension资源补充必要的连接参数,修改后的资源调用示例如下:
postgresql_extension 'adminpack' do
  database 'postgres'
  extension 'adminpack'
  # 补充postgresql连接凭证,按需调整参数值
  host '127.0.0.1'
  port 5432
  user 'postgres'
  password '你配置的postgres用户密码'
  action :create
end
  • 若上述配置后仍报错,可额外补充version参数关联已安装的postgresql版本,或添加pg_config参数指定pg_config二进制文件的绝对路径。

内容的提问来源于stack exchange,提问作者En-Motion

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 06:42:00