3

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?)

dB'
  • 6,904
  • 12
  • 54
  • 92

2 Answers2

4

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

Community
  • 1
  • 1
fearless_fool
  • 29,889
  • 20
  • 114
  • 193
1

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.

hgmnz
  • 12,670
  • 4
  • 34
  • 41
sgrif
  • 3,378
  • 21
  • 30
  • The answer is fundamentally correct, but the latency is the result of network performance, not the tunnel itself. If created properly, when an SSH tunnel is established, the specified port can be reused; reauthentication does not occur on every query, for instance. – Jacob Budin Jan 02 '14 at 16:28
  • @JacobBudin Can we even open an SSH tunnel on Heroku? Given it requires opening a port, I'm not sure it's allowed. – Adrien Mar 12 '14 at 16:06
  • 1
    The answer is fundamentally wrong: you CAN tunnel out of Heroku. I wouldn't do it for the reasons the OP wants, but there are times when you need to, e.g. access to an SSH protected database. See http://stackoverflow.com/questions/21575582/ssh-tunneling-from-heroku/27361295#27361295 for the whole recipe. – fearless_fool Feb 15 '15 at 06:46