【发布时间】:2020-06-10 23:47:21
【问题描述】:
我正在尝试将我的 heroku 数据库迁移到我在 linode (linux vm) 上托管的数据库。
我能够让 heroku 识别它自己的数据库以及远程数据库的正确用户名/数据库名称。但是它试图选择我的本地主机 pg db 而不是远程的。
这是 Heroku 对 pg:pull 命令的描述:
$ heroku help pg:pull
See more details with DEBUG=*
pull Heroku database into local or remote database
USAGE
$ heroku pg:pull SOURCE TARGET
OPTIONS
-a, --app=app (required) app to run command against
-r, --remote=remote git remote of app to use
--exclude-table-data=exclude-table-data tables for which data should be excluded (use ';' to split multiple names)
DESCRIPTION
Pull from SOURCE into TARGET.
TARGET must be one of:
* a database name (i.e. on a local PostgreSQL server) => TARGET must not exist and will be created
* a fully qualified URL to a local PostgreSQL server => TARGET must not exist and will be created
* a fully qualified URL to a remote PostgreSQL server => TARGET must exist and be empty
To delete a local database run `dropdb TARGET`
To create an empty remote database, run `createdb` with connection command-line options (run `createdb --help` for details).
Examples:
# pull Heroku DB named postgresql-swimmingly-100 into local DB mylocaldb that must not exist
$ heroku pg:pull postgresql-swimmingly-100 mylocaldb --app sushi
# pull Heroku DB named postgresql-swimmingly-100 into empty remote DB at postgres://myhost/mydb
$ heroku pg:pull postgresql-swimmingly-100 postgres://myhost/mydb --app sushi
我觉得还不错,所以我尝试了:
heroku pg:credentials:url
这会为您提供如下信息:
Connection information for default credential.
Connection info string:
"dbname=[db name here] host=[aws ip here] port=5432 user=[db username] password=[db password here] sslmode=require"
Connection URL:
postgres://[db username]:[db password here]@[db ip here]:5432/[db name here]
我觉得很棒,我可以将上面的连接 url 用于 heroku db,并按照它的语法用于我自己的 linode pg db。
heroku pg:pull postgres://[heroku db username]:[heroku db password here]@[heroku db ip here]:5432/[heroku db name here] postgres://[linode db username here]:[linode db password here]@[linode ip here]/[linode db name here] --app [my-app-name-here]
然后我得到的问题是它甚至不接受它自己的 db uri 是有效的:
Unknown database:
[Stuff I put in for their db url here, like the full string]
Valid options are: DATABASE_URL
好吧,这有点令人不安,因为我知道上面的凭据可以工作...我已使用这些凭据从我的 rails 应用程序连接到我的 heroku 数据库。不管他们只是想要别的东西,所以我看看:
$ heroku pg:info
task: runHook init
plugin: heroku
root: /usr/lib/heroku
See more details with DEBUG=*
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 1/20
PG Version: 11.6
Created: 2019-06-03 16:06 UTC
Data Size: 9.8 MB
Tables: 15
Rows: 450/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-[random name here]
所以我去好吧,也许他们想要那个“附加组件:”名称:
$ heroku pg:pull postgresql-[random name here] postgres://[linode db username here]:[linode db password here]@[linode ip here]/[linode db name here] --app [my-app-name-here]
这让我非常接近,但我现在不知道如何让它查看正确的 IP 地址/主机,这就是我得到的:
heroku-cli: Pulling postgresql-[random name here] ---> postgres://[linode db username here]:[linode db password here]@[linode ip here]:5432/[linode db name here]
psql: FATAL: no pg_hba.conf entry for host [my **LOCAL** ip address], user [linode db username here], database [linode db name here], SSL on
▸ Remote database is not empty. Please create a new database or use heroku pg:reset
我也试过了:
$ heroku pg:pull postgresql-[random name here] postgres://[linode ip here]:5432/[linode db name here] --app [my-app-name-here]
当它无法识别遥控器时,认为它以某种方式退回到我的本地。同样的错误,但用户名是我的本地计算机用户名,仍然是我的 ip 而不是远程的。
这很接近,但为什么它选择了我的本地 IP 地址?它得到了正确的 linode 用户名/数据库名称,但它试图在本地连接它,这显然不是我想要的。
任何建议都将不胜感激....感觉我尽可能地遵循了他们的命令。
在 linode 上,我更改了设置,因此它在 0.0.0.0:5432 上打开,而不仅仅是 localhost。所以它应该能够接受外部连接。
编辑: 我查看了这些资源以寻求帮助,但发现它们严重缺乏任何具体细节,而这些细节是实际做到这一点的关键: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull
https://blog.heroku.com/push_and_pull_databases_to_and_from_heroku
编辑: 我得到了转储文件.....但这意味着heroku的命令不起作用。是的,我可以使用转储文件来做到这一点。但是我很不高兴对我们说这个 api 命令可以工作,但它不能......有人证明我错了。如果可以的话我会表扬你的。
【问题讨论】:
标签: postgresql heroku heroku-postgres