37

I'm having troubles to connect an existing heroku database to Google Datastudio. I'm trying to add the connection and I get the following:

Access denied, please check your username and password.

Now, I'm 100% sure that I'm correct on those credentials and the problem comes from somewhere else.

I've tried with different setup, either a free or a paid PSQL instance, nothing works.

I've also setup a dummy account on elephantsql and the connection worked the first time without any issue.

Do you have any idea of the cause of that problem?

Edit:

Just found https://www.en.advertisercommunity.com/t5/Data-Studio/Heroku-Postgres-lt-gt-Google-Data-Studio/m-p/1031729 which is not helpful at the time of writing this post.

2
  • Can you accept my answer please?
    – Lee
    Apr 5, 2017 at 17:41
  • 1
    @nobe4 please accept mfazekas's answer. that one actually works. Lee only says "it doesnt work" when that's just a lie.
    – tolgap
    Oct 4, 2019 at 17:08

4 Answers 4

72

Since the February 6, 2018 update, Google DataStudio allows SSL connections with PostgreSQL, which is necessary to connect to a database created via Heroku.

To enable SSL you need to provide client key+cert and server cert, which can be accomplished by taking the following steps:

  1. Generate a self-signed cert + key with openssl for client key + certificate:
openssl req \
       -newkey rsa:2048 -nodes -keyout client.key \
       -x509 -days 365 -out client.crt
  1. Use the postgres_get_server_cert.py script to get the self-signed server cert from heroku psql:

https://raw.githubusercontent.com/thusoy/postgres-mitm/master/postgres_get_server_cert.py

16
  • 3
    This solution worked for me. Just be sure to run postgres_get_server_cert.py in python 2
    – gtalarico
    Mar 22, 2018 at 22:27
  • 29
    I think it's helpful also to know how to call the python script as there doesn't seem to be any documentation on it. Open terminal and use the command python postgres_get_server_cert.py {aws-database-server}:{port} > aws-cert.crt replacing {aws-database-server}:{port} with your server and port as appropriate. This will output the certificate to the aws-cert.crt file
    – Russell
    Jun 12, 2018 at 20:28
  • Make sure to run the openssl command on one line to generate the client.key and client.crt in one command. It took me a couple of tries of downloading the certificates (unable to reach host error), but this finally got me connected to Heroku Postgres with GDS. Nov 18, 2019 at 18:38
  • 1
    It looks like heroku recently removed some TLS protocols to connect, which breaks the script. Does anyone have a solution?
    – JohnDoe
    Mar 16, 2022 at 16:01
  • 1
    UPDATE July 2023 - I went and perform step 2 only and uploaded the cert generated to the SSL field on datastudio. Finally able to connect
    – a.fahmiin
    Jul 11 at 17:01
8

The problem is that Heroku Postgres requires an SSL connection which doesn't seem possible with Data Studio at the moment. Hopefully Google will add that option soon.

3
  • I just encountered this. I tried to force it into using SSL by setting a JDBC connection string with &ssl=true, but I still get an error: {"reason":28,"errorStatus":{"reason":28,"code":3,"reasonStr":"JDBC_HOST_NOT_REACHABLE","errorCategoryStr":"USER_CONFIGURATION","category":2,"uniqueErrorCode":"...","errorCategoryCode":"2013"},"params":{"errorId":"0d539e57"}}.
    – Jeremy
    Dec 18, 2017 at 21:06
  • Here's the thread: en.advertisercommunity.com/t5/forums/v3_1/forumtopicpage/…
    – Andrei
    Jan 18, 2018 at 18:00
  • Google has added the connect via SSL option now
    – DMTintner
    Aug 4, 2020 at 10:53
0

Make sure to run the openssl command on one line to generate the client.key and client.crt in one command. It took me a couple of tries of downloading the certificates (unable to reach host error), but this finally got me connected to Heroku Postgres with GDS.

0

I thought I would mention that I have used this for quite awhile, but every time my database undergoes maintenance it breaks and I have to manually reconnect the certificates. I developed a better approach - connect the data to Google BigQuery and do your blends there, and then use the BigQuery Community Connector. The charts are more performant this way AND you can now use query parameters on blended data.

Of course, DataStudio won't connect directly to Heroku Postgres for the same reason, so I use a service called Fivetran to grab the raw data and send it to Google BigQuery. There is a cost to this, of course, but for some projects it may be worth it. At some point I will move my database off of Heroku to either AWS or Google itself to allow a direct connection, but that is a larger project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.