Deepnote: How to set up a PostgreSQL database in the cloud and connect

Markus Odenthal
3 min readFeb 19, 2022
Photo by Luke Chesser on Unsplash

As a Data Scientist, you always need a way to store data. So I was thinking about how I can quickly and cheap a storage option in the cloud for my hobby project. That is the reason why I came to Heroku.

  1. It is straightforward to set up a PostgreSQL Database.
  2. The first 10.000 rows and up to 1 GB Storage Capacity are free. So for the start of a project, enough.

So in the following, I will show you how you can set up a Database in Heroku.

  1. Go to the Heroku Dashboard: https://dashboard.heroku.com/apps
  2. Create a new app

3. Define app name and choose a region.

4. Now, you will send it back to the dashboard of the App. Here go to the left top menu and choose “Data”.

5. Select “Install Heroku Postgres”.

6. Select the App that you created before in Step 2.

7. Click on the Database to get the credentials

8. Next, click on settings and view credentials

9. Save these credentials for later to insert this in Deepnote.

10. Use these credentials to enter into Deepnote to connect the Database. For this go to Deepnote and click “Add integration”.

11. Click on “PostgreSQL”.

12. Insert the credentials from Heruko.

13. Now, you can connect to your Database

That’s it. Now we can use the database in the notebook if you use a SQL Block. If you want to use the Database with Python than we have to add one more thing.

  1. Add the Postgre URI as a Enviroment variable and important change the beginning of the URI from ‘postgres://’ to ‘postgresql+psycopg2://’.

2. Now you can connect to the Database via Python.

Thanks for Reading.

--

--