Separating the database from the actual Rails app is probably the first thing everyone will do when they want to scale their app, but still, I’m unable to find a tutorial on how to do it. It will be great if you can include one in the “Articles and Tutorials” section or at least give me a link to a page that explains how to solve this problem. Thanks.
PS: I’ll probably use Nginx as an web server, PostgreSQL as RDBMS so it’s better if the tutorial will use them.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It’s actually quite easy to separate out the DB from your app. <br> <br>Just install it on a separate server and make sure that it’s bound to your public IP address or 0.0.0.0 instead of just 127.0.0.1 and then configure your user to be able to connect from your app server. <br> <br>On your app server just specify the IP of your remote DB server instead of localhost and you’re all set.
You can set the DATABASE_URL environment variable: <br>For MySQL (using the mysql2 gem): <br>DATABASE_URL=“mysql2://username:password@host:port/database” <br> <br>For Postgres (using the pg gem): <br>DATABASE_URL=“postgres://username:password@host:port/database” <br> <br>Rails looks for this variable and will use it in place of the database.yml configuration. <br> <br>If you’d rather set it in your database.yml file (that’s all great and all, but don’t check it into source control!!!), just set: <br> <br>host: host:port <br> <br>and that will point the database directly to that hostname. All other variables work as expected.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.