Platform.sh is now Upsun. Click here to learn more
Upsun Fixed User Documentation

Configure PostgreSQL for Strapi on Upsun Fixed

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!¹ A monthly $19 perk!
Activate your 15-day trial
¹Terms and conditions apply

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 Upsun Fixed, 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:

    .platform/services.yaml
    	postgres:
       type: postgresql:13
         disk: 512
  3. In your .platform.app.yaml file, replace the relationship name to match the PostgreSQL database you added:

    .platform.app.yaml
    relationships:
      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(
            __dirname,
            "..",
            process.env.DATABASE_FILENAME || ".tmp/data.db"
          ),
        },
        useNullAsDefault: true,
      },
    };
    
    if (config.isValidPlatform() && !config.inBuild()) {
      // Upsun Fixed database configuration.
      const credentials = config.credentials(dbRelationship);
      console.log(
        `Using Upsun Fixed 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,
          pool,
        },
      };
    } else {
      if (config.isValidPlatform()) {
        // Build hook configuration message.
        console.log(
          "Using default configuration during Upsun Fixed build hook until relationships are available."
        );
      } else {
        // Strapi default local configuration.
        console.log(
          "Not in a Upsun Fixed Environment. Using default local sqlite configuration."
        );
      }
    }
    
    console.log(connection);
    
    // 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.