How to connect PyCharm to postgresql using Vagrant
27 Jul 2015If you want to connect PyCharm to postgresql data source, it is pretty easy to do.
Prerequisites:
- PyCharm (I think this will also work in other JetBrains products)
- Vagrant box with Postgresql inside it. I assume Vagrant is already configured with PyCharm
- Postgresql jdbc driver installed
Step 1
Click on a green plus button in a “Database” editor tab. Then choose “PostgreSQL” and enter your settings. If you didn’t change PostgreSQL settings, defaults should be ok.
Don’t forget to enter your database name, username and password. Host should be localhost
or 127.0.0.1
, because we are going to connect through SSH tunnel.
Step 2
Go to “SSH/SSL” tab and check “Use SSH tunnel” checkbox. Then set proxy host to 127.0.0.1
, port to 2222
, proxy user to vagrant
and password to vagrant
.
I tried connecting with Vagrant private key (which is usually located in user home folder under
/home/user/vagrant.d/insecure_private_key
), but that didn’t work: I only saw “Auth fail” message
Step 3
Now you are ready to press “Test connection” button on a “Database” tab. You should see a message telling that connection is successfull: