A guide to installing TimescaleDB for financial data on an Ubuntu server. TimescaleDB official docs: https://docs.timescale.com/
This guide was created using Ubuntu 20.04 LTS and PostgreSQL 14
Fresh Install
If you want to install postgres by combining multiple drives into a logical volume (useful for cloud block storage, or large local database), please skip to the If using Block Storage (AWS / Digital Ocean / Etc) section. If you are installing locally, using a single drive, continue below:
Install PostgreSQL-14
Update apt, find latest version of Postgres and install
There are a variety of settings that can be configured for your new database. At a minimum, you need to update your postgresql.conf file to include shared_preload_libraries = 'timescaledb'. The easiest way to get started is to run timescaledb-tune, which is installed by default when using apt:
Create a new hypertable with the same index and structure of an existing Postgres table, copy over the data, and set a compression policy:
CREATETABLEnew_table (LIKE old_table INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES);-- Assuming 'time' is the time column for the datasetSELECT create_hypertable('new_table', 'time');-- If there's an error on 'create_hypertable' run the following two statements, otherwise skip this step:-- CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;-- SELECT create_hypertable('new_table', 'time');-- Insert everything from old_tableINSERT INTO new_table SELECT*FROM old_table;-- Add compression, segmented by symbol/tickerALTERTABLE new_table SET ( timescaledb.compress, timescaledb.compress_segmentby ='symbol');-- Add automatic compression at a custom interval:SELECT add_compression_policy('new_table', INTERVAL '7 days');-- More information on compression here: https://docs.timescale.com/timescaledb/latest/how-to-guides/compression/