5

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!

1 Answer 1

9

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')
Sign up to request clarification or add additional context in comments.

2 Comments

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 :)
Note that the correct command is now: create_engine('postgresql://username:password@localhost:1111/database')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.