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
  • Select an option

  • Save vishaltelangre/b5aba6a9d4731db58d521e01904068ef to your computer and use it in GitHub Desktop.

Select an option

Save vishaltelangre/b5aba6a9d4731db58d521e01904068ef to your computer and use it in GitHub Desktop.

Revisions

  1. @marchelbling marchelbling revised this gist Aug 26, 2018. 5 changed files with 49 additions and 11 deletions.
    19 changes: 10 additions & 9 deletions 100-local-citus.sql
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,10 @@
    -- user:
    CREATE ROLE citus WITH NOSUPERUSER LOGIN IN ROLE pg_monitor;

    -- database:
    ALTER DATABASE citus OWNER TO citus;

    -- extensions:
    CREATE EXTENSION IF NOT EXISTS "hll";
    CREATE EXTENSION IF NOT EXISTS "topn";
    -- 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";
    3 changes: 3 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    FROM citusdata/citus:7.5.0

    COPY 100-local-citus.sql /docker-entrypoint-initdb.d/
    2 changes: 0 additions & 2 deletions Dockerfile.md
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    FROM citusdata/citus:7.5.0
    COPY 100-local-citus.sql /docker-entrypoint-initdb.d/
    13 changes: 13 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    # 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](http://marc.helbling.fr/running-citus-locally/) for details and another [gist](https://gist.github.com/marchelbling/8a0b47e82d0993c8a5a4726611d5ccfd) for a worse approach!

    ## Build

    `docker build -t local-citus:latest .`

    ## Run

    `docker-compose -p citus up --scale worker=2 -d`
    23 changes: 23 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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
  2. @marchelbling marchelbling created this gist Aug 26, 2018.
    9 changes: 9 additions & 0 deletions 100-local-citus.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    -- user:
    CREATE ROLE citus WITH NOSUPERUSER LOGIN IN ROLE pg_monitor;

    -- database:
    ALTER DATABASE citus OWNER TO citus;

    -- extensions:
    CREATE EXTENSION IF NOT EXISTS "hll";
    CREATE EXTENSION IF NOT EXISTS "topn";
    2 changes: 2 additions & 0 deletions Dockerfile.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    FROM citusdata/citus:7.5.0
    COPY 100-local-citus.sql /docker-entrypoint-initdb.d/