简体   繁体   English

Rails-Heroku在本地计算机上的现有开发Postgres数据库

[英]Rails - existing development Postgres database on local machine to Heroku

I have developed a Rails 3.2.13 app with PostgreSQL development database on my Windows7 machine. 我已经在Windows7机器上使用PostgreSQL开发数据库开发了Rails 3.2.13应用程序。 I was able to push my app to heroku with success. 我能够成功地将我的应用程序推送到heroku。 However, now I'm stuck at the process of migrating the existing data to Heroku. 但是,现在我陷入了将现有数据迁移到Heroku的过程中。

I have tried following along the documentation by Heroku, but I can't seem to get it to work. 我已经尝试按照Heroku的文档进行操作,但是似乎无法正常工作。

Here's what I have done so far: 到目前为止,这是我所做的:

  1. Installed the PG Backups heroku addon 安装了PG备份heroku插件
  2. Created a dump file for my development database with the command pg_dump -Fc --no-acl --no-owner -h localhost -U user myapp_development > myapp_development.dump 使用命令pg_dump -Fc --no-acl --no-owner -h localhost -U user myapp_development > myapp_development.dump为我的开发数据库创建了一个转储文件
  3. Uploaded the dump file to AWS S3 将转储文件上传到AWS S3

At this point, I am not sure how to proceed, to restore the dump file and turn it to a production database in Heroku. 在这一点上,我不确定如何继续还原转储文件并将其转换为Heroku中的生产数据库。 Can anyone please help? 谁能帮忙吗?

PS I also have tried the heroku db:push command, but it gave the following error: PS我也尝试了heroku db:push命令,但是给出了以下错误:

Failed to connect to database: Sequel::AdapterNotFound -> LoadError: cannot load such file -- pg 无法连接到数据库:Sequel :: AdapterNotFound-> LoadError:无法加载此类文件-pg

a) On S3, you need to set your dump file to be publicly readable. a)在S3上,您需要将转储文件设置为公开可读。

Within the S3 bucket, right-click the dump file you uploaded, and click 'Make Public' 在S3存储桶中,右键单击您上传的转储文件,然后单击“公开”

Now, when you click the 'Properties' button (top-right area) for that file, you will see a 'Link' value. 现在,当您单击该文件的“属性”按钮(右上角)时,您将看到一个“链接”值。 This means the file is now accessible from outside, including by Heroku. 这意味着该文件现在可以从外部(包括Heroku)进行访问。

b) You will need to run a command like this to restore this pg dump to your heroku database: b)您将需要运行以下命令来将此pg dump还原到您的heroku数据库中:

$ heroku pgbackups:restore DATABASE 'http://your.s3.domain.here.s3-us-xxxx-xx.amazonaws.com/myapp_development.dump' --app your-heroku-app-name

Notes: 笔记:

  • To run the 'heroku' command, you'll need to install the heroku toolbelt. 要运行“ heroku”命令,您需要安装heroku工具带。

  • Note that the http URL in step (b) will be the same public URL as the one you saw in 'Properties' in step (a) above. 请注意,步骤(b)中的http URL与您在上述步骤(a)中“属性”中看到的URL是相同的公共URL。

  • DATABASE is a heroku keyword for this command, and should be typed out as is. DATABASE是此命令的heroku关键字,应原样输入。 It equates to the DATABASE_URL config setting you see when you run: 它等于您在运行时看到的DATABASE_URL配置设置:

$ heroku config --app your-heroku-app-name

Now that you have the uploaded dump file on S3, you need to tell pgbackups to load up that dump. 现在您已经在S3上上传了转储文件,您需要告诉pgbackups加载该转储。

Try something like this: 尝试这样的事情:

$ heroku pgbackups:restore DATABASE_URL 'https://s3.amazonaws.com/mybucket/path/to/myapp_development.dump'

I found that command here: https://devcenter.heroku.com/articles/heroku-postgres-import-export 我在这里找到了该命令: https : //devcenter.heroku.com/articles/heroku-postgres-import-export

Edit: 编辑:

DATABASE_URL should work verbatim. DATABASE_URL应该逐字记录。 But if you would like to specify the database, you can use heroku pg:info to find out the name of your database. 但是,如果您想指定数据库,则可以使用heroku pg:info来查找数据库的名称。

For me, heroku pg:info prints: 对我来说, heroku pg:info打印:

=== HEROKU_POSTGRESQL_COPPER_URL (DATABASE_URL)
Plan:        Basic
Status:      available
Connections: 1
PG Version:  9.1.9
Created:     2013-03-06 17:21 UTC
Data Size:   9.5 MB
Tables:      9
Fork/Follow: Unsupported

So, in my case I would use: 因此,就我而言,我将使用:

$ heroku pgbackups:restore HEROKU_POSTGRESQL_COPPER_URL 'https://s3.amazonaws.com/mybucket/path/to/myapp_development.dump'

Make sure all gems are install on your system. 确保在系统上安装了所有gem。

sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby

gem install heroku taps sequel

sudo gem install tabs

sudo heroku db:push

OR 要么

sudo heroku db:push –config herokuServerName

If still problem. 如果仍然有问题。 Use below command 使用以下命令

heroku db:pull postgres://root:@localhost/db_name

Else 其他

sudo heroku db:pull --confirm herokuDomanName postgres://userName:@localhost/Locadatabase

root will be database user name and db_name is database name. root将是数据库用户名,db_name是数据库名。

Good Luck.........!! 祝好运.........!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails 4:如何在本地机器上运行从 Heroku 下载的 Postgres 数据库? - Rails 4: How do you run a Postgres database downloaded from Heroku on my local machine? Rails - 将Postgres生产数据库导入本地开发数据库 - Rails - importing Postgres production database to local development database 无法通过Rails连接Heroku上的现有Postgres数据库 - Can't connect existing postgres database on heroku via rails Rails 和现有的 Postgres 数据库 - Rails and Existing Postgres Database 反引号(`)导致heroku(postgres)出现问题,但本地机器没有问题 - Backtick (`) causing problems with heroku (postgres) but not with local machine 本地sql数据库和heroku postgres数据库文件不同,如何再次同步? Ruby on Rails - Local sql database and heroku postgres database files differ, how to sync again? Ruby on Rails 使用Rails 4 App在Heroku上重定向循环,但不在本地计算机上重定向循环 - Redirect Loop on Heroku with Rails 4 App, but not on local machine 配置rails以使用网络计算机上的数据库进行开发 - configure rails to use database on a network machine for development 在Rails / Heroku上对Postgres数据库的意外SQL查询 - Unexpected SQL queries to Postgres database on Rails/Heroku Rails/Postgres/Heroku 数据库连接失败 - Rails/Postgres/Heroku database connection failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM