I have a server named as servername.mydomain.com. I can do ssh to this server using a port number X using:

ssh  myusername@servername.mydomain.com -p X

From this server I can run:

psql -h localhost -d myDatabase -U myusername -p DBPORT

Instead of having to login using ssh I want to be able to use psql as:

psql -h servername.mydomain.com:X -d myDatabase -U myusername -p DBPORT

Is this possible? I tried this but I am getting the message: could not translate hostname ...

  • leave out the :x it's not part of the hostname – Jasen Apr 5 '20 at 11:53

leave out the :x

 psql -h servername.mydomain.com -d myDatabase -U myusername -p DBPORT

You may need to edit the listen_addresses directive in postgrersql.conf (and restare poastgresql.

Alternatively you can tunnel the postgres connection.

ssh  myusername@servername.mydomain.com -p X -R DBPORT:

then on another command-line

psql -h -d myDatabase -U myusername -p DBPORT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.