我正在使用 Linode 的本教程:https://library.linode.com/databases/postgresql/pgadmin-macos-x https://library.linode.com/databases/postgresql/pgadmin-macos-x连接PGAdmin
我的本地计算机上的数据库到远程服务器上的数据库。
它提供了下面复制的脚本,我应该通过执行此操作来运行该脚本
chmod +x postgresql-tunnel.pl
./postgresql-tunnel.pl start
但是,当我这样做时,我在终端中收到此错误消息:
michael$ ./postgresql-tunnel.pl start
[email protected] /cdn-cgi/l/email-protection's password:
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5433
Could not request local forwarding.
以及来自 pgadmin 的错误消息
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 https://dl.dropboxusercontent.com/u/10328969/pgadmin.png
请注意,按照此 SO 问题的说明进行操作无法使用 pgAdmin 将 PostgreSQL 连接到远程数据库 https://stackoverflow.com/questions/1287067/unable-to-connect-postgresql-to-remote-database-using-pgadmin, I did
/etc/postgresql/9.1/main/postgresql.conf:
listen_addresses = '*'
and
/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 <[email protected] /cdn-cgi/l/email-protection>
# 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;
}