Skip to main content

Module tsdb

Module tsdb 

Source
Expand description

TimescaleDB

§docker

services:
  service_timescaledb:
    command: postgres
      -c config_file=/etc/postgresql/postgresql.conf
      -c hba_file=/etc/postgresql/pg_hba.conf
    container_name: service_timescaledb
    healthcheck:
      test: pg_isready -d db_data
      interval: 30s
      timeout: 60s
      retries: 5
      start_period: 80s
    hostname: service_timescaledb
    image: timescale/timescaledb:2.23.0-pg18 # https://hub.docker.com/r/timescale/timescaledb/tags
    networks:
      - network_internal
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - "5432:5432"
    profiles:
      - dev
      - target
    user: postgres
    volumes:
      - ./timescaledb/postgresql.conf:/etc/postgresql/postgresql.conf
      - ./timescaledb/pg_hba.conf:/etc/postgresql/pg_hba.conf
      - ./timescaledb/init.sql:/docker-entrypoint-initdb.d/init.sql
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - timescaledb_volume:/var/lib/postgresql/data

networks:
  network_internal:

volumes:
  timescaledb_volume:
    name: timescaledb_volume

§postgresql.conf

listen_addresses = '*'
shared_preload_libraries = 'timescaledb'

max_connections = 200

max_wal_size = 2GB

timescaledb.max_background_workers = 100

max_worker_processes = 116

max_parallel_workers = 16

log_min_error_statement = PANIC

§pg_hba.conf

local all all trust
host all all 0.0.0.0/0 trust

§init.sql

CREATE DATABASE db_data;

\c db_data
CREATE EXTENSION IF NOT EXISTS timescaledb;

-- -- table raw
-- CREATE TABLE raw (
--     time        TIMESTAMPTZ         NOT NULL,
--     prj         TEXT                NOT NULL,
--     hst         TEXT                NOT NULL,
--     svc         TEXT                NOT NULL,
--     cmp         TEXT                NOT NULL,
--     key         TEXT                NOT NULL,
--     value       DOUBLE PRECISION    NULL,
--     UNIQUE (time, prj, hst, svc, cmp, key)
-- ) WITH (
--    tsdb.hypertable,
--    tsdb.partition_column = 'time',
--    tsdb.chunk_interval = 'PT1M',
--    tsdb.segmentby = 'prj, hst, svc, cmp, key',
--    tsdb.orderby = 'time ASC'
-- );

-- CALL remove_columnstore_policy('raw');
-- CALL add_columnstore_policy('raw', after => INTERVAL 'PT10M');