Forums

Connecting remotely using psql fails silently

I want to get access to my Pyhonanywhere Postgesql database from home using the command line. When I enter this at the bash prompt:

$ psql -h mycoolsite-96.postgres.pythonanywhere-services.com -p 10096 -U webdba -d memdb

Nothing happens. No error message, nothing. It seems to be waiting for more input from the keyboard but I don't know why. How can I get access to my database remotely using psql?

Your postgres server isn't directly accessible from elsewhere on the Internet, so you need to use an SSH tunnel to connect. On your local machine, you can set up the tunnel by running this command (on Linux and OS/X)

ssh -L 3333:mycoolsite-96.postgres.pythonanywhere-services.com:10096 memberable@ssh.pythonanywhere.com

You can then use psql like this:

psql -h localhost -p 3333 -U webdba -d memdb

Oh! For security purposes I'm glad it's inaccessible elsewhere. I wish the psql diagnostics were a little more helpful. Thank you.