【问题标题】:Panic : Could not connect : Dial TCP X.X.X.X:5432 : Connect : Connection refused恐慌:无法连接:拨号 TCP X.X.X.X:5432:连接:连接被拒绝
【发布时间】:2022-01-12 17:19:07
【问题描述】:

我正在尝试使用 Docker Compose 安装 TimeScaleDB,但在使用 timescaledb-parallel-copy 导入数据时出现以下错误:

/usr/local/bin/docker-entrypoint.sh:正在运行 /docker-entrypoint-initdb.d/import_data.sh timescaledb |恐慌:可以 未连接:拨打 tcp 172.18.0.2:5432:连接:连接被拒绝 时标数据库 |时标数据库 | goroutine 6 [运行]: timescaledb | main.processBatches(0xc000016730, 0xc000060780) timescaledb | /go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:238 +0x8bb 时间刻度数据库 |创建者 main.main timescaledb | /go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:148 +0x1d2 时间刻度数据库 |恐慌:无法连接:拨打 tcp 172.18.0.2:5432:连接:连接被拒绝

这是我的 docker compose 和我的 docker 文件:

Docker 撰写:

version: "3.8"
services:
  timescaledb:
    container_name: timescaledb
    build:
      context: "./timescaledb"
      dockerfile: "docker_file"
    env_file:
      - "./timescaledb/environment.env"
    volumes:
      - "./timescaledb/data:/data"
    ports:
      - "5432:5432/tcp"
    networks:
      - local_network
    restart: on-failure
networks:
  local_network:

Docker 文件:

FROM timescale/timescaledb:latest-pg13
ADD create_tables.sql /docker-entrypoint-initdb.d
ADD import_data.sh /docker-entrypoint-initdb.d
RUN chmod a+r /docker-entrypoint-initdb.d/*

这是调用 timescaledb-parallel-copy 的 import_data.sh 脚本:

#!/bin/bash
timescaledb-parallel-copy --connection "host=timescaledb user=postgres password=XXX sslmode=disable" --db-name YYY --table ZZZ --copy-options "CSV" -skip-header --columns "name, unit" --file "/data/data.csv" --reporting-period 30s workers 4

我也尝试过使用 localhost,但我得到了同样的错误。

【问题讨论】:

  • 您好 Manele,请查看我们在 Timescale slack 社区中遇到相同错误的人的一些笔记。他们发现 sslmode 后面的 disable 这个词必须在 " 标记中,但是因为该短语已经包含在 "" 中,这很痛苦。但是, sslmode=disable 是默认值,所以严格来说你不需要它。值得试试?如果你想保留它,你可能需要添加转义字符?透明度:我为 Timescale 工作
  • @greenweeds 我尝试删除 sslmode=disable 但仍然遇到同样的错误。

标签: postgresql docker go docker-compose timescaledb


【解决方案1】:

编辑:问题已解决。不应在连接字符串中指定主机。根据官方文档(https://hub.docker.com/_/postgres):

此外,从 docker-library/postgres#440 开始,为这些初始化脚本启动的临时守护程序仅在 Unix 套接字上侦听,因此任何 psql 使用都应删除主机名部分(参见 docker-library/postgres#474(注释) 例如)。

【讨论】:

    猜你喜欢
    • 2019-12-25
    • 2020-01-01
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 2019-12-12
    • 2018-12-26
    • 1970-01-01
    相关资源
    最近更新 更多