Heroku pg:pull and Gitpod Postgres problem

Finally I managed to install and run Ruby 2.3.6 with RVM. But now I have another problem running heroku pg:pull command, to pull Heroku Postgres database into Postgres running on Gitpod.

Here’s my Dockerfile on Github: https://github.com/kevinhq/gitpod-dockerfile-collections/blob/master/.ruby-2.3.6-with-heroku.Dockerfile

The problem: when I run heroku pg:pull DATABASE_URL local_db it returned the role doesn’t exist.

The same heroku pg:pull command works normally on my MacOS terminal.

I found out the Gitpod always “force” the heroku pg:pull command to run on its localhost Postgres using this ENV variable:



When I unset that ENV variable, I got another error: can’t connect to Postgres…blah blah…

A bit about how heroku pg:pull works:

  • It will create a database on local Postgres first.
  • Then, it will run pg_dump on remote Postgres on Heroku.
  • Then, it will run pg_restore on local Postgres, to import the dumped data from remote Postgres on Heroku.

So, when I unset PGHOSTADDR: The first step to create database failed because it can’t connect to local Postgres.

When I set PGHOSTADDR to, the second step failed to connect remote Postgres on Heroku — because it’s likely the Gitpod will force the script to always connect to local Postgres when that PGHOSTADDR is set to

Any workaround for this problem?

P.S. I tried to dump and import manually but this is not working too because local Postgres installed for ubuntu 16.04 is 9.5. Is it possible to upgrade it to 9.6 so it will match the Heroku Postgres version?

Hi @kevinhq!

Looking at your Dockerfile, it seems that you’ve already found Gitpod’s default PostgreSQL Dockerfile:

Many lines from the two setups look similar, except that it seems you haven’t used this one:

ENV DATABASE_URL="postgresql://gitpod@localhost"

However, this is just a general comment in passing. I’ll now take a look and try your setup to see if I can somehow get it to work.

On another side note, it seems that you can also bypass heroku pg:pull by:

  1. exporting a pg_dump from Heroku with heroku pg:backups:capture and heroku pg:backups:download

  2. then restore it locally with pg_restore

But I’m also not sure if this will get around the connection failures.

1 Like

Aha, this Keroku Dev Center article seems to be relevant:

E.g. they are defining env variables on-the-fly, based on what heroku config:get returns. Maybe you could use a similar trick to get heroku pg:pull to work in Gitpod? E.g. something like:

DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app) heroku pg:pull
1 Like

Hi @jan,

Thanks for the hint. Finally I was able to get it work with pg:backups command. Here’s the details: Sync up Heroku Postgres to Local Postgres on Gitpod IDE

1 Like

Hey @kevinhq, really cool that you were able to solve this so quickly. :slight_smile:

Well done, and thanks a lot for taking the time to write up the solution! :pray:

1 Like