简体   繁体   English

Heroku Postgres 数据库到 ElephantSQL

[英]Heroku Postgres Database to ElephantSQL

I have a Postgres database on Heroku and I want to have that database hosted on ElephantSQL, but I cannot for the life of me find how to do it.我在 Heroku 上有一个 Postgres 数据库,我想将该数据库托管在 ElephantSQL 上,但我一生都找不到如何去做。 I have a DUMP file downloaded from the Heroku Postgres database, but I cannot find how I put the data into ElephantSQL.我有一个从 Heroku Postgres 数据库下载的 DUMP 文件,但我找不到如何将数据放入 ElephantSQL。

My database was linked to a Django app and I already have my instance on ElephantSQL linked to the a copy of the same Django app, but hosted on Render.我的数据库链接到一个 Django 应用程序,我已经将 ElephantSQL 上的实例链接到同一个 Django 应用程序的副本,但托管在 Render 上。 I can see on ElephantSQL that the instance has all the tables, so I just need to put the data in there somehow.我可以在 ElephantSQL 上看到该实例具有所有表,所以我只需要以某种方式将数据放在那里。

Any tips or hints are welcome!欢迎任何提示或提示!

The tables that you already see may be the problem.您已经看到的表格可能是问题所在。 It may also be that the parents of those tables are the problem.也可能是这些表的父表有问题。 An SQL dump is just a series of SQL commands that run in order to write schema and data back into a new database. SQL 转储只是一系列 SQL 命令,运行这些命令是为了将模式和数据写回新数据库。

The first SQL commands set up the databases, schemas, and tables.第一个 SQL 命令设置数据库、模式和表。 If your tables are already there, your import may be failing because it wants to create new tables that already exist.如果您的表已经存在,您的导入可能会失败,因为它想要创建已经存在的新表。 Sorry without more information on the specific errors you are seeing, it's hard to be more specific.抱歉,没有关于您所看到的特定错误的更多信息,很难更具体。 Hopefully one of these 4 options help you.希望这 4 个选项中的一个对您有所帮助。 Let me know in the comments how it goes.在评论中让我知道进展情况。

For all of the options below, I would suggest backing up your destination server database to be sure that you don't mess up the Django app that currently is working there even without your data.对于下面的所有选项,我建议备份您的目标服务器数据库,以确保即使没有您的数据,您也不会弄乱当前正在那里运行的 Django 应用程序。

Option 1: Look for a way to export your source database without database, schema, and table definitions.选项 1:寻找一种无需数据库、架构和表定义即可导出源数据库的方法。

Option 2: If you're careful, you can edit your dump file to remove those initial setup commands, and have the dump file start with the commands that only push the data to your tables.选项 2:如果您小心的话,您可以编辑转储文件以删除那些初始设置命令,并让转储文件以仅将数据推送到您的表的命令开头。

Option 3: (IMPORTANT to backup the destination server first for this one.) Drop the database, schema, and/or tables on the destination server so that nothing is pre-defined, and see if your dump file can reconstruct everything again the way Django needs it on the destination server with your data.选项 3:(重要的是首先为此服务器备份目标服务器。)删除目标服务器上的数据库、架构和/或表,以便没有任何预定义的内容,然后查看转储文件是否可以再次重建所有内容Django 在目标服务器上需要它和您的数据。

Option 4: It may be a lot of tables, but you can usually export individual table data files with an option to not include table definitions.选项 4:可能有很多表,但您通常可以导出单个表数据文件,并选择不包括表定义。 Then you have to import all the tables as separate imports.然后您必须将所有表作为单独的导入导入。 A mix of option 3 and 4 may work also where if you can't find an option to not include the definition, drop the tables at the destination and import each table independently.选项 3 和 4 的混合也可能适用,如果您找不到不包含定义的选项,请将表放在目标位置并单独导入每个表。

Here is what worked for me using a Mac terminal:以下是使用 Mac 终端对我有用的方法:

  1. Create a backup file from Heroku:从 Heroku 创建备份文件:

pg_dump -h heroku_host -d heroku_database -U heroku_user -p heroku_port -W -Ft > latest.dump

You'll be prompted to input the password from Heroku PostgreSQL. Note that these heroku_xxx are found in the Heroku PostgreSQL credentials.系统将提示您输入来自 Heroku PostgreSQL 的密码。请注意,这些heroku_xxx位于 Heroku PostgreSQL 凭据中。

  1. Restore the backup from Heroku to ElephantSQL:将备份从 Heroku 恢复到 ElephantSQL:

pg_restore -h elephant_host -d elephant_database -U elephant_user -p 5432 -W -Ft latest.dump

You'll be prompted to input the password from Heroku PostgreSQL. Note that these elephant_xxx are found in the ElephantSQL credentials and that they use the term "server" instead of host.系统将提示您输入来自 Heroku PostgreSQL 的密码。请注意,这些elephant_xxx可在 ElephantSQL 凭据中找到,并且它们使用术语“服务器”而不是主机。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM