I am not able to connect to postgres

sudo docker-compose up
Starting postgres … done
Starting kong … done
Starting app … done
Attaching to postgres, kong, app
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2023-03-21 10:56:02.957 UTC [1] LOG: starting PostgreSQL 12.14 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924, 64-bit
postgres | 2023-03-21 10:56:02.958 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
postgres | 2023-03-21 10:56:02.958 UTC [1] LOG: listening on IPv6 address “::”, port 5432
postgres | 2023-03-21 10:56:02.962 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
postgres | 2023-03-21 10:56:02.983 UTC [23] LOG: database system was interrupted; last known up at 2023-03-21 10:53:27 UTC
postgres | 2023-03-21 10:56:03.009 UTC [23] LOG: database system was not properly shut down; automatic recovery in progress
postgres | 2023-03-21 10:56:03.013 UTC [23] LOG: redo starts at 0/1651B48
postgres | 2023-03-21 10:56:03.013 UTC [23] LOG: invalid record length at 0/1651B80: wanted 24, got 0
postgres | 2023-03-21 10:56:03.013 UTC [23] LOG: redo done at 0/1651B48
postgres | 2023-03-21 10:56:03.031 UTC [1] LOG: database system is ready to accept connections
kong | 2023/03/21 10:56:04 [warn] ulimit is currently set to “1024”. For better performance set it to at least “4096” using “ulimit -n”
kong | 2023/03/21 10:56:04 [warn] 1#0: the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/kong/nginx.conf:6
kong | nginx: [warn] the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/kong/nginx.conf:6
kong | 2023/03/21 10:56:04 [notice] 1#0: [kong] vault.lua:457 cannot automatically rotate secrets in absence of options[“$refs”]
kong | 2023/03/21 10:56:04 [error] 1#0: init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:559: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: timeout
kong | stack traceback:
kong | [C]: in function ‘assert’
kong | /usr/local/share/lua/5.1/kong/init.lua:559: in function ‘init’
kong | init_by_lua:3: in main chunk
kong | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:559: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: timeout
kong | stack traceback:
kong | [C]: in function ‘assert’
kong | /usr/local/share/lua/5.1/kong/init.lua:559: in function ‘init’
kong | init_by_lua:3: in main chunk

getting the above error
here is docker-compose file

container_name: postgres
ports:
- “5432:5432”
environment:
POSTGRES_DB: kong
POSTGRES_USER: kong
POSTGRES_PASSWORD: kong
volumes:
- postgres_data:/var/lib/postgresql/data/
networks:
- kong
app:
build: .
container_name: app
ports:
- “8080:8080”
environment:
DATABASE_URL: postgresql://kong:kong@postgres:5432/kong?sslmode=disable
KONG_ADMIN_LISTEN: 0.0.0.0:8001, 0.0.0.0:8444 ssl
depends_on:
- kong
- postgres
networks:
- kong
networks:
kong:
volumes:
postgres_data:

The one time I’ve seen this before:
kong | nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/init.lua:559: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: timeout

Was that postgres was requiring SSL but kong was not using SSL when trying to connect. However, I would guess that if were using wrong hostname or port or if kong and postgress were on different networks, could see the same issue.