Skip to content

Instantly share code, notes, and snippets.

@vishaltelangre
Forked from marchelbling/100-local-citus.sql
Created August 9, 2020 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishaltelangre/b5aba6a9d4731db58d521e01904068ef to your computer and use it in GitHub Desktop.
Save vishaltelangre/b5aba6a9d4731db58d521e01904068ef 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