Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Currently I develop on a remote dev server. I SSH into the dev server (using SSH keys) as

ssh -p 22222 user@devbox.com

Then from the dev server, I connect to the database over the local network

psql -U postgres -h psqldb -d my_database

where psqldb points to 10.0.0.202 on the dev server's /etc/hosts file.

I want to start developing locally on my own computer. How do I connect to the psqldb Postgres server from my local machine by using the remote dev server as an SSH tunnel (or is there a better way to do it)?

EDIT

I failed to mention that I already have Postgres installed on my local server and listening on the default port 5432.

share|improve this question

closed as off topic by EEAA, SvW, Dave M, Ward, Scott Pack Apr 14 '13 at 2:28

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
psql is a client program. It doesn't listen, it connects... –  voretaq7 Apr 13 '13 at 22:06
add comment

1 Answer

ssh -L localhost:5432:psqldb:5432 -p 22222 user@devbox.com

And on another terminal:

psql -h localhost -d my_database -U postgres

Simple, safe and encrypted. I don't know a better way.

share|improve this answer
    
Actually I already use port 5432 for my local Postgres database on my local machine. If I change the first line to ssh -L localhost:5433:psqldb:5432 -p 22222 user@devbox.com, then doing psql -h localhost -d my_database -U postgres would just try to connect to my local database. –  hobbes3 Apr 13 '13 at 19:55
1  
The psql command accepts -p to change the port. psql -p 5433 -h .... –  toppledwagon Apr 13 '13 at 20:02
    
I'm getting an error on the first terminal: channel 3: open failed: administratively prohibited: open failed. –  hobbes3 Apr 13 '13 at 21:10
add comment

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