User Documentation

Configure PostgreSQL for Strapi on

Sign up for Upsun

Get your free trial by clicking the link below.

Get your Upsun free trial

Strapi can be configured to use PostgreSQL as its default database. You can choose PostgreSQL when installing your app by selecting custom and PostgreSQL when asked for the installation type or you can just configure your existing Strapi application to use PostgreSQL. To configure a PostgreSQL database for Strapi on, follow these steps.

  1. Install PostgreSQL on your machine and pg in your Strapi project. Pg comes installed with a fresh Strapi installation.

  2. In your .platform/services.yaml file, add the following:

    	     type: postgresql:13
             disk: 512
  3. In your file, replace the relationship name to match the PostgreSQL database you added:

       postgresdatabase: "postgres:postgresql"
  4. In the config folder, locate the database.js file, and replace its content with the following:

    const path = require("path");
    const config = require("platformsh-config").config();
    let dbRelationship = "postgresdatabase";
    // Strapi default sqlite settings.
    let connection = {
      connection: {
        client: "sqlite",
        connection: {
          filename: path.join(
            process.env.DATABASE_FILENAME || ".tmp/data.db"
        useNullAsDefault: true,
    if (config.isValidPlatform() && !config.inBuild()) {
      // database configuration.
      const credentials = config.credentials(dbRelationship);
        `Using configuration with relationship ${dbRelationship}.`
      let pool = {
        min: 0,
        max: 10,
        acquireTimeoutMillis: 600000,
        createTimeoutMillis: 30000,
        idleTimeoutMillis: 20000,
        reapIntervalMillis: 20000,
        createRetryIntervalMillis: 200,
      connection = {
        connection: {
          client: "postgres",
          connection: {
            host: credentials.ip,
            port: credentials.port,
            database: credentials.path,
            user: credentials.username,
            password: credentials.password,
            ssl: false,
          debug: false,
    } else {
      if (config.isValidPlatform()) {
        // Build hook configuration message.
          "Using default configuration during build hook until relationships are available."
      } else {
        // Strapi default local configuration.
          "Not in a Environment. Using default local sqlite configuration."
    // export strapi database connection
    module.exports = ({ env }) => connection;

This setting deploys your Strapi application with a PostgreSQL database. If you don’t specify a PostgreSQL service in your .platform/services.yaml file or the Strapi application is run on a local machine the default SQLite database is used.

Is this page helpful?