打开端口,以便Windows 7上的pgAdmin可以在VirtualBox上的Debian上连接到PostgreSQL

时间:2013-08-21 07:11:18

标签: postgresql windows-7 port virtualbox pgadmin

大家好:)我在连接时遇到了一些麻烦。

在Windows 7上关于我在配置了Host-only Adapter的VitualBox上的Debian 6:

>nmap -T4 -A -v 192.168.56.1
[...]
5432/tcp  unknown postgresql

在Debian上,PostgreSQl正在倾听:

>netstat -tulpn

tcp  0  0  0.0.0.0:5432  0.0.0.0:*  LISTEN  2432/postgres
tcp6 0  0  :::5432       :::*       LISTEN  2432/postgres

..并打开端口

>iptables -nL

ACCEPT tcp  --  0.0.0.0/0  0.0.0.0./0  tcp  dpt:5432

..而Postgres正在接受postgresql.conf中的所有连接

listen-addresses = '*'
port = 5432

在Windows中,我收到了来自pdAdmin的错误消息:

Server doesn't listen

The server doesn't accept connections: the connection library reports 

could not connect to server: Connection refused (0x0000274D/10061) 
Is the server running on host "192.168.56.1" and accepting TCP/IP 
connections on port 5432? 

If you encounter this message, please check if the server you're trying 
to contact is actually running PostgreSQL on the given port. 
Test if you have network connectivity from your client to the server 
host using ping or equivalent tools. Is your network / VPN / SSH tunnel /
 firewall configured correctly? 

For security reasons, PostgreSQL does not listen on all available 
IP addresses on the server machine initially. In order to access 
the server over the network, you need to enable listening on the 
address first. 

For PostgreSQL servers starting with version 8.0, this is controlled 
using the "listen_addresses" parameter in the postgresql.conf file. 
Here, you can enter a list of IP addresses the server should listen 
on, or simply use '*' to listen on all available IP addresses. For 
earlier servers (Version 7.3 or 7.4), you'll need to set the 
"tcpip_socket" parameter to 'true'. 

You can use the postgresql.conf editor that is built into pgAdmin III 
to edit the postgresql.conf configuration file. After changing this 
file, you need to restart the server process to make the setting effective. 

If you double-checked your configuration but still get this error 
message, it's still unlikely that you encounter a fatal PostgreSQL 
misbehaviour. You probably have some low level network connectivity 
problems (e.g. firewall configuration). Please check this thoroughly 
before reporting a bug to the PostgreSQL community. 

祝你好运

1 个答案:

答案 0 :(得分:1)

您的pg_hba.conf文件怎么样?
您是否将其配置为接受来自192.168.56.0网络中主机的连接? 尝试添加此行并重新启动Postgres:

# VitualBox Host-Only Adapter
host      all     all     192.168.56.0/24     md5

如果是测试环境,您甚至可以用192.168.56.0/24替换0.0.0.0/0并忘记它。