恐慌:无法连接:拨号TCP X.X.X.X:5432:连接:连接被拒绝

huangapple go评论83阅读模式
英文:

Panic : Could not connect : Dial TCP X.X.X.X:5432 : Connect : Connection refused

问题

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

/usr/local/bin/docker-entrypoint.sh: running
/docker-entrypoint-initdb.d/import_data.sh timescaledb | panic: could
not connect: dial tcp 172.18.0.2:5432: connect: connection refused
timescaledb | timescaledb | goroutine 6 [running]: timescaledb |
main.processBatches(0xc000016730, 0xc000060780) timescaledb |
/go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:238
+0x8bb timescaledb | created by main.main timescaledb | /go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:148
+0x1d2 timescaledb | panic: could not connect: dial tcp 172.18.0.2:5432: connect: connection refused

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

Docker Compose:

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,但是我得到了相同的错误。

英文:

I'm trying to install TimeScaleDB using Docker Compose, but I get the following error when importing data using timescaledb-parallel-copy :

> /usr/local/bin/docker-entrypoint.sh: running
> /docker-entrypoint-initdb.d/import_data.sh timescaledb | panic: could
> not connect: dial tcp 172.18.0.2:5432: connect: connection refused
> timescaledb | timescaledb | goroutine 6 [running]: timescaledb |
> main.processBatches(0xc000016730, 0xc000060780) timescaledb |
> /go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:238
> +0x8bb timescaledb | created by main.main timescaledb | /go/src/github.com/timescale/timescaledb-parallel-copy/cmd/timescaledb-parallel-copy/main.go:148
> +0x1d2 timescaledb | panic: could not connect: dial tcp 172.18.0.2:5432: connect: connection refused

Here's my docker compose and my docker file :

Docker compose :

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 file :

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/*

And here's the import_data.sh script that calls timescaledb-parallel-copy :

#!/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

I also tried using localhost, but I get the same error.

答案1

得分: 0

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

> 此外,根据docker-library/postgres#440的说明,为这些初始化脚本启动的临时守护程序仅侦听Unix套接字,因此任何psql使用都应删除主机名部分(例如,请参阅docker-library/postgres#474(评论))。

英文:

Edit : Problem solved. The host should not be specified in the connection string. According to the official documentation (https://hub.docker.com/_/postgres) :

> Also, as of docker-library/postgres#440, the temporary daemon started for these initialization scripts listens only on the Unix socket, so any psql usage should drop the hostname portion (see docker-library/postgres#474 (comment) for example).

huangapple
  • 本文由 发表于 2022年1月10日 18:27:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/70650923.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定