From 45bcf4e754ec8abb734c65a467001b3e1592b2e5 Mon Sep 17 00:00:00 2001 From: marius Date: Sat, 6 May 2023 17:10:01 +0000 Subject: [PATCH] enabled hypertables, from pg to timescale --- timescaledb/enable_hypertables.txt | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 timescaledb/enable_hypertables.txt diff --git a/timescaledb/enable_hypertables.txt b/timescaledb/enable_hypertables.txt new file mode 100644 index 0000000..13b8e9c --- /dev/null +++ b/timescaledb/enable_hypertables.txt @@ -0,0 +1,53 @@ +postgres@loglab:/etc/postgresql/14/main$ psql +psql (15.2 (Ubuntu 15.2-1.pgdg20.04+1), server 14.7 (Ubuntu 14.7-1.pgdg20.04+1)) +Type "help" for help. + +postgres=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE; +NOTICE: extension "timescaledb" already exists, skipping +CREATE EXTENSION +postgres=# SELECT extname FROM pg_extension WHERE extname = 'timescaledb'; + extname +------------- + timescaledb +(1 row) + +postgres=# SELECT create_hypertable('logs', 'timestamp'); +ERROR: cannot create a unique index without the column "timestamp" (used in partitioning) +postgres=# SELECT +postgres-# i.relname AS index_name, +postgres-# a.attname AS column_name +postgres-# FROM +postgres-# pg_class t, +postgres-# pg_class i, +postgres-# pg_index ix, +postgres-# pg_attribute a +postgres-# WHERE +postgres-# t.oid = ix.indrelid +postgres-# AND i.oid = ix.indexrelid +postgres-# AND a.attrelid = t.oid +postgres-# AND a.attnum = ANY(ix.indkey) +postgres-# AND t.relkind = 'r' +postgres-# AND t.relname = 'logs' +postgres-# AND ix.indisunique IS TRUE; + index_name | column_name +------------+------------- + logs_pkey | id +(1 row) + +postgres=# ALTER TABLE logs DROP CONSTRAINT logs_pkey; +ALTER TABLE +postgres=# CREATE UNIQUE INDEX logs_unique_id_timestamp ON logs (id, timestamp); +CREATE INDEX +postgres=# SELECT create_hypertable('logs', 'timestamp'); + create_hypertable +------------------- + (3,public,logs,t) +(1 row) + +postgres=# SELECT extname FROM pg_extension WHERE extname = 'timescaledb'; + extname +------------- + timescaledb +(1 row) + +postgres=# \q \ No newline at end of file