Rails—本地机器上现有的开发Postgres数据库到Heroku

时间:2022-12-15 23:30:55

I have developed a Rails 3.2.13 app with PostgreSQL development database on my Windows7 machine. I was able to push my app to heroku with success. However, now I'm stuck at the process of migrating the existing data to Heroku.

我在Windows7机器上开发了一个带有PostgreSQL开发数据库的Rails 3.2.13应用。我成功地将我的应用推向了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
  2. 安装了PG备份heroku addon
  3. 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
  4. 使用命令pg_dump -Fc—no-acl—no-owner -h localhost -U用户myapp_development > myapp_development.dump为我的开发数据库创建一个转储文件
  5. Uploaded the dump file to AWS S3
  6. 将转储文件上传到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. Can anyone please help?

此时,我不确定该如何继续,以恢复转储文件并将其转换为Heroku中的生产数据库。谁能请帮助?

P.S. I also have tried the heroku db:push command, but it gave the following error:

另外,我也尝试过heroku db:push command,但它给出了如下错误:

Failed to connect to database: Sequel::AdapterNotFound -> LoadError: cannot load such file -- pg

未能连接到数据库:Sequel: AdapterNotFound -> LoadError:无法加载此类文件——pg

3 个解决方案

#1


3  

a) On S3, you need to set your dump file to be publicly readable.

在S3上,您需要将转储文件设置为可公开读取。

Within the S3 bucket, right-click the dump file you uploaded, and click 'Make Public'

在S3 bucket中右键单击上传的转储文件,然后单击“Make Public”

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.

现在,当您单击该文件的“Properties”按钮(右上角)时,您将看到一个“Link”值。这意味着文件现在可以从外部访问,包括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)中的“Properties”中看到的URL相同。

  • DATABASE is a heroku keyword for this command, and should be typed out as is. It equates to the DATABASE_URL config setting you see when you run:

    数据库是这个命令的heroku关键字,应该按原样输入。它等于运行时看到的DATABASE_URL配置设置:

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

$ heroku config——应用你的-heroku-app-name

#2


1  

Make sure all gems are install on your system.

确保所有gems安装在您的系统上。

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.

根用户名是数据库用户名,db_name是数据库名。

Good Luck.........!!

.........好运! !

#3


1  

Now that you have the uploaded dump file on S3, you need to tell pgbackups to load up that dump.

现在已经在S3上上传了转储文件,需要告诉pgbackup加载该转储。

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. But if you would like to specify the database, you can use heroku pg:info to find out the name of your database.

DATABASE_URL应该逐字工作。但是如果您想指定数据库,可以使用heroku pg:info来查找数据库的名称。

For me, heroku pg:info prints:

对我来说,heroku pg:信息打印:

=== 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'

#1


3  

a) On S3, you need to set your dump file to be publicly readable.

在S3上,您需要将转储文件设置为可公开读取。

Within the S3 bucket, right-click the dump file you uploaded, and click 'Make Public'

在S3 bucket中右键单击上传的转储文件,然后单击“Make Public”

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.

现在,当您单击该文件的“Properties”按钮(右上角)时,您将看到一个“Link”值。这意味着文件现在可以从外部访问,包括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)中的“Properties”中看到的URL相同。

  • DATABASE is a heroku keyword for this command, and should be typed out as is. It equates to the DATABASE_URL config setting you see when you run:

    数据库是这个命令的heroku关键字,应该按原样输入。它等于运行时看到的DATABASE_URL配置设置:

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

$ heroku config——应用你的-heroku-app-name

#2


1  

Make sure all gems are install on your system.

确保所有gems安装在您的系统上。

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.

根用户名是数据库用户名,db_name是数据库名。

Good Luck.........!!

.........好运! !

#3


1  

Now that you have the uploaded dump file on S3, you need to tell pgbackups to load up that dump.

现在已经在S3上上传了转储文件,需要告诉pgbackup加载该转储。

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. But if you would like to specify the database, you can use heroku pg:info to find out the name of your database.

DATABASE_URL应该逐字工作。但是如果您想指定数据库,可以使用heroku pg:info来查找数据库的名称。

For me, heroku pg:info prints:

对我来说,heroku pg:信息打印:

=== 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'