Connect to postgresql on remote host

I need to connect to the postgresql database on a remote host. The host
need authentication as well as the database.

So the
host=192.168.0.116
port=8022
hostusername = hostName
password for host= hostPass
Postgres database name = databaseName
database login username = userName
database login password = userPass

I can do the ssh to connect to the host

Net::SSH.start(‘192.168.0.116’, hostName,:port=>8022,
:password=>hostPass)

But I don’t know how to continue and get connect with the database on
the host. The closest way I can think of is:

conn =
PGconn.connect(‘192.168.0.116’,8022,’’,’’,‘databaseName’,‘userName’,‘userPass’)

The error I was getting is:

`initialize’: SSL error: wrong version number (PGError)
expected authentication request from server, but received S

Does anyone have the same problem. I would appreciate any inputs. Thanks
a lot!!

Hi,

Am 11.05.2010 21:31, schrieb Jing Tian:

I need to connect to the postgresql database on a remote host.
The host need authentication as well as the database.
[…]

I can do the ssh to connect to the host

Net::SSH.start(‘192.168.0.116’, hostName,:port=>8022,
:password=>hostPass)

But I don’t know how to continue and get connect with the database on
the host. The closest way I can think of is:

conn =
PGconn.connect(‘192.168.0.116’,8022,’’,’’,‘databaseName’,
‘userName’,‘userPass’)

The error I was getting is:

`initialize’: SSL error: wrong version number (PGError)
expected authentication request from server, but received S

Does anyone have the same problem. I would appreciate any inputs.
Thanks a lot!!

It seems sshd is listening on port 8022. On which port is postgresql
listening?

If postgresql is listening on some local port only bound to the host
itself (127.0.0.1), then you can tunnel your PGconn through SSH.

Open a SSH tunnel on your local machine: e.g.
ssh -p 8022 -N -v -L
:urgewalten.de: user@host

then you can open a postgresql connection to
localhost: and it will be forwarded to your
destination host.

Greetings,

Waldemar

Waldemar Dick wrote:

It seems sshd is listening on port 8022. On which port is postgresql
listening?

If postgresql is listening on some local port only bound to the host
itself (127.0.0.1), then you can tunnel your PGconn through SSH.

Open a SSH tunnel on your local machine: e.g.
ssh -p 8022 -N -v -L
:urgewalten.de: user@host

then you can open a postgresql connection to
localhost: and it will be forwarded to your
destination host.

Greetings,

Waldemar

Thanks so much Waldemar for the comments. I am complete new to ruby.
Right now we are trying to come up some ruby code getting data from the
database on a remote host.
I think postgresql is on port 5432 of the host. I don’t understand open
a ssh tunnel when you said ssh -p 8022 -N -v -L
:urgewalten.de: user@host

what is urgewalten.de? Can I do it through ruby code? Sorry about
bugging you again :slight_smile: