How to overcome SQLite limitation when building Rails application by using PostgreSQL

Image for post
Image for post

The default Relational Database Management System (RDBMS) that is used when you create a new Rails project is SQLite. SQLite is fine for a small stand-alone application. However, it has some limitations, such as the lack of ability to deal with huge databases and concurrency, which is the ability for more than one user to write to the database. If you wish to use another RDBMS that Rails supports, you will have to specify it when you first create the project, otherwise, it will be a little harder to switch to afterward.

This blog will teach you how to create your Rails application using PostgreSQL in very easy straightforward steps.

Make sure you installed Rails on your machine. If it is not installed, use the following command to do so:
$ gem install rails

If you want to use PostgreSQL in your rails application, you need to first have it on your local machine. To install PostgreSQL you can go to the official website and download it from there. If you are using Ubuntu/Linux like myself, I have it here handy for you, just run the following command in your terminal:
$ sudo apt-get -y install postgresql

After you made sure you have PostgreSQL on your machine, you need to install the ruby PostgreSQL plugin/gem that is required so you can interact with the database management system from your rails application.
To install the gem just run the following command in your terminal:
$ gem install pg

The command to create a new rails project is rails new app-name, but as I said before, SQLite will be the RDBMS by default. It is very simple to change the default by indicating while creating your application. You just need to append a “postgresql” flag to your command as follows:
$ rails new application-name --database=postgresql
To make sure you have created a rails application with PostgreSQL, after the command finishes creating your new application, go to the GemFile, you will see the ‘pg’ gem is included as highlighted below:

Image for post
Image for post

Hope that was helpful and always consider using PostgreSQL because SQLite has a limitation in the production lifecycle. Leave a comment below if you have another thing you would like to add.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store