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

Shaqqour
2 min readOct 9, 2020

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.

1) Installing Rails

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

2) Installing PostgreSQL on your local machine

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

3) Installing the PostgreSQL gem

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

4) Create your Rails project with PostgreSQL

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:

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.

--

--

Shaqqour

Full stack software engineer. Passionate about making people’s lives better and easier through programming. LinkedIn.com/in/shaqqour