Connecting Google Data Studio to your PostgreSQL database is easier than you would think. I will walk you through the whole process step by step. By the end of the article you will learn how to visualize your PostgreSQL data within a few minutes.

Before you start, it might be useful if you go through these articles first:

STEP 0

If you haven’t done it yet, register for Google Data Studio. You can do it on datastudio.google.com. It’s free; all you need is a gmail email address.

connect Google Data Studio to PostgreSQL -- landing

STEP 1: Add a new Data Source!

When you go to datastudio.google.com, you will see this landing page. Here, you can set up new reports and manage your existing ones. But what we want to do first is add a new Data Source. So click the Data Source button.

connect Google Data Studio to PostgreSQL -- add new data source

It will list all the data sources you already have. If this is your first time with Data Studio, you will see an empty list. Either way, just click the little plus button on the bottom right corner.

connect Google Data Studio to PostgreSQL - data source landing

STEP 2: Select your connector!

On this new window, you see many many connectors. You can connect to your Google Analytics data, your Google Adwords data, your Youtube data, etc. If you are looking for even more connectors, click the ‘EXPLORE CONNECTORS’ button and you will get dozens more.

We want to connect Google Data Studio to PostgreSQL, so click PostgreSQL:

connect Google Data Studio to PostgreSQL - create new data source landing

STEP 3: Provide your data server login credentials!

A “Database Authentication” window pops up. (Sometimes, before that, you also need to¬†authorise your Google Drive account. It’s a one-click thing.) Don’t get intimidated; you just have to type the very same credentials that you use with SQL Workbench or pgadmin4.

connect Google Data Studio to PostgreSQL - postgresql connector

It’s:

  1. Host Name or IP: the IP address of your data server. (The same that you use when you ssh to your data server from your terminal window, or when you establish a connection with SQL Workbench, or when you login to Jupyter Notebook or RStudio.)
    Note: if you have no idea what am I talking about, go through the Install Python, R, SQL and bash article first!
  2. Port: the port for PostgreSQL on your dataserver. By default, it’s: 5432. (If you didn’t change the configuration, this will be yours as well.)
  3. Database: the name of your database. By default, this is: postgres. (If you didn’t change the configuration, this will be yours as well.)
  4. Username: your SQL user’s username.
  5. Password: the password for your SQL user.
  6. Enable SSL connection: you can decide whether you want to use secure connection (tick it) or not (don’t tick it). For now, I’ll go without SSL connection. It’s just fine for practicing.

Okay, for me the filled-in form looks like this:

connect Google Data Studio to PostgreSQL -- authenticate with credentials

Now click Authenticate!

STEP 4: Select a datatable!

Next step: you have to select the data table you want to work with!
Just choose the one you want to import! I have only one table on my server: the zoo data set.

connect Google Data Studio to PostgreSQL -- authenticate TABLES

Note that there is a new feature in Google Data Studio as of the beginning of 2018. You can actually use a query to transform your PostgreSQL data to a preferred format before you connect it to Google Data Studio. You can look at this feature as an extra layer between your PostgreSQL database and Data Studio. It’s very handy if you don’t want to import your whole data table but only an aggregated version of it. (E.g. it can count the number of animals in my zoo dataset.)

connect Google Data Studio to PostgreSQL -- authenticate - CUSTOM QUERY

Either way you go: click ‘CONNECT’ in the top right corner!

STEP 5: Format your datatable!

As a last step of importing, you have to name your new datatable. Pick something simple and meaningful. You can also rename your columns and set the data type and the aggregate function as necessary.

Example #1: my zoo dataset.
connect Google Data Studio to PostgreSQL -- zoo data set

Example #2: my zoo dataset with the animal-counter query
connect Google Data Studio to PostgreSQL -- zoo counted dataset

Note that every data import will create a new Google Data Studio data source.

STEP 6: Create your reports.

And you are done! From now on, the connection between Google Data Studio and your PostgreSQL table will be there when you need it. It’s time to create some charts.

Example #1: a chart for my zoo data set.

connect Google Data Studio to PostgreSQL -- waterneed of animals

water_need of the different animals

Example #2: a bar chart to show the number of animals for my zoo-data-counted data set.

connect Google Data Studio to PostgreSQL -- number of animals

number of the different animals

If anything changes in your PostgreSQL table, it will come automatically to Data Studio as well (so you don’t have to set up a new connection, just simply refresh your charts) which is awesome.

Conclusion

This is how to connect Google Data Studio to PostgreSQL! Wasn’t that hard, was it?
Now, you are ready to visualize your SQL data in a simple and efficient way.

If you have any questions let me know in the comment section below. Plus, don’t forget to subscribe to my Newsletter.

Cheers,
Tomi