Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJS => PostgresQL: Error: getaddrinfo EAI_AGAIN postgres at GetAddrInfoReqWrap.onlookup

I've been developing a NestJS-GraphQL app connecting to my local Postgres database. Everything had been working fine until Ubuntu 20.04 reinstallation.

After cloning a repo with the project, installing Postgres, and building the application with yarn start:dev I can see this strange error:

[Nest] 21577  - 02/05/2022, 2:51:10 PM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
Error: getaddrinfo EAI_AGAIN postgres
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)

Postgres is running:

hleb@hleb:~$ psql artwine postgres
psql (14.1 (Ubuntu 14.1-2.pgdg20.04+1))
Type "help" for help.

artwine=# 

/etc/postgresql/14/main/pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                trust

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256

/etc/postgresql/14/main/pg_ident.conf

# MAPNAME       SYSTEM-USERNAME         PG-USERNAME
user1           hleb                    postgres

.env

DB_TYPE=postgres
DB_HOST=postgres
DB_PORT=5432
DB_USERNAME=hleb
DB_NAME=artwine
DB_PASSWORD=Mypassword

Looking forward to the community help as I have no idea what could go wrong. Tried: node_modules reinstall, Postgres reinstall, dist folder recreation.

Remark: After building a repo with yarn start:dev I ran the application in docker container using docker-compose. Everything worked fine with no errors. Maybe it will be useful for the investigation. Thanks for your time, do appreciate it.

like image 506
Gleb Gaiduk Avatar asked Oct 18 '25 17:10

Gleb Gaiduk


1 Answers

DB_HOST=localhost instead of DB_HOST=postgres

like image 126
Gleb Gaiduk Avatar answered Oct 20 '25 09:10

Gleb Gaiduk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!