B
B
bbbbudgie2017-09-08 19:37:18
PostgreSQL
bbbbudgie, 2017-09-08 19:37:18

How to connect to PostgreSQL 9.2.18 on a remote CentOS server via SSH?

PostgreSQL 9.2.18 is installed and running on the remote СentOS server. I can connect to the database from my local machine with pgAdmin 3 using SSH. However, when I open an SSH tunnel through Putty (the tunnel is working, the commands in the Putty terminal open after opening the tunnel) and try to open a connection in my PHP application, I get the following error:

Warning: pg_connect(): Unable to connect to PostgreSQL server: expected authentication request from server, but received S

The code I use to connect:
<?php
    $db_connection = pg_connect("host=localhost port={локальный SSH порт} dbname={имя дб} user={пользователь дб} password={пароль} sslmode=disable");
?>

If I set the port on which PostgreSQL listens instead of the local SSH port, I get:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2017-09-08
@Casufi

avz.org.ua/wp/2010/06/29/putty-how-to-make-your-wi...

A
Alexander, 2017-09-09
@ushliy

2017 postgres 9.2? Putty? Maybe just read about pg_hba? SSH tunnel to postgres via putti, brrr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question