Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Heroku-PostgreSQL-如何在Windows上远程连接_Postgresql_Heroku_Remote Access_Windows Firewall - Fatal编程技术网

Heroku-PostgreSQL-如何在Windows上远程连接

Heroku-PostgreSQL-如何在Windows上远程连接,postgresql,heroku,remote-access,windows-firewall,Postgresql,Heroku,Remote Access,Windows Firewall,在我得到negs之前,我知道有很多类似的帖子,但我读过并用它们来达到这一点,但我认为它们没有回答我的问题 概述 我正在尝试将我的tester heroku站点[编辑:删除]连接到我的PostgreSQL数据库。我以前试过MS Server,但我在Windows上,Heroku不喜欢pyodbc 短版 我很确定我的PostgreSQL设置正确,但我正在尝试确定我是否有正确的PostgreSQL URL主机名,以及是否需要在允许通过Windows防火墙访问方面做更多的事情 长版本 PostgreSQ

在我得到negs之前,我知道有很多类似的帖子,但我读过并用它们来达到这一点,但我认为它们没有回答我的问题

概述 我正在尝试将我的tester heroku站点[编辑:删除]连接到我的PostgreSQL数据库。我以前试过MS Server,但我在Windows上,Heroku不喜欢pyodbc

短版 我很确定我的PostgreSQL设置正确,但我正在尝试确定我是否有正确的PostgreSQL URL主机名,以及是否需要在允许通过Windows防火墙访问方面做更多的事情

长版本 PostgreSQL


在接受的答案之后,my
postgresql.conf
具有
listen\u地址='*'
和端口5432。我加了一条线

托管所有0.0.0.0/0 md5

pg_hba.conf
上获取以下信息

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all         all         0.0.0.0/0       md5
现在我可以在命令行上执行此操作

C:\etc> psql -U postgres -h 192.XXX.XX.XXX -d ProductionData
其中
192.XXX.XX.XXX
是我的IPv4地址(从开始>更改以太网设置>MyCompany.local中找到),一切正常。我知道,因为如果我撤销
pg_hba.conf
上的行,我会得到

(venv) C:\etc> psql -U postgres -h 192.XXX.XX.XXX -d ProductionData
psql: FATAL:  no pg_hba.conf entry for host "192.XXX.XX.XXX", user "postgres", database "ProductionData", SSL off

赫罗库


我知道postgres需要该表单的URL

postgresql://username:password@hostname/database

除了IP网络地址之外,我不太了解主机名。我已经尝试了
localhost
和上面的相同IPv4地址
192.XXX.XX.XXX
192.XXX.XX.XXX:5432

下面的日志部分有netstat、heroku config设置,在git bash中每次尝试都会重新启动postgresql,但我得到以下两个
192.XXX.XX.XXX
作为超时

Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

Is the server running on host "192.XXX.XX.XXX" and accepting
TCP/IP connections on port 5432?

Windows防火墙


我已创建入站规则以允许访问

协议类型-TCP

本地端口-5432

远程端口-所有端口

程序-此程序-%ProgramFiles%\PostgreSQL\11\bin\postgres.exe

Heroku原木
尝试#1-本地主机,结果错误



尝试#2-192.XXX.XX.XXX,结果超时



尝试#3-192.XXX.XX.XXX:5432,结果超时



网络是一个大话题,但总的来说

  • 大型网络(如互联网)由小型网络(如本地网络)组成
  • 较小网络上的设备通常无法从这些网络的外部访问
  • 您部分显示的IP地址以
    192
    开始,我打赌下一个八位组是
    168
    ,这意味着它是一个,因此无法从Internet访问(例如,有许多机器的地址
    192.168.1.10
    ,这可以存在于任何专用网络上)
  • 如果您需要公开本地网络上的某些内容,例如IP地址为
    192.168.1.10
    ,则必须做一些额外的工作
以下是一些选项:

  • 在云中托管数据库,例如使用
  • 在内部托管您的web服务,以便它可以使用其内部
    192.168.x.y
    地址连接到您的数据库
  • 与前面的选项一样在内部托管,并将本地web应用程序公开到Internet,以便用户可以从网络外部访问它
  • 租用一个VPS,这样您就可以在网络之外托管,但保留对数据存储方式的控制措施(并承担由此带来的管理开销和责任)
我不建议将web应用程序放在您的网络之外,将数据库放在您的网络之内,并将数据库公开给Internet。这样做没有什么价值,特别是因为您无法轻松锁定对应用程序的访问。最佳情况下,您将拥有一个只能通过SSL访问的公共可用数据库(这正是Heroku和其他提供商可以提供的),您必须自己管理

传出连接相对容易,例如,如果您想将本地网络上运行的web服务连接到云中的数据库,但我认为这对您没有帮助


这是件好事™ 因为它提供了一层保护,可以防止对您的个人设备的直接攻击。如果你每次等几天才在Windows上安装更新,你的机器就被黑客攻击,这不是很可怕吗


²一个例子是在网络的公共IP地址上设置端口转发,例如
123.123.123.123
,这样对
123.123.123:1234
的请求被路由到内部网络上的特定IP地址和端口,例如,
192.168.1.10:5432

您试图让应用程序在Heroku上运行,并连接到本地运行的Postgres数据库?我可以问一下为什么吗?Heroku提供了,如果您出于某种原因不喜欢,还有。无论如何,您将无法使用
192.x.y.z
IP地址将任何东西从网络外部连接到本地计算机。这是本地网络。如果你真的有理由这么做,你将需要一个静态IP地址或动态DNS域和端口转发或类似的。我正在努力降低成本,而且我不喜欢在云端有公司信息。也许我太天真了,但我认为将数据发送到数据库会很简单,也就是说,用其他东西替换localhost badaboombadabing hey presto它可以工作。什么是静态IP地址,动态DNS域,端口转发或类似的…我对这些一无所知,就像我在OP中所说的。你能指出关于这些的任何好的来源或书籍吗?网络是一个大话题。基本上,您在问题中部分隐藏的IP地址在本地网络之外是不可见的。从您的本地网络到云端,建立传出连接相对容易,但从另一个方向进行连接要复杂得多。在本地托管应用程序和在云中托管数据库将更容易
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

Is the server running on host "192.XXX.XX.XXX" and accepting
TCP/IP connections on port 5432?
$ pg_ctl -D "C:\Program Files\PostgreSQL\11\data" restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2019-02-19 10:09:04.423 GMT [11952] LOG:  listening on IPv6 address "::", port 5432
2019-02-19 10:09:04.423 GMT [11952] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-02-19 10:09:04.460 GMT [11952] LOG:  redirecting log output to logging collector process
2019-02-19 10:09:04.460 GMT [11952] HINT:  Future log output will appear in directory "log".
 done
server started

$ netstat -ant | findstr 5432
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
  TCP    [::]:5432              [::]:0                 LISTENING       InHost

$ heroku restart -a pgtester
Restarting dynos on ? pgtester... done

$ heroku logs -t -a pgtester
...lots of stack errors...
2019-02-19T09:52:25.731597+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 437, in connect
2019-02-19T09:52:25.731599+00:00 app[web.1]: return self.dbapi.connect(*cargs, **cparams)
2019-02-19T09:52:25.731600+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
2019-02-19T09:52:25.731602+00:00 app[web.1]: conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2019-02-19T09:52:25.731604+00:00 app[web.1]: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
2019-02-19T09:52:25.731606+00:00 app[web.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2019-02-19T09:52:25.731607+00:00 app[web.1]: TCP/IP connections on port 5432?
2019-02-19T09:52:25.731646+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/e3q8)
$ heroku config:set DEV_DATABASE_URL=postgresql://postgres:mysecretpassword@192.XXX.XX.XXX/ProductionData
Setting DEV_DATABASE_URL and restarting ? pgtester... done, v47
DEV_DATABASE_URL: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX/ProductionData

$ heroku restart -a pgtester
Restarting dynos on ? pgtester... done

$ netstat -ant | findstr 5432
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
  TCP    [::]:5432              [::]:0                 LISTENING       InHost

$ heroku logs -t -a pgtester
...lots of stack errors...
2019-02-19T10:00:57.273592+00:00 app[api]: Set DEV_DATABASE_URL config vars by user email@example.com
2019-02-19T10:00:57.273592+00:00 app[api]: Release v47 created by user email@example.com
2019-02-19T10:01:05.401378+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=44666 flasky:app`
2019-02-19T10:01:05.672789+00:00 heroku[web.1]: Restarting
2019-02-19T10:01:08.193167+00:00 app[web.1]: [heroku-exec] Starting
2019-02-19T10:01:10.388293+00:00 app[web.1]: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX/ProductionData
2019-02-19T10:01:10.897113+00:00 app[web.1]: Serving on http://0.0.0.0:44666
2019-02-19T10:01:12.089984+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-02-19T10:01:12.196052+00:00 heroku[web.1]: Process exited with status 143
2019-02-19T10:01:12.358184+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=18540 flasky:app`
2019-02-19T10:01:16.133191+00:00 app[web.1]: [heroku-exec] Starting
2019-02-19T10:01:18.520615+00:00 app[web.1]: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX/ProductionData
2019-02-19T10:01:19.161158+00:00 app[web.1]: Serving on http://0.0.0.0:18540
2019-02-19T10:01:19.687131+00:00 heroku[web.1]: State changed from starting to up
2019-02-19T10:01:33.125392+00:00 heroku[router]: at=info method=GET path="/" host=pgtester.herokuapp.com request_id=7e65dc99-b99f-4b81-8bbe-a4b98adebd91 fwd="185.16.227.58" dyno=web.1 connect=1ms service=231ms status=200 bytes=2077 protocol=https
2019-02-19T10:02:11.389923+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/" host=pgtester.herokuapp.com request_id=6837dbb0-b2e4-44ee-a67c-2f79a1c7c1b6 fwd="185.16.227.58" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
$ pg_ctl -D "C:\Program Files\PostgreSQL\11\data" restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2019-02-19 10:09:04.423 GMT [11952] LOG:  listening on IPv6 address "::", port 5432
2019-02-19 10:09:04.423 GMT [11952] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-02-19 10:09:04.460 GMT [11952] LOG:  redirecting log output to logging collector process
2019-02-19 10:09:04.460 GMT [11952] HINT:  Future log output will appear in directory "log".
 done
server started

$ netstat -ant | findstr 5432
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
  TCP    [::]:5432              [::]:0                 LISTENING       InHost

$ heroku config:set DEV_DATABASE_URL=postgresql://postgres:mysecretpassword@192.XXX.XX.XXX:5432/ProductionData
Setting DEV_DATABASE_URL and restarting ? pgtester... done, v48
DEV_DATABASE_URL: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX:5432/ProductionData

$ netstat -ant | findstr 5432
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
  TCP    [::]:5432              [::]:0                 LISTENING       InHost

$ heroku restart -a pgtester
Restarting dynos on ? pgtester... done

$ heroku logs -t -a pgtester
...lots of stack errors...
2019-02-19T10:11:10.352241+00:00 app[api]: Release v48 created by user email@example.com
2019-02-19T10:11:10.352241+00:00 app[api]: Set DEV_DATABASE_URL config vars by user email@example.com
2019-02-19T10:11:17.316331+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=56616 flasky:app`
2019-02-19T10:11:20.998316+00:00 app[web.1]: [heroku-exec] Starting
2019-02-19T10:11:21.724624+00:00 heroku[web.1]: Restarting
2019-02-19T10:11:25.043993+00:00 app[web.1]: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX:5432/ProductionData
2019-02-19T10:11:25.797589+00:00 app[web.1]: Serving on http://0.0.0.0:56616
2019-02-19T10:11:26.872124+00:00 heroku[web.1]: Starting process with command `waitress-serve --port=51247 flasky:app`
2019-02-19T10:11:27.101119+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-02-19T10:11:27.211928+00:00 heroku[web.1]: Process exited with status 143
2019-02-19T10:11:29.033774+00:00 app[web.1]: [heroku-exec] Starting
2019-02-19T10:11:30.261042+00:00 app[web.1]: postgresql://postgres:mysecretpassword@192.XXX.XX.XXX:5432/ProductionData
2019-02-19T10:11:30.570976+00:00 app[web.1]: Serving on http://0.0.0.0:51247
2019-02-19T10:11:31.054334+00:00 heroku[web.1]: State changed from starting to up
2019-02-19T10:11:34.448659+00:00 heroku[router]: at=info method=GET path="/" host=pgtester.herokuapp.com request_id=7498e3a1-5a09-419b-8038-fc4bf3ddd642 fwd="185.16.227.58" dyno=web.1 connect=1ms service=170ms status=200 bytes=2077 protocol=https
...lots of stack errors...
2019-02-19T10:16:14.079101+00:00 app[web.1]: sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection timed out
2019-02-19T10:16:14.079102+00:00 app[web.1]: Is the server running on host "192.168.10.162" and accepting
2019-02-19T10:16:14.079104+00:00 app[web.1]: TCP/IP connections on port 5432?
2019-02-19T10:16:14.079144+00:00 app[web.1]: (Background on this error at: http://sqlalche.me/e/e3q8)