We were trying out the new hosting tool, Render, for Receipt-AI.com, and we ended up regretting it. Even though we were paying for their starter plan, we experienced numerous disconnection issues. After spending two days dealing with these problems, I decided to switch back to Heroku for my Rails app. Let me share with you the steps I took to make the transition.
Step 1. Download your Postgres Database from Render to your local machine
The process of downloading and uploading a Postgres database is called 'pg_dump' and 'pg_restore'. Since we need to migrate from Render to Heroku, the first step is to connect to Render and download the database.
A. Add your local machine's ip address on Render.
Make sure your VPN is turned off and add the correct IP address. This will enable you to connect to your database on Render from your local machine.
B. Add -Fc
for correct compression format.
Run pg_dump -Fc -d postgres://{YOUR_POSTGRESS_URL}
on your local machine to download the database.
-Fc
is the format for Heroku. If a backup is created with the incorrect format, pg_restore
will not be able to restore the dump file. You may see an error like this: pg_restore: [archiver] did not find magic string in file header.
To run pg_dump
from your local machine, install 'pg_dump' using homebrew. Remember the version of pg_dump
has to be the same as Render's. Otherwise you will see this error pg_dump: error: aborting because of server version mismatch.
Some additional details and instructions are available here. https://devcenter.heroku.com/articles/heroku-postgres-import-export#create-dump-file
C. Upload your database to a cloud bucket.
Heroku doesn't allow database uploads from a local machine, so you need to store the database in a publicly accessible bucket in the cloud. Both Google Cloud and AWS are suitable options. Remember to delete it after restoring the database.
Step 2. Upload your Postgre Database to Heroku from a cloud bucket.
Assuming you have already created an account on Heroku and completed all the necessary preparations to run your app, you can now proceed by running this command to restore your database.heroku pg:backups:restore '<SIGNED URL>' DATABASE_URL --app example-app
Step 3. SSL certificate
If your app is already running on Basic or Professional dynos, enable Automated Certificate Management
with the following command:
heroku certs:auto:enable
Step 4. Redis
A1: If you are using heroku data for redis
It's a way easier setup. Starting plan costs $3/month.
Source: https://devcenter.heroku.com/articles/heroku-redis
or
A2: If you want to use Redis Enterprise Cloud
to save $3/month:
Set the REDIS_PROVIDER
env var to the name of the env var containing the Redis server URL. (Example with RedisCloud: set REDIS_PROVIDER=REDISCLOUD_URL and Sidekiq will use the value of the REDISCLOUD_URL env var when connecting to Redis.)
Run this command: heroku config:set REDIS_PROVIDER=REDISCLOUD_URL
Source: https://github.com/sidekiq/sidekiq/wiki/Using-Redis
You may see this error if you are running Sidekiq 7+
redis-client requires Redis 6+ with HELLO command available
You have to downgrade Sidekiq to 6.5.8 version for it to work.
B: Add these lines to your procfile
worker: bundle exec sidekiq -C config/sidekiq.yml
release: bin/rails db:migrate
You are almost there:
Copy all your environment variables from Render to Heroku, ensure everything is up and running, and confirm that your Sidekiq jobs are executing. Once you have verified these aspects, you can safely suspend the usage of Render. You may also delete all the YAML files that were generated by Render from your repository.
🎉 Congratulations! You have successfully migrated from Render to Heroku. Woo wee! I hope this guide proves helpful to you, and feel free to share it with anyone who may encounter similar challenges. Also, don't forget to check out https://receipt-ai.com —it's up and running.
Top comments (0)