Connect to PostgreSql database in Linux VirtualBox from Win7

依然范特西╮ 提交于 2019-12-21 11:09:07

问题


As said in headline, from Win7 host I'm trying to access Postgres 9.3 established in Linux Centos 5.8 which is in VirtualBox on the same machine. I'm trying to access it from PGAdmin and everything is OK when I start the Postgre from Win7 services, so PGAdmin is well configured.

What have I tried? I've read many articles about this subject, and even some questions on this forum but nothing worked. I have:

  1. switched to NAT and forwarded port 5432 in VirtualBox GUI
  2. set listenadresses = '*' in postgresql.conf file
  3. put host all all 10.0.2.1/24 md5 line in the pg_hba.conf file
  4. put 5432 port inbound and outbound rule in win7 firewall settings
  5. disabled linux firewall with #service iptables stop

Just to mention. When service is started in virtual linux, I can access it from linux, so service is properly started. Problem is that windows doesn't see that service. And when service is started from linux, I can start the same service in Win and vice-versa although the port 5432 should be occupied.

The most suspicious part to me is point 3) because I'm not sure whether i have put good address in rule. That address vary from article to article, and I would appreciate if someone could explain me how to be sure which address (or range) to put there, according to my network. Or some other advice if possible. Thanks.


回答1:


Solved.

Replacing:

"host all all 10.0.2.1/24 md5" with "host all all 0.0.0.0/0 trust" solved it.




回答2:


In my case adding the below line to pg_hba.conf was enough:

host    all    all    10.0.0.0/16    md5

and then restart:

sudo /etc/init.d/postgresql restart


来源:https://stackoverflow.com/questions/18121666/connect-to-postgresql-database-in-linux-virtualbox-from-win7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!