3

I am trying to connect to a local postgres from Redash. (both from redash.io and http://0.0.0.0:5000/) but cannot connect to it. an other tools i can connect localhost, but from Redash i getting error:

 Connection Test Failed:
 could not connect to server: Connection refused Is the server running 
 on host "localhost" (::1) and accepting TCP/IP connections on port 
 5432? could not connect to server: Connection refused Is the server 
 running on host "localhost" (127.0.0.1) and accepting TCP/IP 
 connections on port 5432?

Any ideas what can be the problem? I am using docker for my local Redash, which can cause the issue, but i am getting the same error from redash.io as well.

Here is my docker-compose file:

# This configuration file is for **development** setup. For production, refer to
# docker-compose.production.yml.
version: '2'
services:
  server:
    build: .
    command: dev_server
    depends_on:
      - postgres
      - redis
    ports:
      - "5000:5000"
    volumes:
      - ".:/app"
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: "INFO"
      REDASH_REDIS_URL: "redis://redis:6379/0"
      REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
  worker:
    build: .
    command: scheduler
    volumes_from:
      - server
    depends_on:
      - server
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: "INFO"
      REDASH_REDIS_URL: "redis://redis:6379/0"
      REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
      QUEUES: "queries,scheduled_queries,celery"
      WORKERS_COUNT: 2
  redis:
    image: redis:3.0-alpine
    restart: unless-stopped
  postgres:
    image: postgres:9.5.6-alpine
    # The following turns the DB into less durable, but gains significant performance improvements for the tests run (x3
    # improvement on my personal machine). We should consider moving this into a dedicated Docker Compose configuration for
    # tests.
    command: "postgres -c fsync=off -c full_page_writes=off -c synchronous_commit=OFF"
    restart: unless-stopped

You can see the whole project in this repo. thanks.

Alejandro Nortes
  • 594
  • 5
  • 17
clairvoyant
  • 195
  • 1
  • 11
  • Is postgres running on docker? Could you show how do you create docker container? Send dockerfiles or docker-compose and show how do you run it. – Alejandro Nortes Aug 27 '18 at 18:23
  • https://gist.github.com/deepak365/3316270abce892370414bee232f31551 i followed the instructions from here. i have a separate postgres locally not in docker (although redash also created some postgres image) – clairvoyant Aug 27 '18 at 18:26
  • images: REPOSITORY TAG IMAGE ID CREATED SIZE redash/redash latest bec561ff0cc0 3 months ago 1.07GB redis 3.0-alpine 856249f48b0c 14 months ago 12.6MB postgres 9.5.6-alpine cc38b642ca58 15 months ago 36.9MB redash/nginx latest 76abf32984e9 2 years ago 134MB – clairvoyant Aug 27 '18 at 18:28
  • hard to see 4 images altogether: redash/redash, redis, docker, redash/nginx – clairvoyant Aug 27 '18 at 18:29
  • If you've redash running in a docker container, and your postgres database in your computer. Redash is not able to connect postgres using 'localhost', because 'localhost' is to docker container, not to your computer. You should point your local IP instead of localhost, or use a docker container for postgresql. Take a look this similar question: https://stackoverflow.com/questions/51849404/connecting-to-localhost-or-127-0-0-1-with-a-docker-docker-compose-setup/51849522#51849522 – Alejandro Nortes Aug 27 '18 at 19:17
  • i have already tried that: Connection Test Failed: could not send SSL negotiation packet: Resource temporarily unavailable – clairvoyant Aug 27 '18 at 19:34
  • maybe i need to open some port on docker? I thought it is nothing to do with docker since i also tried it on redash.io. – clairvoyant Aug 27 '18 at 19:35
  • I just saw docker-compose in redash repo, and it has its own postgresql database. Why don't you use it? – Alejandro Nortes Aug 28 '18 at 09:39
  • Seein docker-compose, in container "server", I saw this environment variable: REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres" You should change this variable in order to point your local postgresql and the URL you provide should be reachable. – Alejandro Nortes Aug 28 '18 at 09:42

1 Answers1

10

Changed localhost to host.docker.internal to make it work.

Ashwin Yaprala
  • 2,737
  • 2
  • 24
  • 56
clairvoyant
  • 195
  • 1
  • 11