问题描述
将postgres数据库复制到另一个postgres数据库很容易,使用 heroku pg:pull
。有谁知道如何使用这个命令将postgres复制到sqlite中?
并未说明如何使用不同类型的dbs。 暗示它曾经是可能的。设置一个本地postgres数据库是我想避免的。
您需要在本地执行 pg_restore
-a
选项只能转储数据。
它应该看起来像这样:
-
下载数据转储。
heroku addons :添加pgbackups
heroku pgbackups:捕获
curl -o latest.dump`heroku pgbackups:url`
$ -
将转储恢复到您的临时数据库。
sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -d tempdb latest.dump
-
以正确的格式转储数据。
sudo -u postgres pg_dump --inserts -a -b tempdb> data.sql
-
在sqlite3中读取dump。
sqlite3
> .read data.sql
sudo -u postgres createdb tempdb
创建一个临时数据库。 code>
这是一个近似值解。您很可能需要做一些小的调整。
我同意,它可能是值得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:
Download a data dump.
heroku addons:add pgbackups heroku pgbackups:capture curl -o latest.dump `heroku pgbackups:url`
Create a temporary database.
sudo -u postgres createdb tempdb
Restore the dump to your temporary database.
sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -d tempdb latest.dump
Dump the data in the correct format.
sudo -u postgres pg_dump --inserts -a -b tempdb > data.sql
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数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!