Resolving PostgreSQL Authentication Errors in Docker Compose for Redash
Introduction
When setting up Redash with Docker Compose, one of the common errors users might encounter is related to PostgreSQL authentication. Specifically, the psycopg2.OperationalError: fe_sendauth: no password supplied error can be frustrating, especially when you believe everything is configured correctly. This post will guide you through understanding and resolving this error.
Understanding the Error
The fe_sendauth: no password supplied error indicates that PostgreSQL is expecting a password for the connection, but none was provided. This can happen due to misconfigurations in your environment variables, Docker Compose file, or the way the create_db command is executed.
Common Setup
Typically, the Docker Compose setup for Redash might look something like this:
version: "2"
x-redash-service: &redash-service
image: redash/redash:8.0.0.b32245
depends_on:
- postgres
- redis
env_file: /opt/redash/env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "5000:5000"
environment:
REDASH_WEB_WORKERS: 4
scheduler:
<<: *redash-service
command: scheduler
environment:
QUEUES: "celery"
WORKERS_COUNT: 1
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 1
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: unless-stopped
postgres:
image: pgautoupgrade/pgautoupgrade:15-alpine3.8
env_file: /opt/redash/env
volumes:
- /opt/redash/postgres-data:/var/lib/postgresql/data
restart: unless-stopped
nginx:
image: redash/nginx:latest
ports:
- "80:80"
depends_on:
- server
links:
- server:redash
restart: always
And the env file might look like this:
REDASH_HOST=http://localhost/redash
PYTHONUNBUFFERED=0
REDASH_LOG_LEVEL=INFO
REDASH_REDIS_URL=redis://redis:6379/0
POSTGRES_PASSWORD=postgres
REDASH_COOKIE_SECRET=redash-selfhosted
REDASH_SECRET_KEY=redash-selfhosted
REDASH_DATABASE_URL=postgresql://postgres@postgres/postgres
Encountering the Error
When you try to initialize the Redash database with the following command:
docker-compose run --rm server create_db
You might encounter the fe_sendauth: no password supplied error. This indicates that the POSTGRES_PASSWORD environment variable isn’t being correctly used by the create_db command.
Solution
To resolve this issue, you can pass the POSTGRES_PASSWORD directly when running the create_db command. Here’s how:
- Remove the
env_fileReference: Ensure that theenv_filereference in yourdocker-compose.ymlfile for theserverservice is removed or overridden, so it doesn’t interfere. - Run the Command with Password: Use the
-eoption to explicitly pass thePOSTGRES_PASSWORDas an environment variable:
docker-compose run --rm -e POSTGRES_PASSWORD=postgres server create_db
- Replace
postgreswith the actual password if it’s different.
Conclusion
By passing the POSTGRES_PASSWORD directly in the docker-compose run command, you ensure that the correct password is used for PostgreSQL authentication. This method is effective in resolving the fe_sendauth: no password supplied error and allows you to proceed with setting up Redash successfully.