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:
How to Become a Data Scientist
(free 50-minute video course by Tomi Mester)
Just subscribe to the Data36 Newsletter here (it’s free)!
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.
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 CREATE >> DATA SOURCE.
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, just scroll down and you will get dozens more.
We want to connect Google Data Studio to PostgreSQL, so scroll down and click PostgreSQL:
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.
- 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!
- 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.)
- Database: the name of your database. By default, this is: postgres. (If you didn’t change the configuration, this will be yours as well.)
- Username: your SQL user’s username.
- Password: the password for your SQL user.
- 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:
Now click Authenticate!
The Junior Data Scientist's First Month
A 100% practical online course. A 6-week simulation of being a junior data scientist at a true-to-life startup.
“Solving real problems, getting real experience – just like in a real data science job.”
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.
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.)
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.
Example #2: my zoo dataset with the animal-counter query
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.
Example #2: a bar chart to show the number of animals for my zoo-data-counted data set.
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.
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 want to learn more about how to become a data scientist, take my 50-minute video course: How to Become a Data Scientist. (It’s free!)
- Also check out my 6-week online course: The Junior Data Scientist’s First Month video course.