Question

I'm thinking of deploying a small Rails app on Heroku. In an effort to save money, I'd like my app to use an external database (to which I have free access), rather than a Heroku-hosted database. The trouble is that the free database only accepts local connections. To access it from Heroku, I'd need to do so via an SSH tunnel.

Is it possible for a Heroku app to persist its data in an external DB accessed via SSH? If so, how?

(For bonus points, here's a second question: is this a good idea? On the one hand, this scheme would save me from paying for a Heroku database. On the other hand, it means having to encrypt all my database traffic. I imagine that this would massively slow down my web dynos, and reduce the number of requests they can serve. Would the money I save on the database get used up paying for more dynos? Am I likely to come out ahead by doing this?)

Was it helpful?

Solution

No, and even if it was an option it's a really bad idea as you'd be adding massive latency to every request, since you'd for all intents and purposes have to open a new tunnel for every request.

Your best option is likely to use Heroku's development or starter tiers. The free development tier will work if your database is less than 10,000 rows. Their $15/mo starter tier works for up to 1,000,000 rows.

OTHER TIPS

Yes, you can.

It is possible to set up a tunnel on Heroku to an external database.

You don't want to do it for the reasons the O.P. mentions (to avoid paying for a local database) for the reasons @sgrif mentions (it would be painfully slow and probably not really save anything)

But there are legitimate reasons for wanting to tunnel to an external database, for example if data is residing in a legacy system that you need to analyze.

Rather than simply repeat myself (it's long), here's a link to the recipe that worked for me: SSH tunneling from Heroku

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top