复制一个heroku postgres数据库到本地sqlite数据库 [英] Copy a heroku postgres db to a local sqlite db

查看:122
本文介绍了复制一个heroku postgres数据库到本地sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



将postgres数据库复制到另一个postgres数据库很容易,使用 heroku pg:pull 。有谁知道如何使用这个命令将postgres复制到sqlite中

Heroku docs on pg:pull 并未说明如何使用不同类型的dbs。 这篇旧文章暗示它曾经是可能的。设置一个本地postgres数据库是我想避免的。

解决方案

您需要在本地执行 pg_restore -a 选项只能转储数据。



它应该看起来像这样:


  1. 下载数据转储。

      heroku addons :添加pgbackups 
    heroku pgbackups:捕获
    curl -o latest.dump`heroku pgbackups:url`

  2. $

      sudo -u postgres createdb tempdb 
    创建一个临时数据库。 code>


  3. 将转储恢复到您的临时数据库。

      sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -d tempdb latest.dump 


  4. 以正确的格式转储数据。

      sudo -u postgres pg_dump --inserts -a -b tempdb> data.sql 


  5. 在sqlite3中读取dump。

      sqlite3 
    > .read data.sql


这是一个近似值解。您很可能需要做一些小的调整。



我同意克雷格林格,它可能是值得postgres本地运行。希望这个过程能够做到这一点!


I want to copy my heroku production db (postgres) to my development (sqlite).

Copying a postgres db into another postgres db is easy using heroku pg:pull. Does anyone know how to use this command to copy postgres into sqlite?

Heroku docs on pg:pull do not say how to use different types of dbs. This old article implied that it used to be possible. Setting up a local postgres db is something I'd like to avoid.

解决方案

You will need do a pg_restore locally then dump the data using the -a option to dump data only.

It should look something like this:

  1. Download a data dump.

    heroku addons:add pgbackups
    heroku pgbackups:capture
    curl -o latest.dump `heroku pgbackups:url`
    

  2. Create a temporary database.

    sudo -u postgres createdb tempdb
    

  3. Restore the dump to your temporary database.

    sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -d tempdb latest.dump
    

  4. Dump the data in the correct format.

    sudo -u postgres pg_dump --inserts -a -b tempdb > data.sql
    

  5. Read dump in sqlite3.

    sqlite3
    > .read data.sql
    

This is an approximate solution. You will most likely need to make some small adjustments.

I agree with Craig Ringer that it might be worth getting postgres running locally. Hopefully this process will do the trick though!

这篇关于复制一个heroku postgres数据库到本地sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆