使用pgadmin连接到远程服务器

时间:2013-07-30 03:03:39

标签: postgresql pgadmin

我正在使用Linode的这个教程:https://library.linode.com/databases/postgresql/pgadmin-macos-x将本地计算机上的PGAdmin连接到远程服务器上的数据库。

它提供了下面复制的脚本,我应该通过这样做来运行

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问题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;
}

1 个答案:

答案 0 :(得分:2)

在脚本中指定其他本地端口。指定的端口已被其他东西使用,可能是在端口5433上运行的本地PostgreSQL。

这真的只是一个围绕SSH隧道的玩具包装。我个人倾向于在需要时直接启动ssh隧道,或者ssh到远程机器并在本地使用psql