【问题标题】:How to copy the data from database on heroku to local database如何将数据从heroku上的数据库复制到本地数据库
【发布时间】:2014-05-30 19:05:45
【问题描述】:

我有一个 Ruby on Rails 应用程序,我想将数据从 Heroku 服务器获取到本地机器。

我已经尝试了中提到的步骤 https://devcenter.heroku.com/articles/heroku-postgres-import-export,但它只是复制数据定义而不是服务器上的实际数据。

有没有办法将数据从 Heroku 获取到本地数据库?

【问题讨论】:

    标签: 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。因此,在此示例中,usernameuser3123database namedb982398。下一部分您将需要它。

    然后,您将使用上述 postgres 字符串中的信息,使用 pg_dump 制作 Heroku 数据库的本地副本。在终端中输入以下内容:

    pg_dump --host=<host_name> --port=<port> --username=<username> --password --dbname=<dbname> > output.sql
    

    在上述代码中&lt;....&gt; 所在的每个位置,输入您的具体信息。输入后,终端会要求您输入密码。输入它。

    最后,您将使用psql 将该转储文件加载到本地数据库中。

    psql -d <local_database_name> -f output.sql
    

    请务必输入本地数据库的名称。

    【讨论】:

      猜你喜欢
      • 2014-04-19
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 2014-05-30
      • 2015-09-11
      • 1970-01-01
      • 2023-04-05
      相关资源
      最近更新 更多