我正在使用 Linode 的本教程:httpsPGAdmin
://library.linode.com/databases/postgresql/pgadmin-macos-x在我的本地计算机上连接到远程服务器上的数据库。
它提供了下面复制的脚本,我应该通过这样做来运行
chmod +x postgresql-tunnel.pl
./postgresql-tunnel.pl start
但是,当我这样做时,我在终端中收到此错误消息:
michael$ ./postgresql-tunnel.pl start
michael@192.XXX.XXX.XXX's password:
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5433
Could not request local forwarding.
以及来自 pg admin 的这条错误消息
The server doesn't accept connections: the connection library reports
could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5433?
我不确定这是否是我必须在本地 postgres 安装或远程服务器上更改的设置。
你能提供一些指导吗?
顺便说一句,当我尝试连接时,我的本地服务器正在运行。
这些是我用于 pgadmin 连接的设置,但它的用户名是“michael”而不是“allison” https://dl.dropboxusercontent.com/u/10328969/pgadmin.png
注意,按照这个 SO question Unable to connect PostgreSQL to remote database using pgAdmin的说明,我做到了
/etc/postgresql/9.1/main/postgresql.conf:
listen_addresses = '*'
和
/etc/postgresql/9.1/main/pg_hba.conf:
host all all 0.0.0.0/0 md5
并重新启动了 postgres 服务器,但我仍然收到该错误消息。
你能建议我如何让连接正常工作吗?
连接脚本
#!/usr/bin/perl
# PostgreSQL Tunnel Tool for Mac OS X and Linux
# Copyright (c) 2010 Linode, LLC
# Author: Philip C. Paradis <pparadis@linode.com>
# Usage: postgresql-tunnel.pl [start|stop]
# Access a PostgreSQL database server via an SSH tunnel.
$local_ip = "127.0.0.1";
$local_port = "5433";
$remote_ip = "127.0.0.1";
$remote_port = "5432";
$remote_user = "michael";
$remote_host = "192.XXX.XXX.XXX";
$a = shift;
$a =~ s/^\s+//;
$a =~ s/\s+$//;
$pid=`ps ax|grep ssh|grep $local_port|grep $remote_port`;
$pid =~ s/^\s+//;
@pids = split(/\n/,$pid);
foreach $pid (@pids)
{
if ($pid =~ /ps ax/) { next; }
split(/ /,$pid);
}
if (lc($a) eq "start")
{
if ($_[0]) { print "Tunnel already running.\n"; exit 1; }
else
{
system "ssh -f -L $local_ip:$local_port:$remote_ip:$remote_port $remote_user\@$remote_host -N";
exit 0;
}
}
elsif (lc($a) eq "stop")
{
if ($_[0]) { kill 9,$_[0]; exit 0; }
else { exit 1; }
}
else
{
print "Usage: postgresql-tunnel.pl [start|stop]\n";
exit 1;
}