database 如何将 .sql 文件导入 Heroku postgres 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20508898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:09:27  来源:igfitidea点击:

How can I import a .sql file into my Heroku postgres database?

databasepostgresqlherokuimport

提问by Some Guy

I have a backup sql file from another database that I want to import into Heroku's postgres database. How do you do that?

我有一个来自另一个数据库的备份 sql 文件,我想将它导入到 Heroku 的 postgres 数据库中。你是怎样做的?

回答by SergeyB

This is how you do it:

这是你如何做到的:

heroku pg:psql --app YOUR_APP_NAME_HERE < updates.sql

And if you want to restore your production into staging (assuming both are heroku postgres DBs):

如果您想将您的生产恢复到暂存状态(假设两者都是 heroku postgres 数据库):

heroku pgbackups:restore YOUR_STAGING_DATABASE_NAME `heroku pgbackups:url --app YOUR_PRODUCTION_APP_NAME` --app YOUR_STAGING_APP_NAME --confirm YOUR_STAGING_APP_NAME

Make sure to preserve the special single quotes around "heroku pgbackups:url --app YOUR_PRODUCTION_APP_NAME".

确保保留“heroku pgbackups:url --app YOUR_PRODUCTION_APP_NAME”周围的特殊单引号。

-------- HEROKU TOOLBELT UPDATE --------

-------- HEROKU 工具带更新 --------

Heroku has recently updated their toolbelt so the old commands are no longer valid (see this linkfor more info). Below is the new version of the restore command.

Heroku 最近更新了他们的工具带,因此旧命令不再有效(有关更多信息,请参阅此链接)。下面是恢复命令的新版本。

heroku pg:backups restore `heroku pg:backups public-url -a YOUR_PRODUCTION_APP_NAME` YOUR_STAGING_DATABASE_NAME --app YOUR_STAGING_APP_NAME --confirm YOUR_STAGING_APP_NAME

回答by Abel

Making backup file:

制作备份文件:

pg_dump -U USERNAME DATABASE --no-owner --no-acl -f backup.sql 

Restoring from sql file to heroku :

从 sql 文件恢复到 heroku :

heroku pg:psql --app APPNAME < backup.sql 

(Bonus) Deleting all tables from heroku app database (example):

(奖励)从 heroku 应用程序数据库中删除所有表(示例):

heroku pg:reset --app APPNAME HEROKU_POSTGRESQL_ROSE

get DATABASE_URL from posgresql heroku panel (psql line)

从 posgresql heroku 面板(psql 行)获取 DATABASE_URL

回答by Dan Kohn

Load the SQL into a local Postgres instance and make sure it's correct. Then dump the data using the directions here: https://devcenter.heroku.com/articles/heroku-postgres-import-export

将 SQL 加载到本地 Postgres 实例中并确保它是正确的。然后使用此处的说明转储数据:https: //devcenter.heroku.com/articles/heroku-postgres-import-export

Finally, upload the dump to a public web server (like S3) and restore to Heroku like this:

最后,将转储上传到公共 Web 服务器(如 S3)并像这样恢复到 Heroku:

heroku pgbackups:restore DATABASE 'https://s3.amazonaws.com/me/items/3H0q/mydb.dump'

回答by Fauzan Khan

Django local db import on Heroku on windows

在 Windows 上的 Heroku 上导入 Django 本地数据库

create backup

创建备份

pg_dump -U postgres -d hawkishfinance > C:\Users\Fauzan\Projects\hawkishfinance.sql

dump on server

在服务器上转储

heroku pg:psql --app hawkishfinance < hawkishfinance.sql