# Redash Query & Visualization

> Connect to any data source, query, visualize, and share your data.

- Category: Monitoring & Observability
- Difficulty: intermediate
- Components: redash, postgresql, redis, nginx
- Tags: redash, sql, visualization, dashboards, analytics
- Source: https://docker.recipes/monitoring/redash-analytics

## Overview

Redash is an open-source business intelligence and data visualization platform that enables organizations to connect to multiple data sources, write SQL queries, create visualizations, and build interactive dashboards. Originally developed by Arik Fraimovich and later acquired by Databricks, Redash democratizes data access by providing a web-based interface that allows both technical and non-technical users to explore data through SQL queries and share insights through compelling visualizations. Its strength lies in supporting dozens of data sources including PostgreSQL, MySQL, BigQuery, Redshift, Elasticsearch, and APIs, making it a versatile choice for organizations with diverse data infrastructure.

This Docker stack combines Redash with PostgreSQL as the metadata database, Redis for caching and job queue management, and a multi-service architecture that includes separate containers for the web application, scheduler, and worker processes. PostgreSQL stores Redash's internal data including user accounts, query definitions, dashboard configurations, and cached query results, while Redis handles the distributed task queue system that powers Redash's background query execution and scheduled refresh capabilities. The scheduler service manages automated query runs and dashboard refreshes, while worker containers execute queries against your connected data sources in parallel, preventing long-running queries from blocking the web interface.

This configuration is ideal for data teams, business analysts, and organizations seeking to establish a centralized analytics platform without the complexity and cost of enterprise BI solutions like Tableau or Looker. The stack provides production-grade capabilities including user management, query scheduling, alert systems, and API access, making it suitable for teams ranging from startups building their first data culture to enterprises consolidating multiple reporting tools into a unified platform.

## Features

- Multi-data source connectivity supporting 40+ databases and APIs including PostgreSQL, MySQL, BigQuery, Redshift, Elasticsearch, and MongoDB
- Distributed query execution with Redis-backed job queues allowing parallel processing of multiple queries without blocking the web interface
- Automated query scheduling with configurable refresh intervals for keeping dashboards current with live data
- Interactive visualization library with chart types including line graphs, bar charts, pivot tables, cohort analysis, and geographic maps
- User permission system with organization-level access control, query sharing, and dashboard publication workflows
- Query result caching in PostgreSQL reducing load on source databases and improving dashboard loading times
- Alert system with threshold-based notifications via email, Slack, webhooks, and other integrations when query results meet specified conditions
- REST API for programmatic access to queries, dashboards, and data sources enabling custom integrations and automated workflows

## Use cases

- Startup analytics platform for tracking KPIs across multiple SaaS tools and databases without expensive BI software licensing
- E-commerce business intelligence combining sales data from PostgreSQL, marketing metrics from APIs, and inventory data from MySQL
- DevOps monitoring dashboards connecting to Elasticsearch logs, application databases, and infrastructure APIs for operational visibility
- Financial reporting system aggregating data from accounting software APIs, payment processors, and internal transaction databases
- Customer success analytics combining CRM data, product usage metrics, and support ticket information for churn prediction
- Marketing campaign analysis integrating Google Analytics, social media APIs, email marketing platforms, and conversion tracking databases
- Executive reporting platform providing scheduled dashboard delivery and automated alerts for key business metrics across departments

## Prerequisites

- Minimum 2GB RAM for the complete stack (512MB for Redash services, 1GB for PostgreSQL, 256MB for Redis, 256MB for system overhead)
- Available ports 5000 for Redash web interface access from external clients
- Basic SQL knowledge for writing queries against your data sources, as Redash is query-centric rather than drag-and-drop
- Administrative access to target data sources including database credentials, API keys, and network connectivity for Redash to connect
- Understanding of environment variable configuration for database credentials, secret keys, and Redis connection strings
- Docker Compose 2.0+ with support for health check conditions and multi-service dependencies

## docker-compose.yml

```yaml
services:
  redash:
    image: redash/redash:latest
    ports:
      - "5000:5000"
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: INFO
      REDASH_REDIS_URL: redis://redis:6379/0
      REDASH_DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      REDASH_COOKIE_SECRET: ${COOKIE_SECRET}
      REDASH_SECRET_KEY: ${SECRET_KEY}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - redash-net
    restart: unless-stopped

  redash-scheduler:
    image: redash/redash:latest
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: INFO
      REDASH_REDIS_URL: redis://redis:6379/0
      REDASH_DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      REDASH_COOKIE_SECRET: ${COOKIE_SECRET}
      REDASH_SECRET_KEY: ${SECRET_KEY}
      QUEUES: "celery"
      WORKERS_COUNT: 1
    command: scheduler
    depends_on:
      - redash
    networks:
      - redash-net
    restart: unless-stopped

  redash-worker:
    image: redash/redash:latest
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: INFO
      REDASH_REDIS_URL: redis://redis:6379/0
      REDASH_DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      REDASH_COOKIE_SECRET: ${COOKIE_SECRET}
      REDASH_SECRET_KEY: ${SECRET_KEY}
      QUEUES: "queries,scheduled_queries,celery"
      WORKERS_COUNT: 2
    command: worker
    depends_on:
      - redash
    networks:
      - redash-net
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - redash-net
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - redash-net
    restart: unless-stopped

volumes:
  postgres_data:
  redis_data:

networks:
  redash-net:
    driver: bridge
```

## .env

```bash
# Redash Secrets
COOKIE_SECRET=$(openssl rand -hex 32)
SECRET_KEY=$(openssl rand -hex 32)

# PostgreSQL
POSTGRES_USER=redash
POSTGRES_PASSWORD=secure_postgres_password
POSTGRES_DB=redash
```

## Usage notes

- Redash at http://localhost:5000
- Create database: docker compose run --rm redash create_db
- Connect to any SQL database or API
- Build dashboards from saved queries

## Troubleshooting

- Redash web interface shows 'Internal Server Error': Check PostgreSQL connection by verifying REDASH_DATABASE_URL environment variable and ensure postgres container is healthy with pg_isready
- Queries never complete or show perpetual 'Running' status: Restart redash-worker container and check Redis connectivity, as worker processes handle query execution through Redis job queues
- Dashboard refresh fails with 'Scheduled query failed': Check redash-scheduler container logs and verify data source connectivity from within the Docker network
- High memory usage in PostgreSQL container: Tune shared_buffers and work_mem settings, or increase query result cache TTL to reduce frequent large query re-execution
- Redis connection errors in Redash logs: Verify REDASH_REDIS_URL format matches 'redis://redis:6379/0' and ensure redis container is accessible on redash-net network
- Permission denied when connecting to external data sources: Ensure data source allows connections from Docker container IP ranges and verify firewall rules for outbound database connections

