-
Aside: Ironically this piece is now out of date, as bit.io abruptly shut down their service and gave customers one month to migrate. So it seems in hindsight this was bad advice, but I'm leaving it up here for posterity.
-
-
Now that Heroku is removing their free tier, I wanted a way to limit our monthly bill. One of the most expensive parts of an Heroku app is the database.
-
Conversely, Bit.io has an extremely generous, incrementally scaling plan which allows you to create as many databases as you want. You put a credit card down and then only get paid for what you use, starting at 0.17c per month.
-
We run Metabase on Heroku and have saved quite a few queries. Rather than having to pay arm and a leg, to run it, I wondered if I could move the database to Bit.io.
-
There were two parts to this: Transferring the data to Bit.io database, and then telling your metabase install to use the new url.
-
Transfering the data is only 3 steps, which I've outlined here:
-
Telling your metabase install to use the new bit.io database url
-
One would hope for this to be as simple as swapping out the DATABASE_URL environment variable in Heroku, but it was not. There were a few gotchas which took me a while to figure out.
-
Step One: Detach the previous database (Heroku won't let you add a new DATABASE_URL unless you do this first)
-
heroku addons:detach DATABASE -a <app_name>
-
Step Two: Add your new DATABASE_URL as an heroku environment variable
-
Grab you new postgres url from your bit.io "Connect" tab.
-
The last part of the url will consist of the database name, which will be of the format
username/database
. Metabase uses jdbc behind the scenes, which requires a urlencoded database name, so you need to replace the forward slash with%2f
. -
So if your original url looked like this -
-
postgresql://you:password@db.bit.io/you/database
-
the new one should look like this
-
postgresql://you:password@db.bit.io/you%2fdatabase
-
Add this modified url as an environment variable called
DATABASE_URL
. -
Step Three: Redeploy Metabase from source
-
If you already have Metabase deployed on Heroku, simply doing a new re-deploy doesn't seem to be enough to trigger the new environment variables to get set. Instead you will need to fork the metabase repository, connect it to Heroku, and re-deploy from master. More detailed instructions can be found here.
-
As you're doing this, tail the Logs to make sure everything's going ok. If everyhing runs smoothly, you should now be able to log in to your newly updated, bit.io powered, metabase instance.
-