【问题标题】:Can the pg gem be used to import database dump (.sql) files?pg gem 可以用来导入数据库转储(.sql)文件吗?
【发布时间】:2014-10-12 17:02:04
【问题描述】:

我们有一些实用程序 rake 任务,用于将 postgres 数据库从 Heroku 克隆到本地开发机器,以便使用“真实”数据进行测试。他们倾向于使用 pg_restore 的 shell 命令运行导入,例如

sh 'pg_restore --verbose --clean --create --no-owner -h localhost <dbname> <filename>'

这种 postgres 操作是否可以通过 pg gem(Rails 已经到位)来实现,或者我们这里的 punt-to-shell 操作真的是最好的方法吗?我在the documentation 中没有发现任何有希望的东西。

【问题讨论】:

    标签: ruby postgresql heroku rake


    【解决方案1】:

    由于pg_dumppg_restore 是存在于postgres 库之外的命令,我不相信有办法使用pg gem 来实现这一点。但是,根据您要完成的工作的 heroku 文档,看起来您正在按照recommend

    的方式进行操作
    heroku pgbackups:capture
    curl -o latest.dump `heroku pgbackups:url`
    pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
    

    【讨论】:

    • 啊,这是一个很好的理由,我不会在 pg 中找到函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2017-01-23
    • 1970-01-01
    相关资源
    最近更新 更多