Reputation: 463
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.
Upvotes: 4
Views: 11949
Reputation: 2625
I had a similar issue. After updating the Postgresql config with no success, it ended up being a "#" in the password of my user.
https://github.com/pantsel/konga/issues/510
Upvotes: 0
Reputation: 70510
When running the application completely via docker-compose
using DB_HOST=postgres
is fine, as docker-compose will create a DNS resolution between services using the service name as the host. However, with the server running locally, and the database running through docker-compose
you need to use the value localhost
for the DB_HOST
Upvotes: 1