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

升级Heroku PostgreSQL至Essential 1后pg:pull报错:schema '_heroku'不存在

Heroku PostgreSQL升级至Essential 1后pg:pull报错schema "_heroku"不存在的解决办法

问题原因

Heroku PostgreSQL的Essential 1及更高套餐,会自动创建_heroku schema以及配套的事件触发器(如log_create_ext、log_drop_ext),用于管理数据库扩展的生命周期与合法性验证。当执行heroku pg:pull同步数据库到本地时,这些Heroku专属的数据库对象会被一并导出,但本地数据库未预先创建_heroku schema,导致pg_restore执行触发器创建语句时抛出"schema '_heroku' does not exist"错误。

解决办法

方案1:同步时排除Heroku专属schema(推荐)

修改heroku pg:pull命令,添加--exclude-schema="_heroku"参数,直接跳过Heroku专属的schema及其中的对象,避免本地不需要的触发器同步:

修改后的任务脚本如下:

task :download_staging_db do
  puts %x{echo "Setting environment to development"}
  puts %x{rails db:environment:set RAILS_ENV=development}
  puts %x{echo "Dropping existing DB"}
  puts %x{rake db:drop}
  puts %x{echo "Downloading staging DB"}
  puts %x{heroku pg:pull DATABASE_URL <my_db_name> --exclude-table-data="versions" --exclude-schema="_heroku" --app evening-meadow-24924}
end

方案2:本地预先创建_heroku schema(不推荐)

若不想排除schema,可在执行pg:pull前,先在本地数据库手动创建_heroku schema:

# 先创建目标数据库并添加_heroku schema
createdb <my_db_name> && psql <my_db_name> -c "CREATE SCHEMA _heroku;"

之后再运行原有的pg:pull命令即可。此方法会将Heroku的触发器同步到本地,但这些触发器对本地开发环境无实际作用,因此不推荐使用。

内容的提问来源于stack exchange,提问作者Julien

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 07:53:22