使用pgadmin连接到远程服务器 [英] Connecting to remote server with pgadmin
问题描述
我正在使用Linode上的本教程: https://library. linode.com/databases/postgresql/pgadmin-macos-x 将本地计算机上的PGAdmin
连接到远程服务器上的数据库.
I'm using this tutorial from Linode: https://library.linode.com/databases/postgresql/pgadmin-macos-x to connect PGAdmin
on my local machine to a databas on a remote server.
它提供了下面复制的脚本,我应该通过执行以下操作来
It provides the script copied below which I'm supposed to run by doing this
chmod +x postgresql-tunnel.pl
./postgresql-tunnel.pl start
但是,当我这样做时,我会在终端中收到以下错误消息:
However when I do it, I get this error message in the terminal:
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的此错误消息
and this error message from 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安装还是在远程服务器上更改的设置.
I'm not sure if this is a setting I have to change on my local postgres installation or on the remote server.
您能提供一些指导吗?
顺便说一句,当我尝试连接时,我的本地服务器正在运行.
By the way, my local server is running when I try to connect.
这些是我用于pgadmin连接的设置,除了它的用户名是'michael'而不是'allison'
These are the settings I'm using for my pgadmin connection with the exception that it's username 'michael' not 'allison' https://dl.dropboxusercontent.com/u/10328969/pgadmin.png
请注意,请按照此SO问题中的说明进行操作使用pgAdmin将PostgreSQL连接到远程数据库,我做到了
Note, following the instructions at this SO question Unable to connect PostgreSQL to remote database using pgAdmin, I did
/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服务器,但是我仍然收到该错误消息.
and the restarted the postgres server but I still get that error message.
您能建议我如何使连接正常工作吗?
Can you suggest how I might get the connection to work?
连接脚本
#!/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;
}
推荐答案
在脚本中指定其他本地端口.指定的端口已被其他端口使用,可能是在端口5433上运行的本地PostgreSQL.
Specify a different local port in the script. The specified port is already in use by something else, possibly a local PostgreSQL running on port 5433.
这实际上只是SSH隧道周围的玩具包装.就个人而言,我倾向于直接在需要时直接启动ssh隧道,或者ssh进入远程计算机并在本地使用psql
.
That's really just a toy wrapper around an SSH tunnel. Personally I tend to just fire up the ssh tunnel directly when I need that, or ssh into the remote machine and use psql
on it locally.
这篇关于使用pgadmin连接到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!