Error: getaddrinfo ENOTFOUND ${db.HOSTNAME}

I’m deploying Strapi on Digital Ocean App platform. Strapi builds correctly, but I get an error on the deploy phase:

Error: getaddrinfo ENOTFOUND ${db.HOSTNAME}

I have a database.js for production at config/env/production containing the following code

module.exports = ({ env }) => ({
connection: {
client: ‘postgres’,
connection: {
host: env(‘DATABASE_HOST’, ‘127.0.0.1’),
port: env.int(‘DATABASE_PORT’, 5432),
database: env(‘DATABASE_NAME’, ‘neekplatform’),
user: env(‘DATABASE_USERNAME’, ‘webdev’),
password: env(‘DATABASE_PASSWORD’, ‘Development’),
ssl:{
ca: env(‘DATABASE_CA’)
},
},
debug: false,
},
});

Environment variables are set in the app settings in Digital Ocean.

I’ve got the exact same error. Anyone with a solution?

im dealing with the same thing. i went ahead and hardcoded the database values and it worked after that. but im still getting other issues so i cant say it worked 100%

this might be the answer!

From the Strapi Digital Ocean deployment docs:

The default database name is “db” and is used to prefix the database values in the global environment table. If another database name is used, it should be substituted for “db”.

At first, when I renamed my database from db to new-database-name, I forgot to update the app-level environment variables accordingly.

When I changed ${db.HOSTNAME} to ${new-database-name.HOSTNAME} (and did the same for all the others) the deployment worked.

2 Likes

@jenibelle08 You save my life!
I used Digital Ocean to serve my Strapi 4. It is upgraded to managed Database cluster.

The point you mentioned, “db”, is the “db” tab in the components of the App.

I was trapped while I try to restore my DB from a backup

When try to restore the DB,
Digital Ocean will create a new Database cluster from the backup.
After the new cluster is created, we have to attach the new DB cluster to the Strapi App.

Screenshot 2023-02-16 at 9.55.37 AM

And cancel the auto build immediately.

Then update all the environment variables as you said, to the ${xxxx.HOSTNAME} , where xxxx is the new DB cluster component name I want to attach to my strapi.


app-YYYY is the unique ID of the cluster component

Save and Let it build once.

Change ${db.HOSTNAME} to ${xxxxx.HOSTNAME} (and the same for other vars), where ‘xxxxx’ is the db cluster name, for me which looked like this: ‘db-postgresql.abcd.1234’