Question

How to fix Error: connect ETIMEDOUT 138.68.132.125:25060 In Postgresql

I know this seems like a redundant question, but I’ve checked others like it and non of them helped.

I am trying to seed my DO managed Postgres DB with some data, while the seeder works perfectly fine in development I kept getting this timeout error when trying to do the same in production. Below is what my config looks like with nestJs and typeorm

{
        type: 'postgres',
        host: DB_HOST,
        port: +DB_PORT,
        username: DB_USERNAME,
        password: DB_PASSWORD,
        database: DB_NAME,
        entities: [__dirname + '/../**/*.entity.{js,ts}'],
        ssl:
          process.env.NODE_ENV === 'prod'
            ? {
                requestCert: true,
                rejectUnauthorized: true,
                ca: fs.readFileSync(`${process.cwd()}/ca-certificate.crt`).toString(),
              }
            : undefined,
        autoLoadEntities: true,
}

Any form of help is welcome, thank you

Show comments

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
November 3, 2022

Hi @msadiq,

First, check the following article:

https://docs.digitalocean.com/products/app-platform/how-to/use-environment-variables/#databases

Try to define the variables as suggested there ^

Additionally, Have you check out Trusted sources? (click on your app and click on the Settings tab) You could have restricted access to database cluster.

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
November 2, 2022

👋 @msadiq

Hmm, let me see if I can help. Attached DB’s bind variables (eg. the env vars that are set like DB_HOST=${db.HOSTNAME} are not available during build time. If you’r trying to run this script as part of the app build that is likely the culprit. I would recommend running this seed as part of your application startup or as a predeploy job.

If the above is not the case, then try outputting some of your env vars to console during app startup and verify they are correct.

Hope this helps!

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.