Cannot access main postgres database with coolify

I installed Noocdb on coolify. I added a postgres service to the project. Use the env variable NC_DB with the value

pg://j4g44okskok04cks4kwogkkg:5432?u=postgres&p=<password>&d=postgres

but I am getting this error in logs post deployment while trying to run he service:

[Nest] 9  - 09/07/2024, 7:31:25 PM   ERROR ;5;3m[ExceptionHandler] Error: getaddrinfo EAI_AGAIN j4g44okskok04cks4kwogkkg
Error: Error: getaddrinfo EAI_AGAIN j4g44okskok04cks4kwogkkg
    at NcConfig.create (/usr/src/app/docker/main.js:2:2228217)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InstanceWrapper.useFactory [as metatype] (/usr/src/app/docker/main.js:2:1830025)
    at async Injector.instantiateClass (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:369:37)
    at async callback (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:65:34)
    at async Injector.resolveConstructorParams (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:144:24)
    at async Injector.loadInstance (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:70:13)
    at async Injector.loadProvider (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:97:9)
    at async /usr/src/app/node_modules/@nestjs/core/injector/instance-loader.js:56:13
    at async Promise.all (index 3)

Which means postgres client is unable to resolve the hostname of the pg service. To ensure this is not a coolify issue I created a simple nodejs application and added it to the same project. It was able to access pg service using the same hostname.

Please verify if your password has below character which might be interfering with env variable parsing (which is in URL format).

It doesn’t. All numbers and letters. The error is caused by hostname resolution before even trying to connect. Also the hostname in the error message is correct which means the env variable was read properly.

I used knex in my own nodejs application and it resolved the container name properly. I used the same knex connection json used in nocodb instance

Glad this was figured out. If you could also mention what was the extra key you used in NC_DB_JSON that would be helpful to others in the community.

I only figured out that knex is able to resolve the db container hostname inside my application, hence theoretically everything should work accordingly in nocodb. But it still doesn’t work in nocodb. I used the same knex json in NC_DB_JSON and I tried both methods: a connection object and a connection string url for the connection key. Both methods worked inside my application, and didn’t work inside nocodb

I only figured out that knex is able to resolve the db container hostname inside my application

Can you give more details on this, Is your application running as a container ? If not then it looks like the host name not avail inside the nocodb container.

If you are using docker compose then can you share the compose file ? Although from where the j4g44okskok04cks4kwogkkg hostname is derived? Is it a container id or did you added it in hosts file ?

Coolify uses nixpacks to run my application inside a container. This container is part of the same project that also has pg container and nocodb container. They are connected together with a docker network also managed by coolify.

j4g44okskok04cks4kwogkkg is the pg container name which should be resolved by the docker network to point to the correct container. Inside my application this resolution happens and my application is able to connect to pg using knex.

Is it possible to get inside nocodb docker container and check the host available or not ? Although confirm that both are under same network.

Following threads may help as well - The getaddrinfo EAI_AGAIN error again · Issue #15780 · nodejs/node · GitHub , javascript - What's the cause of the error 'getaddrinfo EAI_AGAIN'? - Stack Overflow

After reading above it feels more issue with how coolify is setting up things for you (I 've not tried it so can not comment much)

However, if you have a VPS/Server : you should definitely try our new installation command - just a single one

bash <(curl -sSL http://install.nocodb.com/noco.sh) <(mktemp)

Notes from our docs

What is auto-upstall ?
Auto-upstall is the fastest way to install NocoDB with SSL, auto-upgrades with every release, and auto-renews your SSL — all within just 2 minutes!

How it works when we run it ? :

  • :whale: First it automatically installs all pre-requisites on your linux based server (docker, docker-compose)
  • :rocket: Then automatically installs
    • 🇳 NocoDB,
    • :elephant: PostgreSQL,
    • :zap: Redis,
    • :file_cabinet: Minio,
    • :globe_with_meridians: Traefik gateway.
  • :arrows_counterclockwise: Also automatically upgrades NocoDB when new versions are available.
  • :lock: And finally automatically sets up SSL that auto-renews!

Thank you for your suggestion and time, but this does not solve the case of installing NocoDB on coolify which is what I am trying to achieve. I am sure installing NocoDB directly on the server will work but this is not what I’m trying to do. It needs to be installed on coolify.

Coolify allows you to run commands inside the container. I am able to ping the container name from inside my app container but not nocodb container. I got the IP address of the PG container from my application. I am able to ping it from inside nocodb container. I used the IP address as the hostname in NC_DB_JSON but received the new exception:

[Nest] 8  - 09/10/2024, 6:43:53 PM   ERROR ;5;3m[ExceptionHandler] KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Error: KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at NcConfig.create (/usr/src/app/docker/main.js:2:2228217)
    at async InstanceWrapper.useFactory [as metatype] (/usr/src/app/docker/main.js:2:1830025)
    at async Injector.instantiateClass (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:369:37)
    at async callback (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:65:34)
    at async Injector.resolveConstructorParams (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:144:24)
    at async Injector.loadInstance (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:70:13)
    at async Injector.loadProvider (/usr/src/app/node_modules/@nestjs/core/injector/injector.js:97:9)
    at async /usr/src/app/node_modules/@nestjs/core/injector/instance-loader.js:56:13
    at async Promise.all (index 3)
    at async InstanceLoader.createInstancesOfProviders (/usr/src/app/node_modules/@nestjs/core/injector/instance-loader.js:55:9)

Can you share the sample(with dummy value) of NC_DB_JSON value you are using.

{“client”:“pg”,“connection”:{“host”:“172.18.0.7”,“port”:5432,“user”:“postgres”,“password”:“password”,“database”:“postgres”}}

Hey @shady, at this juncture - I would like you to urge to figure it out by running a bare minimal docker compose on a VPS with postgres to check how it works. And there are like 1000s of installations running like this. It will help you figure the missing parts with coolify. Its beyond us to support / figure what is going wrong specially at coolify.

Got the response from coolify issue queue. Had to set “connect to predefined network” for this to work.

That is so great to hear.

If you don’t mind - please add a sample of docker-compose or likes here or make a PR in our github.

This will be so useful to both nocodb and coolify community.

I am using coolify application installation which pulls nocodb/nocodb docker image and deploys it. I do not make any changes to the docker-compose file. It’s just a setting in coolify that forces containers in docker-compose deployments to use the coolify network and not its own.

I was able to reach PG container from NocoDB instance, but for some reason this deployment wont even read the env variables directly from coolify, I had to edit docker-compose in coolify under service stack and add those:

services:
  nocodb:
    environment:
      - 'NC_REDIS_URL=${NC_REDIS_URL}'
      - 'NC_DB=${NC_DB}'

Now I have a working instance that’s connected to PG.

2 Likes