Cron job can't access database

I have an application, accessing a PostgreSQL database via the DATABASE_URL environment variable.

I have a cron job, attempting to access the database via the same environment variable. For some reason, the cron job can’t resolve the domain. I keep getting the following error:

django.db.utils.OperationalError: could not translate host name “dpg-c9l77650mal5d4tm6j7g-a” to address: Name or service not known

I checked the DATABASE_URL in both the application and the cron job and they are exactly the same.

Any ideas what is going on here?

It’s also worth pointing out that if i SSH into the application server and run the job manually it works fine. It’s as if the CRON job doesn’t have network access to the DB.

Hey Jack,
That error smells very much like the 2 services aren’t in the same region. We don’t have cross regional network access so it would be worth checking if that.

Hi Jack,

Thanks for reaching out.

We most often see this type of issue when services aren’t in the same region. Services can’t communicate cross-region currently.

If the DB/Cron Job you are referring to are in the same region, please let us know and we’ll take a deeper look.

Kind regards

Alan

JINX! :slight_smile:

Ah, that was it! I forgot to specify the region in my render.yaml file.

Great - we’ve actually put some logic in place when services are created by the dashboard to highlight where you have services running to help you choose and we default the region picker to the region where you have the most services running - this isn’t surfaced when you create services via blueprints though but we should do better here to summarize what’s going to be created.

John B