【问题标题】:How to copy the data from database on heroku to local database如何将数据从heroku上的数据库复制到本地数据库
【发布时间】:2014-05-30 19:05:45
【问题描述】:
【问题讨论】:
标签:
ruby-on-rails
ruby
heroku
【解决方案1】:
尝试使用here 详述的步骤。
基本上,使用heroku config:get 从您的 Heroku 数据库中获取信息。查找您的 Heroku Postgres 网址。它看起来像这样:HEROKU_POSTGRESQL_RED_URL: postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398。请注意,字符串配置为database://username:password@host:port/databasename。因此,在此示例中,username 是 user3123,database name 是 db982398。下一部分您将需要它。
然后,您将使用上述 postgres 字符串中的信息,使用 pg_dump 制作 Heroku 数据库的本地副本。在终端中输入以下内容:
pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<dbname> > output.sql
在上述代码中<....> 所在的每个位置,输入您的具体信息。输入后,终端会要求您输入密码。输入它。
最后,您将使用psql 将该转储文件加载到本地数据库中。
psql -d <local_database_name> -f output.sql
请务必输入本地数据库的名称。