The previous answers were not working for me with Strapi V4 and Heroku so I rewrote database.js based on the latest doc and it now works!
const { parse } = require("pg-connection-string");
module.exports = ({ env }) => {
const { host, port, database, user, password } = parse(env("DATABASE_URL"));
return {
connection: {
client: 'postgres',
connection: {
host,
port,
database,
user,
password,
ssl: { rejectUnauthorized: false },
},
debug: false,
},
}
};