Postgresql Heroku pg:拉入远程linode数据库

Postgresql Heroku pg:拉入远程linode数据库,postgresql,heroku,heroku-postgres,Postgresql,Heroku,Heroku Postgres,我正在尝试将heroku数据库迁移到我在linode(linux虚拟机)上托管的数据库 我能够让heroku识别它自己的数据库以及远程数据库的正确用户名/数据库名。但是,它正在尝试选择我的本地主机pg db,而不是远程主机 这是Heroku对pg:pull命令的描述: $ heroku help pg:pull See more details with DEBUG=* pull Heroku database into local or remote database USAGE $ h

我正在尝试将heroku数据库迁移到我在linode(linux虚拟机)上托管的数据库

我能够让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地址?它得到了正确的linodeusername/db名称,但它试图在本地连接它,这显然不是我想要的

如有任何建议,将不胜感激。。。。我觉得我尽可能地听从了他们的命令

在linode上,我更改了设置,因此它在0.0.0.0:5432上打开,而不仅仅是本地主机。因此,它应该能够接受外部连接

编辑: 我查看了这些资源以寻求帮助,但发现它们缺乏任何具体细节,而这些细节正是真正做到这一点的关键:

编辑: 我得到了转储文件。。。。。但这意味着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在
上。也许这个错误有误导性。它后来说
远程数据库不是空的
,因此它正试图拉入,但由于
目标必须存在且为空

您是否确保远程数据库服务器为空,是否运行了
createdb
,以防万一

createdb -h [host] -p [port] -U [dbuser] [dbname]

您好,是的,远程服务器上的数据库是空的(并且已经由我创建),因为我刚刚从heroku下载了一个最新的.dump文件,然后将其向上推,并用它还原了空数据库(还原最新的.dump还需要一个空数据库)。它已创建,但其中没有表。在本地,我根本没有pg中的数据库。也许它想要创建它,但在本地是空的,然后它就可以工作了,但是。。。这意味着在本地而不是在我的远程服务器上:(