Skip to content

Instantly share code, notes, and snippets.

@marchelbling
Last active July 5, 2023 15:47
Show Gist options
  • Save marchelbling/1ef4ae74c3d5bd745a04f7b8ae375f8a to your computer and use it in GitHub Desktop.
Save marchelbling/1ef4ae74c3d5bd745a04f7b8ae375f8a to your computer and use it in GitHub Desktop.
Local Citus cluster setup — bis
-- user:
CREATE ROLE citus WITH NOSUPERUSER LOGIN IN ROLE pg_monitor;
-- database:
ALTER DATABASE citus SET citus.shard_replication_factor = 1;
ALTER DATABASE citus OWNER TO citus;
-- extensions:
CREATE EXTENSION IF NOT EXISTS "hll";
CREATE EXTENSION IF NOT EXISTS "topn";

Why this gist?

This gist propose a clean way to run a local Citus cluster. A custom database called citus is created when containers are created and /docker-entrypoint-initdb.d/ hooks allow to create a custom role, change citus database ownership and install any needed extension.

View Running Citus in Docker for details and another gist for a worse approach!

Build

docker build -t local-citus:latest .

Run

docker-compose -p citus up --scale worker=2 -d

version: '2.1'
services:
master:
container_name: "${COMPOSE_PROJECT_NAME:-citus}_master"
image: 'local-citus:latest'
ports: ["${MASTER_EXTERNAL_PORT:-5432}:5432"]
labels: ['com.citusdata.role=Master']
environment:
- POSTGRES_DB=citus
worker:
image: 'local-citus:latest'
labels: ['com.citusdata.role=Worker']
depends_on: { manager: { condition: service_healthy } }
environment:
- POSTGRES_DB=citus
manager:
container_name: "${COMPOSE_PROJECT_NAME:-citus}_manager"
image: 'citusdata/membership-manager:0.2.0'
volumes: ['/var/run/docker.sock:/var/run/docker.sock']
depends_on: { master: { condition: service_healthy } }
environment:
- POSTGRES_DB=citus
FROM citusdata/citus:7.5.0
COPY 100-local-citus.sql /docker-entrypoint-initdb.d/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment