How to connect PyCharm to postgresql using Vagrant

If you want to connect PyCharm to postgresql data source, it is pretty easy to do.

Prerequisites:

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.

PostgreSQL connection settings

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.

PostgreSQL SSH settings

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:

PostgreSQL SSH success