At version 2 (in beta, no production recommended), timescale will had a new functionality that distribute hypertables over different data nodes chunks. This repository contains all you need to setup this using docker locally at your machine.
- Docker
- docker-compose
- Clone this repo to your machine
git clone https://github.com/jairsjunior/timescaledb-cluster
- Run the docker-compose file using this command
docker-compose up -d
- The access node will be avaliable at this address
localhost:5432
Using your favorite timescale/postgres client
- Check if your data nodes are registered using the command below. If everything is okay you will receive a response with the number of data nodes that you created. (default docker-compose.yml file creates 3 nodes)
SELECT * FROM timescaledb_information.data_node;
- Create a new table
CREATE TABLE state (time TIMESTAMPTZ NOT NULL, owner CHARACTER VARYING(100) NOT NULL, thing CHARACTER VARYING(100) NOT NULL, node CHARACTER VARYING(100) NOT NULL, tags JSONB, fields JSONB, CONSTRAINT state_pk PRIMARY KEY (time, owner, thing, node));
- Setup this table as a distributed hypertable (partitioned along time and owner)
SELECT create_distributed_hypertable('state', 'time', 'owner');
- If everything goes right, you know have a distributed hypertable over your data nodes.
- At
docker-compose.yml
file add this lines below
pg-data-node-4:
image: timescaledev/timescaledb:pg12-ts2.0.0-beta5
hostname: pg-data-node-4
environment:
- POSTGRES_USER=user-name
- POSTGRES_PASSWORD=dataNodePass
## Acess Node Configuration for node register
- POSTGRES_HOST_ACCESS_NODE=pg-access-node
- POSTGRES_DB_ACCESS_NODE=db-name
- POSTGRES_PASSWORD_ACCESS_NODE=accessNodePass
volumes:
- ./updateConfigDataNode.sh:/docker-entrypoint-initdb.d/_updateConfig.sh
- ./docker-entrypoint-listen.sh:/docker-entrypoint.sh
- Run the docker-compose up command to create/update your existing containers.
docker-compose up -d
- When the data node starts, it register yourself as a new data node in the cluster.
- In a few second the new node are ready to receive data.
- Using your favorite timescale/postgres client
- Run the command below to add a new node to your distributed hypertable passing the new node hostname as
NEW_NODE_HOSTNAME
and the hypertable name asHYPERTABLE_NAME
SELECT attach_data_node('${NEW_NODE_HOSTNAME}', hypertable => '${HYPERTABLE_NAME}');
Eg.
SELECT attach_data_node('pg-data-node-4', hypertable => 'state');