postgresql - Heroku pg:拉到远程 linode 数据库
问题描述
我正在尝试将我的 heroku 数据库迁移到我在 linode (linux vm) 上托管的数据库。
我能够让 heroku 识别它自己的数据库以及远程数据库的正确用户名/数据库名称。但是它试图选择我的 localhost 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-拉
https://blog.heroku.com/push_and_pull_databases_to_and_from_heroku
编辑: 我得到了转储文件.....但这意味着heroku的命令不起作用。是的,我可以使用转储文件来做到这一点。但是我很不高兴对我们说这个 api 命令可以工作,但它不能......有人证明我错了。如果可以,我会赞美你。
解决方案
* 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 create an empty remote database, run `createdb` with connection command-line options (run `createdb --help` for details).
# 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-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
奇怪的是它列出了您的本地 IP 地址。但是,它将其识别为远程数据库而不是本地数据库。
缺少的一个常见问题pg_hba.conf
是 SSL 未启用,但它说那里SSL on
。也许这个错误具有误导性。后来它说Remote database is not empty
,所以它正试图拉入,但由于TARGET must exist and be empty
您是否确保远程数据库服务器为空并运行createdb
以防万一?
createdb -h [host] -p [port] -U [dbuser] [dbname]
推荐阅读
- javascript - 这种函数结构会减慢应用程序的速度吗?
- java - 重置 OutputStream 以便更新的变量发送
- flutter - 如何在推送到数据库之前跨多个小部件在本地存储数据?
- javascript - 为什么我的 Phaser3 精灵渲染在错误的位置?
- polygon - 有没有办法用剪辑路径(对于元素)制作非常详细的撕裂边缘效果?
- android - Dependency injection using hilt on singleton private constructor class
- php - how to add an html button do each row in a table filled with php data?
- discord - How to make a "set mute role" command in Discord.py?
- c# - 为什么在转换浮点数和字节时,BitConverter 似乎返回不正确的结果?
- java - Using JSOUP to Parse Nested Divs