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

Time:01-12

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.

CodePudding user response:

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).

  •  Tags:  
  • Related