我正在使用npm pg
("pg": "^7.18.2", "pg-native": "^3.0.0"
我的package.json中的)新手将新手node
应用程序连接到postgresql
数据库。我使用docker-compose
以下配置来启动所有内容:
version: '3'
services:
postgres:
image: 'postgres:latest'
environment:
- POSTGRES_USER=postgres_user
- POSTGRES_PASSWORD=postgres_password
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres_user"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: 'redis:latest'
nginx:
restart: always
build:
dockerfile: Dockerfile.dev
context: ./nginx
ports:
- '8000:80'
depends_on:
- fibclient
- fibserver
fibserver:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- './server:/app'
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
- PGUSER=postgres_user
- PGPASSWORD=postgres_password
- PGHOST=postgres
- PGPORT=5432
- PGDATABASE=postgres
depends_on:
- redis
- postgres
- fibworker
ports:
- '9229:9229'
fibclient:
build:
dockerfile: Dockerfile.dev
context: ./client
volumes:
- './client:/app'
fibworker:
build:
dockerfile: Dockerfile.dev
context: ./fibworker
volumes:
- './fibworker:/app'
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
ports:
- '9230:9229'
depends_on:
- redis
可以想象fibserver
,后端应用程序试图连接到postgres
托管postgresql
数据库的服务。可悲的是,fibserver
应用程序在连接到数据库时总是出现此错误:
fibserver_1 | Error: Connection terminated due to connection timeout
fibserver_1 | at Connection.<anonymous> (/app/node_modules/pg/lib/client.js:255:9)
fibserver_1 | at Object.onceWrapper (events.js:420:28)
fibserver_1 | at Connection.emit (events.js:314:20)
fibserver_1 | at Socket.<anonymous> (/app/node_modules/pg/lib/connection.js:78:10)
fibserver_1 | at Socket.emit (events.js:314:20)
fibserver_1 | at emitCloseNT (net.js:1657:8)
fibserver_1 | at processTicksAndRejections (internal/process/task_queues.js:79:21)
fibserver_1 | at runNextTicks (internal/process/task_queues.js:62:3)
fibserver_1 | at listOnTimeout (internal/timers.js:520:9)
fibserver_1 | at processTimers (internal/timers.js:494:7)
docker-compose
如果服务可以相互识别(fibserver
可以ping查postgres
),npm pg
配置,文档和示例,并且我觉得一切正常,那么我会仔细检查文件。仍然缺少一些东西。这是在那里你可以找到整个东西。
更新:我在我的断路器中放了一个简单的断路器fibserver
:当他无法连接数据库时,它会等待一段时间,然后重试。好fibserver
了postgres
,即使在10分钟之后,也做了很多尝试连接服务的尝试。可能是我使用npm pg
图书馆导致此问题吗?如果有人想看看,我也会更新主人。谢谢。
更新:我将psql安装到fibserver容器中,并且成功地成功连接到postgres服务,我认为这与我使用pg客户端的方式有关。这是我应该尝试过的东西。
最后有一些时间来解决这个问题。我pg
在我的fibserver应用程序中卸载了两个模块,然后再次安装pg,为我提供了npm
pg
模块的新版本(8.3.3),而没有可能错误安装的本机部分。单个javascriptpg
库即可完成工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句