Postgres池未连接到客户端

时间:2020-04-28 00:16:44

标签: node.js postgresql backend

我的postgres池未连接到客户端,并且几乎可以确定我将正确的属性传递给了它。

这是池实例:


const { Pool } = require('pg')

module.exports = new Pool({
    host: 'localhost',
    port: 5432,
    user: 'laura',
    password: 123,
    database: 'launchstore'
})

然后我用docker-compose创建了postgres服务:

version: '3.3'

services:
  postgres:
    container_name: postgres
    image: postgres
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_DB: ${POSTGRES_DATABASE}
    ports:
      - "5432:5432"
    restart: unless-stopped

我的环境文件:

POSTGRES_DATABASE=launchstore
POSTGRES_PASSWORD=123
POSTGRES_USER=laura

当我进入页面时,它会不断加载,这就是为什么我尝试记录池实例的结果:

Pool {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  options: {
    Client: [Function: Client] { Query: [Function: Query] },
    host: 'localhost',
    port: 5432,
    user: 'laura',
    password: 123,
    database: 'postgres',
    max: 10,
    idleTimeoutMillis: 10000
  },
  log: [Function (anonymous)],
  Client: [Function: Client] { Query: [Function: Query] },
  Promise: [Function: Promise],
  _clients: [],
  _idle: [],
  _pendingQueue: [],
  _endCallback: undefined,
  ending: false,
  ended: false,
  [Symbol(kCapture)]: false
}

如果我传递正确的属性并且我的容器正在运行,为什么我的客户端无法连接到池?

1 个答案:

答案 0 :(得分:0)

PG依赖关系未正确安装,这就是池也无法正常工作的原因。因此,它与任何配置错误都不相关。