Using PostgreSQL
You might recall from Chapter 1, An Introduction to Strapi, that Strapi is database-agnostic, meaning that it can work with different database systems. We will configure Strapi to use a PostgreSQL database in production and keep SQLite for development. Let's get started, as follows:
- The first thing to do is to install the PostgreSQL client.
- From the terminal, navigate to the project root and run the
yarn add pg
command. This will install the PostgreSQL Node.js client to the project. - Create a
config/env/production/database.js
file. This file will be used to configure the database in the production environment.Remember
Strapi uses the
config/database.js
file to load the database configurations. However, since we want to use PostgreSQL in the production environment only, we used theconfig/env/production/database.js
file instead. - Add the following content:
module.exports = ({ env }) => ({ connection: { ...