I have two servers. Server 1 has access to an Oracle instance on a server I have permission to hit but not login to via SSH. I would like to use SSH port forwarding to connect from server 2 to server 1 and from there to the Oracle instance. I have set GatewayPorts=yes and AllowTcpForwarding=yes but I still feel like something is wrong.

For the purposes of this question, I would like to focus simply on connecting to a postgres instance on server 1 (port 5432) from server 2 port forward from 16951.

After running:

ssh -L 16951:localhost:5432 server1 -nNT -f -g

from server 2, I can see "localhost.16951" after running netstat to check open ports which leads me to believe that the port is listening successfully.

When I run:

psql -U jbarton -p 16951

I get a message saying that there is no listening port localhost:16951

    psql: could not connect to server: No such file or directory
     Is the server running locally and accepting
     connections on Unix domain socket "/tmp/.s.PGSQL.16951"?

Any comments, answers or suggestions are greatly appreciated.


When I now try this with oracle, connect using: ./sqlplus W_USER/password@//localhost:16951/dbname, I get this error: ERROR: ORA-12537: TNS:connection closed

My oracle ora files look like this:

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 16951))
         (SERVICE_NAME = prod2)

And the sqlnet.ora

'# sqlnet.ora Network Configuration File Generated by Oracle configuration tools.

NAMES.LOG_DIRECTORY = /var/oracle/network/log

1 Answer 1


If you do not specify the hostname psql assumes domain socket connections. As per the man page:

If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

Try adding -h localhost to the psql command line.

As to the Oracle error, I would guess because of the following (oracle is much harder to diagnose):

The ORA-12537 error sometimes relates configuration issues in the sqlnet.ora, protocol.ora and listener.ora files.  Verify that you service names match between your listener and remote client connect strings.

So your connect string including localhost is being rejected by oracle.


If that is a local tnsnames.ora, have you tried sqlplus W_USER@PROD2 instead? (it will prompt for a password if required). You may have to set the environment variable TNS_ADMIN to the location of where tnsnames.ora resides.

  • That worked, so now that the proof of concept is in place, why doesn't this same process work with oracle? I connect using: ./sqlplus W_USER/password@//localhost:16951/dbname I get this error: ERROR: ORA-12537: TNS:connection closed Aug 5, 2015 at 19:14
  • Updated my answer in relation to the Oracle error.
    – Drav Sloan
    Aug 5, 2015 at 21:34
  • Updated my question with my ora files, as far as I can tell they are the same as the ora files on my working system (other than the change to localhost:16951) Aug 6, 2015 at 17:07
  • I did have the $TNS_ADMIN var set and attempted sqlplus W_USER@PROD2 but I got the same no listener error Aug 6, 2015 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .