Search code examples
postgresqlsslherokustrapiheroku-postgres

Strapi CMS on Heroku Postgres - no pg_hba.conf entry, SSL off


I have 2 apps in Heroku with same code version, both using Heroku Postgres with plan free (Hobby). But they were created in different time, some months of difference.

And the problem is, the first work fine, but the second thows error on start

error: no pg_hba.conf entry for host "210.221.51.3", user "byhoyaaasdevfr", database "darcnk9hucbap", SSL off

I read about use SSL, but I want to keep the free plan, and the first app work fine without. This is the connection file content:

const parse = require("pg-connection-string").parse;
const config = parse(process.env.DATABASE_URL);

module.exports = ({ env }) => ({
  defaultConnection: "default",
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "postgres",
        host: config.host,
        port: config.port,
        database: config.database,
        username: config.user,
        password: config.password,
      },
      options: {
        ssl: false,
      },
    },
  },
});

Changing the options ssl to true throws

error Error: self signed certificate

  • I already recreate the app and database.
  • I already connect the second app with the first database succefully.
  • Local using second database connection credential thows the same error.
  • Local using first database connection credential also thows the same error.

Strapi 3.1.5

Thanks for your attention, you are amazing.


Solution

  • We ran into the same issue today and fixed it by updating our config/env/production/database.js with the one provided by Strapi for Heroku:

    const { parse } = require("pg-connection-string");
    
    module.exports = ({ env }) => {
      const { host, port, database, user, password } = parse(env("DATABASE_URL"));
    
      return {
        defaultConnection: "default",
        connections: {
          default: {
            connector: "bookshelf",
            settings: {
              client: "postgres",
              host,
              port,
              database,
              username: user,
              password,
              ssl: { rejectUnauthorized: false }
            },
            options: {
              ssl: false
            },
          },
        },
      };
    };
    

    The part that fixed it was the ssl: { rejectUnauthorized: false } line. I just don't understand why ssl must be disabled on Heroku pg...