Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So, I am using Windows to connect to remote Postgres database with a tool like Navicat. I am trying to achieve the same thing using Python (2.7) and SQLAlchemy (0.9) but with no success.

So, my Navicat setup looks like this:

enter image description here

enter image description here

I tried to set up tunnels in PuTTY, connect to server, leave connection opened and experimenting with IPs and ports but with no success at all. I'm not sure if all that's enough since I have this public key and passphrase, so I wonder is it possible to connect to this database from Windows machine using Python and SQLAlchemy (and this beautiful PuTTY app also, of course) in any way?
Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can pass the server and port to your create_engine() statement, ala:

create_engine('postgres://username:password@server:port/database')

http://docs.sqlalchemy.org/en/rel_0_9/dialects/postgresql.html

So assuming you've FIRST established an SSH tunnel to the remote host, and port forwarded local port 1111 to the remote server's port 5432 (which is the default postgres port), your connect string would be something like:

create_engine('postgres://username:password@localhost:1111/database')
share|improve this answer
    
Thanks! I was always trying to connect to this first IP (from 'general' tab) instead of 127.0.0.1... Works like a charm now :) –  errata Aug 7 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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