How to use multiple databases for Rails server? - ruby-on-rails

I have a Rails application which is using PostgreSQL database and a huge user base is expected. Is there a way to use multiple databases, may be one database for Read operations and other for Write operations.
Any suggestions/solution?

You can achieve it via database clustering. Master database and slave database. Try using amazon RDS or Heroku services.

Use database sharding. Try using Master and slave databases.
Octopus is a really useful gem for that. https://github.com/thiagopradi/octopus

Related

Can Node and Rails share database?

I have a Rails app which is using Postgresql. I want to make a new Node + React Native app and I want to use the same database (usernames, passwords and other details will be shared).
I saw lots of sources which are explaining how to set up Postgresql on Node, but how do I set up an existing database? For the dev environment it is stored locally if I'm not mistaken.
You just need to use this package.
https://github.com/sequelize/sequelize
This is a connector for nodejs and postgresql.
But I suggest you do not use both of them handle database migration at the same time.
You can use rails to handle the migration. And just implement the database query in nodejs.

How to setup new Redshift database with Heroku/Rails 4 app

I have been using Heroku-postgres as my database for my rails 4 app deployed to Heroku.
I connect to the DB locally using pgAdmin3, and haven't had any issues.
Now, I want to switch my database to a amazon-redshift instance which has been spun up for me. All I have is a username, password, and the database host name. Where do I store this information within my Rails 4 app so that my app will use this DB instead of the current postgres DB?
I provided a similar answer here, but I would recommend using this adapter to connect:
https://github.com/fiksu/activerecord-redshift-adapter
This certainly works well for any ActiveRecord query you need to do, I'm using insert statements to update redshift tables rather than ActiveRecord create. Working on a full redshift adapter, hopefully to be released in the next few weeks.
Here's the answer I've given in the past with code examples about halfway down:
How can I build a front end for querying a Redshift database (hopefully with Rails)
Heroku will need to support Redshift as a database option for you, otherwise you'll need to spin up your own stack.
It might be worthwhile checking out AWS EBS service to do this.

Is it possible to share a common Neo4j db by two Rails apps, each using Neography?

While using the Neography gem to implement a Neo4j database on a Rails app, it so appears that the database is local to that particular Rails app's embedded Neo4j server. I wish to share a common Neo4j DB between two Rails apps, just the way you could do with a MySQL database through entries into database.yml. Is this impossible while using Neography? If so, what could be my possible alternatives which don't involve JRuby(i.e. using neo4j.rb).
Neography is a wrapper to query a neo4j server through the REST protocol. In that case, you should be able to query from anywhere you want, once you have started the server, even with a simple curl command.
You want especially to uncomment this line in conf/neo4j-server.properties if your apps are on 2 different servers :
org.neo4j.server.webserver.address=0.0.0.0
Make sure however to protect your database, you can read here how to : http://docs.neo4j.org/chunked/stable/security-server.html

Which database should be chosen in Heroku?

I want to migrate a database to Heroku. The old database is exported to some JSON files, but now I don't know how to select the database in Heroku.
My issue is:
The data is always increasing, so in the future, there will be a lot of data. Which database is available for this?
I can only get JSON files from my old database. Can it be imported into the Heroku database?
My users are mostly in America. The database in Heroku whether lead the user's access speed slowly or not?
My project is using Ruby on Rails.
What should I do?
First of all, Heroku provides PostgreSQL as the default database. It might be the following reasons for use it.
PostgreSQL is a powerful, open source object-relational database system.
Heroku Postgres is the SQL database service run by Heroku that is provisioned and managed as an add-on.
Heroku Postgres is accessible from any language with a PostgreSQL driver including all languages and frameworks supported by Heroku: Java, Ruby, Python, Scala, Play, Node.js and Clojure.
For more you can refer this http://www.postgresql.org/about/advantages/.
It's better that you specify the database you currently use for your application. If you give more information, I will update my answer.
But firstly, reading the article Moving a Rails App to Heroku will help you a lot with moving the application to Heroku.
Heroku has addons from another provider. The only database they provide is PostgreSQL which is very nice and suitable for many kind of applications. It's just brilliant.
Read the mentioned article above.
If you create your application in Heroku, it will be located in the USA by default. I don't know if Heroku optimizes to the location of your application and addons or not, but normally if you have something slow in your application, it's your fault, not Heroku's.
Yes! Heroku loves Ruby on Rails

Database loadbalancing outside rails application?

I want to make a master/slave setup on my postgresql servers. My problem is how I can get queries from my rails app balanced to the databases? I can't use a gem like Octopus, because it collides with my use of the Apartment gem (both modifies ActiveRecord) inspired by this rails cast. Does anyone know of a way to load balance outside the rails app?
You may consider using pgPool that allows distribution of SELECT request across a pool of servers.
PgBouncer efficiently supports both connection pooling and simple load balancing.

Resources