Refactor and harden size and stats functions

Fix a number of issues with size and stats functions:

* Return `0` size instead of `NULL` in several functions when
  hypertables have no chunks (e.g., `hypertable_size`,
  `hypertable_detailed_size`).
* Return `NULL` when functions are called on non-hypertables instead
  of simply failing with generic error `query returned no rows`.
* Include size of "root" hypertable, which can have non-zero size
  indexes and other objects even if the root table holds no data.
* Make `hypertable_detailed_size` include one additional row for
  storage size of objects on the access node. While the access node
  stores no data, the empty hypertable may still take up some disk
  space.
* Improve test coverage for all size utility functions. In particular,
  add tests on regular tables as well as empty and compressed
  hypertables.
* Several size utility functions that were defined as `PL/pgSQL`
  functions have been converted to simple `SQL` functions since they
  ran only a single SQL query.

The `dist_util` test is moved to the solo test group because,
otherwise, it gives different size output when run in parallel vs. in
isolation.

Fixes #2871
This commit is contained in:
Erik Nordström 2021-02-25 17:07:19 +01:00 committed by Erik Nordström
parent 8553323b5e
commit 931da9a656
17 changed files with 1249 additions and 262 deletions

View File

@ -8,10 +8,13 @@ accidentally triggering the load of a previous DB version.**
**Bugfixes**
* #2974 Fix index creation for hypertables with dropped columns
* #2989 Refactor and harden size and stats functions
* #3042 Commit end transaction for CREATE INDEX
**Thanks**
* @jocrau for reporting an issue with index creation
* @pedrokost and @RobAtticus for reporting an issue with size
functions on empty hypertables
## 2.1.0 (2021-02-22)

View File

@ -27,7 +27,8 @@ set(SOURCE_FILES
pre_install/fdw_functions.sql
hypertable.sql
chunk.sql
ddl_internal.sql
data_node.sql
ddl_internal.sql
util_time.sql
util_internal_table_ddl.sql
chunk_constraint.sql
@ -44,7 +45,6 @@ set(SOURCE_FILES
cache.sql
bgw_scheduler.sql
metadata.sql
data_node.sql
dist_internal.sql
views.sql
gapfill.sql

View File

@ -7,8 +7,8 @@
CREATE OR REPLACE VIEW _timescaledb_internal.hypertable_chunk_local_size AS
SELECT
h.schema_name,
h.table_name,
h.schema_name AS hypertable_schema,
h.table_name AS hypertable_name,
h.id as hypertable_id,
c.id as chunk_id,
c.schema_name as chunk_schema,
@ -67,46 +67,25 @@ RETURNS TABLE (
AS '@MODULE_PATHNAME@', 'ts_dist_remote_chunk_info' LANGUAGE C VOLATILE STRICT;
CREATE OR REPLACE FUNCTION _timescaledb_internal.hypertable_local_size(
schema_name_in name,
table_name_in name)
schema_name_in name,
table_name_in name)
RETURNS TABLE (
table_bytes bigint,
index_bytes bigint,
toast_bytes bigint,
total_bytes bigint)
LANGUAGE PLPGSQL VOLATILE STRICT AS
table_bytes bigint,
index_bytes bigint,
toast_bytes bigint,
total_bytes bigint)
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
BEGIN
RETURN QUERY
SELECT
(sub2.table_bytes + sub2.compressed_heap_bytes)::bigint as heap_bytes,
(sub2.index_bytes + sub2.compressed_index_bytes)::bigint as index_bytes,
(sub2.toast_bytes + sub2.compressed_toast_bytes)::bigint as toast_bytes,
(sub2.total_bytes + sub2.compressed_heap_bytes + sub2.compressed_index_bytes + sub2.compressed_toast_bytes)::bigint as total_bytes
FROM
(
SELECT
*,
sub1.total_bytes - sub1.index_bytes - sub1.toast_bytes AS table_bytes
FROM
(
SELECT
sum(ch.total_bytes) as total_bytes,
COALESCE( sum(ch.index_bytes) , 0 ) as index_bytes,
COALESCE( sum(ch.toast_bytes), 0 ) as toast_bytes,
COALESCE( sum(ch.compressed_heap_size) , 0 ) as compressed_heap_bytes,
COALESCE( sum(ch.compressed_index_size) , 0) as compressed_index_bytes,
COALESCE( sum(ch.compressed_toast_size) , 0 ) as compressed_toast_bytes
FROM
_timescaledb_internal.hypertable_chunk_local_size ch
WHERE
schema_name = schema_name_in
AND table_name = table_name_in
GROUP BY
hypertable_id
) sub1
) sub2;
END;
SELECT
(COALESCE(sum(ch.total_bytes), 0) - COALESCE(sum(ch.index_bytes), 0) - COALESCE(sum(ch.toast_bytes), 0) + COALESCE(sum(ch.compressed_heap_size), 0))::bigint + pg_relation_size(format('%I.%I', schema_name_in, table_name_in)::regclass)::bigint AS heap_bytes,
(COALESCE(sum(ch.index_bytes), 0) + COALESCE(sum(ch.compressed_index_size), 0))::bigint + pg_indexes_size(format('%I.%I', schema_name_in, table_name_in)::regclass)::bigint AS index_bytes,
(COALESCE(sum(ch.toast_bytes), 0) + COALESCE(sum(ch.compressed_toast_size), 0))::bigint AS toast_bytes,
(COALESCE(sum(ch.total_bytes), 0) + COALESCE(sum(ch.compressed_heap_size), 0) + COALESCE(sum(ch.compressed_index_size), 0) + COALESCE(sum(ch.compressed_toast_size), 0))::bigint + pg_total_relation_size(format('%I.%I', schema_name_in, table_name_in)::regclass)::bigint AS total_bytes
FROM
_timescaledb_internal.hypertable_chunk_local_size ch
WHERE
hypertable_schema = schema_name_in
AND hypertable_name = table_name_in
$BODY$;
CREATE OR REPLACE FUNCTION _timescaledb_internal.hypertable_remote_size(
@ -118,10 +97,8 @@ RETURNS TABLE (
toast_bytes bigint,
total_bytes bigint,
node_name NAME)
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
BEGIN
RETURN QUERY
SELECT
sum(entry.table_bytes)::bigint AS table_bytes,
sum(entry.index_bytes)::bigint AS index_bytes,
@ -147,7 +124,6 @@ BEGIN
NULL
END, schema_name_in, table_name_in) entry ON TRUE
GROUP BY srv.node_name;
END;
$BODY$;
-- Get relation size of hypertable
@ -162,50 +138,55 @@ $BODY$;
-- total_bytes - Total disk space used by the specified table, including all indexes and TOAST data
CREATE OR REPLACE FUNCTION hypertable_detailed_size(
hypertable REGCLASS
)
hypertable REGCLASS)
RETURNS TABLE (table_bytes BIGINT,
index_bytes BIGINT,
toast_bytes BIGINT,
total_bytes BIGINT,
node_name NAME
)
node_name NAME)
LANGUAGE PLPGSQL VOLATILE STRICT AS
$BODY$
DECLARE
table_name NAME;
schema_name NAME;
is_distributed BOOL;
table_name NAME = NULL;
schema_name NAME = NULL;
is_distributed BOOL = FALSE;
BEGIN
SELECT relname, nspname, replication_factor > 0
INTO STRICT table_name, schema_name, is_distributed
INTO table_name, schema_name, is_distributed
FROM pg_class c
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname AND ht.table_name = c.relname)
WHERE c.OID = hypertable;
IF table_name IS NULL THEN
RETURN;
END IF;
CASE WHEN is_distributed THEN
RETURN QUERY SELECT * FROM _timescaledb_internal.hypertable_remote_size(schema_name, table_name);
RETURN QUERY
SELECT *, NULL::name
FROM _timescaledb_internal.hypertable_local_size(schema_name, table_name)
UNION
SELECT *
FROM _timescaledb_internal.hypertable_remote_size(schema_name, table_name);
ELSE
RETURN QUERY SELECT *, NULL::name FROM _timescaledb_internal.hypertable_local_size(schema_name, table_name);
RETURN QUERY
SELECT *, NULL::name
FROM _timescaledb_internal.hypertable_local_size(schema_name, table_name);
END CASE;
END;
$BODY$;
--- returns total-bytes for a hypertable (includes table + index)
CREATE OR REPLACE FUNCTION hypertable_size(
hypertable REGCLASS
)
hypertable REGCLASS)
RETURNS BIGINT
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
DECLARE
num_bytes BIGINT;
BEGIN
SELECT sum(hd.total_bytes) INTO STRICT num_bytes
FROM hypertable_detailed_size(hypertable) hd;
RETURN num_bytes;
END;
-- One row per data node is returned (in case of a distributed
-- hypertable), so sum them up:
SELECT sum(total_bytes)::bigint
FROM hypertable_detailed_size(hypertable);
$BODY$;
CREATE OR REPLACE FUNCTION _timescaledb_internal.chunks_local_size(
@ -219,10 +200,8 @@ RETURNS TABLE (
index_bytes bigint,
toast_bytes bigint,
total_bytes bigint)
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
BEGIN
RETURN QUERY
SELECT
ch.chunk_id,
ch.chunk_schema,
@ -232,12 +211,10 @@ BEGIN
(COALESCE( ch.toast_bytes, 0 ) + COALESCE( ch.compressed_toast_size, 0 ))::bigint as toast_bytes,
(ch.total_bytes + COALESCE( ch.compressed_heap_size, 0 ) + COALESCE( ch.compressed_index_size, 0) + COALESCE( ch.compressed_toast_size, 0 ))::bigint as total_bytes
FROM
_timescaledb_internal.hypertable_chunk_local_size ch
_timescaledb_internal.hypertable_chunk_local_size ch
WHERE
ch.schema_name = schema_name_in
AND ch.table_name = table_name_in
;
END;
ch.hypertable_schema = schema_name_in
AND ch.hypertable_name = table_name_in;
$BODY$;
---should return same information as chunks_local_size--
@ -253,10 +230,8 @@ RETURNS TABLE (
toast_bytes bigint,
total_bytes bigint,
node_name NAME)
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
BEGIN
RETURN QUERY
SELECT
entry.chunk_id,
entry.chunk_schema,
@ -283,8 +258,9 @@ BEGIN
srv.node_name
ELSE
NULL
END , schema_name_in, table_name_in) entry ON TRUE;
END;
END , schema_name_in, table_name_in) entry ON TRUE
WHERE
entry.chunk_name IS NOT NULL;
$BODY$;
-- Get relation size of the chunks of an hypertable
@ -318,12 +294,16 @@ DECLARE
is_distributed BOOL;
BEGIN
SELECT relname, nspname, replication_factor > 0
INTO STRICT table_name, schema_name, is_distributed
INTO table_name, schema_name, is_distributed
FROM pg_class c
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname AND ht.table_name = c.relname)
WHERE c.OID = hypertable;
IF table_name IS NULL THEN
RETURN;
END IF;
CASE WHEN is_distributed THEN
RETURN QUERY SELECT ch.chunk_schema, ch.chunk_name, ch.table_bytes, ch.index_bytes,
ch.toast_bytes, ch.total_bytes, ch.node_name
@ -415,8 +395,8 @@ $BODY$;
-------- stats related to compression ------
CREATE OR REPLACE VIEW _timescaledb_internal.compressed_chunk_stats AS
SELECT
srcht.schema_name,
srcht.table_name,
srcht.schema_name AS hypertable_schema,
srcht.table_name AS hypertable_name,
srcch.schema_name AS chunk_schema,
srcch.table_name AS chunk_name,
CASE WHEN srcch.compressed_chunk_id IS NULL THEN
@ -470,11 +450,10 @@ CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_chunk_local_stats (s
after_compression_index_bytes bigint,
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint)
LANGUAGE PLPGSQL
LANGUAGE SQL
STABLE STRICT
AS $BODY$
BEGIN
RETURN QUERY
AS
$BODY$
SELECT
ch.chunk_schema,
ch.chunk_name,
@ -490,9 +469,8 @@ BEGIN
FROM
_timescaledb_internal.compressed_chunk_stats ch
WHERE
ch.schema_name = schema_name_in
AND ch.table_name = table_name_in;
END;
ch.hypertable_schema = schema_name_in
AND ch.hypertable_name = table_name_in;
$BODY$;
CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_chunk_remote_stats (schema_name_in name, table_name_in name)
@ -509,11 +487,10 @@ CREATE OR REPLACE FUNCTION _timescaledb_internal.compressed_chunk_remote_stats (
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE PLPGSQL
LANGUAGE SQL
STABLE STRICT
AS $BODY$
BEGIN
RETURN QUERY
AS
$BODY$
SELECT
ch.*,
srv.node_name
@ -533,8 +510,8 @@ BEGIN
srv.node_name
ELSE
NULL
END, schema_name_in, table_name_in) ch ON TRUE;
END;
END, schema_name_in, table_name_in) ch ON TRUE
WHERE ch.chunk_name IS NOT NULL;
$BODY$;
-- Get per chunk compression statistics for a hypertable that has
@ -564,7 +541,9 @@ BEGIN
SELECT
relname,
nspname,
replication_factor > 0 INTO STRICT table_name,
replication_factor > 0
INTO
table_name,
schema_name,
is_distributed
FROM
@ -574,19 +553,24 @@ BEGIN
AND ht.table_name = c.relname)
WHERE
c.OID = hypertable;
IF table_name IS NULL THEN
RETURN;
END IF;
CASE WHEN is_distributed THEN
RETURN QUERY
SELECT
*
FROM
_timescaledb_internal.compressed_chunk_remote_stats (schema_name, table_name);
ELSE
RETURN QUERY
SELECT
*,
NULL::name
FROM
_timescaledb_internal.compressed_chunk_local_stats (schema_name, table_name);
ELSE
RETURN QUERY
SELECT
*,
NULL::name
FROM
_timescaledb_internal.compressed_chunk_local_stats (schema_name, table_name);
END CASE;
END;
$BODY$;
@ -606,14 +590,13 @@ CREATE OR REPLACE FUNCTION hypertable_compression_stats (hypertable REGCLASS)
after_compression_toast_bytes bigint,
after_compression_total_bytes bigint,
node_name name)
LANGUAGE PLPGSQL
LANGUAGE SQL
STABLE STRICT
AS $BODY$
BEGIN
RETURN QUERY
SELECT
count(*) AS total_chunks,
count(*) FILTER (WHERE ch.compression_status = 'Compressed') AS number_compressed_chunks,
AS
$BODY$
SELECT
count(*)::bigint AS total_chunks,
(count(*) FILTER (WHERE ch.compression_status = 'Compressed'))::bigint AS number_compressed_chunks,
sum(ch.before_compression_table_bytes)::bigint AS before_compression_table_bytes,
sum(ch.before_compression_index_bytes)::bigint AS before_compression_index_bytes,
sum(ch.before_compression_toast_bytes)::bigint AS before_compression_toast_bytes,
@ -624,43 +607,51 @@ BEGIN
sum(ch.after_compression_total_bytes)::bigint AS after_compression_total_bytes,
ch.node_name
FROM
chunk_compression_stats (hypertable) ch
chunk_compression_stats(hypertable) ch
GROUP BY
ch.node_name;
END;
$BODY$;
-------------Get index size for hypertables -------
--schema_name - schema_name for hypertable index
-- index_name - index on hyper table
---note that the query matches against the hypertable's schema name as
-- the input is on the hypertable index nd not the chunk index.
-- the input is on the hypertable index and not the chunk index.
CREATE OR REPLACE FUNCTION _timescaledb_internal.indexes_local_size(
schema_name_in NAME,
index_name_in NAME
)
RETURNS TABLE ( hypertable_id INTEGER,
total_bytes BIGINT )
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
BEGIN
RETURN QUERY
SELECT ci.hypertable_id, sum(pg_relation_size(c.oid))::bigint
WITH chunk_index_size (num_bytes) AS (
SELECT
COALESCE(sum(pg_relation_size(c.oid)), 0)::bigint
FROM
pg_class c,
pg_namespace n,
_timescaledb_catalog.hypertable h,
_timescaledb_catalog.chunk ch,
_timescaledb_catalog.chunk_index ci
WHERE ch.schema_name = n.nspname
AND c.relnamespace = n.oid
AND c.relname = ci.index_name
AND ch.id = ci.chunk_id
AND h.id = ci.hypertable_id
AND h.schema_name = schema_name_in
AND ci.hypertable_index_name = index_name_in
GROUP BY ci.hypertable_id;
END;
pg_class c,
pg_namespace n,
_timescaledb_catalog.chunk ch,
_timescaledb_catalog.chunk_index ci,
_timescaledb_catalog.hypertable h
WHERE ch.schema_name = n.nspname
AND c.relnamespace = n.oid
AND c.relname = ci.index_name
AND ch.id = ci.chunk_id
AND h.id = ci.hypertable_id
AND h.schema_name = schema_name_in
AND ci.hypertable_index_name = index_name_in
) SELECT
h.id,
-- Add size of index on all chunks + index size on root table
(SELECT num_bytes FROM chunk_index_size) + pg_relation_size(format('%I.%I', schema_name_in, index_name_in)::regclass)::bigint
FROM
pg_class c, pg_index i, _timescaledb_catalog.hypertable h
WHERE
i.indexrelid = format('%I.%I', schema_name_in, index_name_in)::regclass
AND c.oid = i.indrelid
AND h.schema_name = schema_name_in
AND h.table_name = c.relname;
$BODY$;
CREATE OR REPLACE FUNCTION _timescaledb_internal.data_node_index_size (node_name name, schema_name_in name, index_name_in name)
@ -673,14 +664,10 @@ CREATE OR REPLACE FUNCTION _timescaledb_internal.indexes_remote_size(
index_name_in NAME
)
RETURNS BIGINT
LANGUAGE PLPGSQL VOLATILE STRICT AS
LANGUAGE SQL VOLATILE STRICT AS
$BODY$
DECLARE
total_bytes BIGINT;
BEGIN
SELECT
sum(entry.total_bytes)::bigint AS total_bytes
INTO total_bytes
FROM (
SELECT
s.node_name,
@ -698,9 +685,7 @@ BEGIN
srv.node_name
ELSE
NULL
END, schema_name_in, index_name_in) entry ON TRUE ;
RETURN total_bytes;
END;
END, schema_name_in, index_name_in) entry ON TRUE;
$BODY$;
-- Get sizes of indexes on a hypertable
@ -724,26 +709,32 @@ DECLARE
ht_id INTEGER;
index_bytes BIGINT;
BEGIN
SELECT c.relname, cl.relname, nsp.nspname
INTO STRICT ht_index_name, ht_name, ht_schema_name
FROM pg_class c, pg_index cind, pg_class cl, pg_namespace nsp
SELECT c.relname, cl.relname, nsp.nspname, ht.replication_factor > 0
INTO ht_index_name, ht_name, ht_schema_name, is_distributed
FROM pg_class c, pg_index cind, pg_class cl,
pg_namespace nsp, _timescaledb_catalog.hypertable ht
WHERE c.oid = cind.indexrelid AND cind.indrelid = cl.oid
AND cl.relnamespace = nsp.oid AND c.oid = index_name;
SELECT replication_factor > 0
INTO STRICT is_distributed
FROM _timescaledb_catalog.hypertable ht
WHERE ht.schema_name = ht_schema_name AND ht.table_name = ht_name;
AND cl.relnamespace = nsp.oid AND c.oid = index_name
AND ht.schema_name = nsp.nspname ANd ht.table_name = cl.relname;
IF ht_index_name IS NULL THEN
RETURN NULL;
END IF;
-- get the local size or size of access node indexes
SELECT il.total_bytes
INTO index_bytes
FROM _timescaledb_internal.indexes_local_size(ht_schema_name, ht_index_name) il;
IF index_bytes IS NULL THEN
index_bytes = 0;
END IF;
-- Add size from data nodes
IF is_distributed THEN
index_bytes = index_bytes + _timescaledb_internal.indexes_remote_size(ht_schema_name, ht_name, ht_index_name);
END IF;
CASE WHEN is_distributed THEN
SELECT _timescaledb_internal.indexes_remote_size(ht_schema_name, ht_name, ht_index_name)
INTO index_bytes ;
ELSE
SELECT il.total_bytes
INTO index_bytes
FROM _timescaledb_internal.indexes_local_size(ht_schema_name, ht_index_name) il;
END CASE;
RETURN index_bytes;
END;
$BODY$;

View File

@ -1 +1,2 @@
DROP VIEW IF EXISTS _timescaledb_internal.hypertable_chunk_local_size;
DROP VIEW IF EXISTS _timescaledb_internal.compressed_chunk_stats;

View File

@ -160,20 +160,20 @@ SELECT * FROM test_dt ORDER BY time;
SELECT * FROM "testSchema0".hypertable_detailed_size('test_ts');
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
16384 | 65536 | 16384 | 98304 |
16384 | 81920 | 16384 | 122880 |
(1 row)
-- testing hypertable_detailed_size END
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_time_idx');
hypertable_index_size
-----------------------
32768
40960
(1 row)
SELECT * FROM "testSchema0".hypertable_index_size('test_ts_device_time_idx');
hypertable_index_size
-----------------------
32768
40960
(1 row)
CREATE SCHEMA "testSchema";

View File

@ -45,49 +45,49 @@ INSERT 0 1
SELECT * FROM hypertable_detailed_size('"public"."two_Partitions"');
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
32768 | 417792 | 32768 | 483328 |
32768 | 475136 | 32768 | 548864 |
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_device_id_timeCustom_idx"');
hypertable_index_size
-----------------------
65536
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_device_id_idx"');
hypertable_index_size
-----------------------
65536
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_idx"');
hypertable_index_size
-----------------------
65536
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_0_idx"');
hypertable_index_size
-----------------------
65536
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_1_idx"');
hypertable_index_size
-----------------------
65536
73728
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_2_idx"');
hypertable_index_size
-----------------------
40960
49152
(1 row)
SELECT * FROM hypertable_index_size('"public"."two_Partitions_timeCustom_series_bool_idx"');
hypertable_index_size
-----------------------
49152
57344
(1 row)
SELECT * FROM chunks_detailed_size('"public"."two_Partitions"') order by chunk_name;
@ -413,24 +413,244 @@ SELECT * FROM approximate_row_count(NULL);
(1 row)
\set ON_ERROR_STOP 1
SELECT * FROM chunks_detailed_size(NULL);
-- Test size functions with invalid or non-existing OID
SELECT * FROM hypertable_size(0);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(0) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(0) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_detailed_size(NULL);
SELECT * FROM hypertable_compression_stats(0) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(0) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(0);
hypertable_index_size
-----------------------
(1 row)
SELECT * FROM hypertable_size(1);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(1) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(1) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats(1) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(1) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(1);
hypertable_index_size
-----------------------
(1 row)
-- Test size functions with NULL input
SELECT * FROM hypertable_size(NULL);
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size(NULL) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size(NULL) ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats(NULL) ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats(NULL) ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size(NULL);
hypertable_index_size
-----------------------
(1 row)
-- tests with tables that are not hypertables
CREATE TABLE regtab( a integer, b integer);
CREATE INDEX regtab_idx ON regtab( a);
SELECT * FROM hypertable_index_size('regtab_idx');
ERROR: query returned no rows
-- Test size functions on regular table
CREATE TABLE hypersize(time timestamptz, device int);
CREATE INDEX hypersize_time_idx ON hypersize (time);
\set ON_ERROR_STOP 0
\set VERBOSITY default
\set SHOW_CONTEXT never
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
(1 row)
\set VERBOSITY terse
\set ON_ERROR_STOP 1
-- Test size functions on empty hypertable
SELECT * FROM create_hypertable('hypersize', 'time');
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
6 | public | hypersize | t
(1 row)
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
8192
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 8192 | 0 | 8192 |
(1 row)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
8192
(1 row)
-- Test size functions on non-empty hypertable
INSERT INTO hypersize VALUES('2021-02-25', 1);
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size | pg_relation_size
------------------+---------------+-----------------+------------------------+------------------
0 | 0 | 8192 | 8192 | 8192
(1 row)
SELECT pg_relation_size(ch), pg_table_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('hypersize') ch
ORDER BY ch;
pg_relation_size | pg_table_size | pg_indexes_size | pg_total_relation_size
------------------+---------------+-----------------+------------------------
8192 | 8192 | 16384 | 24576
(1 row)
SELECT * FROM hypertable_size('hypersize');
hypertable_size
-----------------
32768
(1 row)
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
8192 | 24576 | 0 | 32768 |
(1 row)
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_6_11_chunk | 8192 | 16384 | 0 | 24576 |
(1 row)
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('hypersize_time_idx');
hypertable_index_size
-----------------------
24576
(1 row)

View File

@ -9,7 +9,7 @@ step CI: <... completed>
step P: SELECT * FROM hypertable_index_size('test_index');
hypertable_index_size
65536
73728
step Sc: COMMIT;
starting permutation: I1 CI Bc Ic P Sc
@ -21,7 +21,7 @@ step CI: <... completed>
step P: SELECT * FROM hypertable_index_size('test_index');
hypertable_index_size
65536
73728
step Sc: COMMIT;
starting permutation: S1 CI Bc Sc P Ic
@ -38,7 +38,7 @@ step Sc: COMMIT;
step P: SELECT * FROM hypertable_index_size('test_index');
hypertable_index_size
49152
57344
step Ic: COMMIT;
starting permutation: F WPE CI DI Bc WPR P Ic Sc
@ -70,6 +70,6 @@ step RI: <... completed>
step P: SELECT * FROM hypertable_index_size('test_index');
hypertable_index_size
49152
57344
step Ic: COMMIT;
step Sc: COMMIT;

View File

@ -164,11 +164,64 @@ SELECT * FROM approximate_row_count();
SELECT * FROM approximate_row_count(NULL);
\set ON_ERROR_STOP 1
SELECT * FROM chunks_detailed_size(NULL);
SELECT * FROM hypertable_detailed_size(NULL);
-- Test size functions with invalid or non-existing OID
SELECT * FROM hypertable_size(0);
SELECT * FROM hypertable_detailed_size(0) ORDER BY node_name;
SELECT * FROM chunks_detailed_size(0) ORDER BY node_name;
SELECT * FROM hypertable_compression_stats(0) ORDER BY node_name;
SELECT * FROM chunk_compression_stats(0) ORDER BY node_name;
SELECT * FROM hypertable_index_size(0);
SELECT * FROM hypertable_size(1);
SELECT * FROM hypertable_detailed_size(1) ORDER BY node_name;
SELECT * FROM chunks_detailed_size(1) ORDER BY node_name;
SELECT * FROM hypertable_compression_stats(1) ORDER BY node_name;
SELECT * FROM chunk_compression_stats(1) ORDER BY node_name;
SELECT * FROM hypertable_index_size(1);
-- Test size functions with NULL input
SELECT * FROM hypertable_size(NULL);
SELECT * FROM hypertable_detailed_size(NULL) ORDER BY node_name;
SELECT * FROM chunks_detailed_size(NULL) ORDER BY node_name;
SELECT * FROM hypertable_compression_stats(NULL) ORDER BY node_name;
SELECT * FROM chunk_compression_stats(NULL) ORDER BY node_name;
SELECT * FROM hypertable_index_size(NULL);
-- tests with tables that are not hypertables
CREATE TABLE regtab( a integer, b integer);
CREATE INDEX regtab_idx ON regtab( a);
SELECT * FROM hypertable_index_size('regtab_idx');
-- Test size functions on regular table
CREATE TABLE hypersize(time timestamptz, device int);
CREATE INDEX hypersize_time_idx ON hypersize (time);
\set ON_ERROR_STOP 0
\set VERBOSITY default
\set SHOW_CONTEXT never
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
SELECT * FROM hypertable_size('hypersize');
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_index_size('hypersize_time_idx');
\set VERBOSITY terse
\set ON_ERROR_STOP 1
-- Test size functions on empty hypertable
SELECT * FROM create_hypertable('hypersize', 'time');
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
SELECT * FROM hypertable_size('hypersize');
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_index_size('hypersize_time_idx');
-- Test size functions on non-empty hypertable
INSERT INTO hypersize VALUES('2021-02-25', 1);
SELECT pg_relation_size('hypersize'), pg_table_size('hypersize'), pg_indexes_size('hypersize'), pg_total_relation_size('hypersize'), pg_relation_size('hypersize_time_idx');
SELECT pg_relation_size(ch), pg_table_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('hypersize') ch
ORDER BY ch;
SELECT * FROM hypertable_size('hypersize');
SELECT * FROM hypertable_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('hypersize') ORDER BY node_name;
SELECT * FROM hypertable_index_size('hypersize_time_idx');

View File

@ -440,18 +440,18 @@ pg_size_pretty(toast_bytes), pg_size_pretty(total_bytes)
from hypertable_detailed_size('foo');
-[ RECORD 1 ]--+-----------
pg_size_pretty | 32 kB
pg_size_pretty | 144 kB
pg_size_pretty | 160 kB
pg_size_pretty | 8192 bytes
pg_size_pretty | 184 kB
pg_size_pretty | 200 kB
select pg_size_pretty(table_bytes), pg_size_pretty(index_bytes),
pg_size_pretty(toast_bytes), pg_size_pretty(total_bytes)
from hypertable_detailed_size('conditions');
-[ RECORD 1 ]--+------
-[ RECORD 1 ]--+-------
pg_size_pretty | 16 kB
pg_size_pretty | 48 kB
pg_size_pretty | 56 kB
pg_size_pretty | 32 kB
pg_size_pretty | 96 kB
pg_size_pretty | 112 kB
select * from timescaledb_information.hypertables
where hypertable_name like 'foo' or hypertable_name like 'conditions'

View File

@ -347,10 +347,11 @@ ORDER BY chunk_name, node_name;
SELECT * FROM hypertable_detailed_size('compressed'::regclass) ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------------------
16384 | 65536 | 0 | 81920 | db_dist_compression_1
16384 | 65536 | 0 | 81920 | db_dist_compression_2
16384 | 65536 | 0 | 81920 | db_dist_compression_3
(3 rows)
16384 | 81920 | 0 | 98304 | db_dist_compression_1
16384 | 81920 | 0 | 98304 | db_dist_compression_2
16384 | 81920 | 0 | 98304 | db_dist_compression_3
0 | 16384 | 0 | 16384 |
(4 rows)
-- Test compression policy with distributed hypertable
--

View File

@ -380,10 +380,11 @@ SELECT node_name, "options" FROM timescaledb_information.data_nodes ORDER BY nod
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+----------------------
81920 | 98304 | 0 | 180224 | db_dist_hypertable_1
81920 | 98304 | 0 | 180224 | db_dist_hypertable_2
81920 | 98304 | 0 | 180224 | db_dist_hypertable_3
(3 rows)
81920 | 122880 | 0 | 204800 | db_dist_hypertable_1
81920 | 122880 | 0 | 204800 | db_dist_hypertable_2
81920 | 122880 | 0 | 204800 | db_dist_hypertable_3
0 | 24576 | 0 | 24576 |
(4 rows)
-- Show what some queries would look like on the frontend
EXPLAIN (VERBOSE, COSTS FALSE)

View File

@ -380,10 +380,11 @@ SELECT node_name, "options" FROM timescaledb_information.data_nodes ORDER BY nod
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+----------------------
81920 | 98304 | 0 | 180224 | db_dist_hypertable_1
81920 | 98304 | 0 | 180224 | db_dist_hypertable_2
81920 | 98304 | 0 | 180224 | db_dist_hypertable_3
(3 rows)
81920 | 122880 | 0 | 204800 | db_dist_hypertable_1
81920 | 122880 | 0 | 204800 | db_dist_hypertable_2
81920 | 122880 | 0 | 204800 | db_dist_hypertable_3
0 | 24576 | 0 | 24576 |
(4 rows)
-- Show what some queries would look like on the frontend
EXPLAIN (VERBOSE, COSTS FALSE)

View File

@ -380,10 +380,11 @@ SELECT node_name, "options" FROM timescaledb_information.data_nodes ORDER BY nod
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+----------------------
81920 | 98304 | 0 | 180224 | db_dist_hypertable_1
81920 | 98304 | 0 | 180224 | db_dist_hypertable_2
81920 | 98304 | 0 | 180224 | db_dist_hypertable_3
(3 rows)
81920 | 122880 | 0 | 204800 | db_dist_hypertable_1
81920 | 122880 | 0 | 204800 | db_dist_hypertable_2
81920 | 122880 | 0 | 204800 | db_dist_hypertable_3
0 | 24576 | 0 | 24576 |
(4 rows)
-- Show what some queries would look like on the frontend
EXPLAIN (VERBOSE, COSTS FALSE)

View File

@ -207,69 +207,640 @@ SELECT key, value FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
-- Test space reporting functions for distributed and non-distributed tables
\c frontend_2 :ROLE_CLUSTER_SUPERUSER
CREATE TABLE nondisttable(time timestamptz PRIMARY KEY, device int CHECK (device > 0), temp float);
CREATE TABLE disttable(time timestamptz PRIMARY KEY, device int CHECK (device > 0), temp float);
SELECT * FROM create_hypertable('nondisttable', 'time');
CREATE TABLE nondisttable(time timestamptz, device int CHECK (device > 0), temp float);
CREATE TABLE disttable(time timestamptz, device int CHECK (device > 0), temp float);
SELECT * FROM create_hypertable('nondisttable', 'time', create_default_indexes => false);
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+--------------+---------
1 | public | nondisttable | t
(1 row)
SELECT * FROM create_distributed_hypertable('disttable', 'time');
SELECT * FROM create_distributed_hypertable('disttable', 'time', create_default_indexes => false);
NOTICE: adding not-null constraint to column "time"
hypertable_id | schema_name | table_name | created
---------------+-------------+------------+---------
2 | public | disttable | t
(1 row)
SELECT node_name FROM timescaledb_information.data_nodes
ORDER BY node_name;
node_name
-------------
data_node_1
data_node_2
(2 rows)
SELECT * FROM timescaledb_information.hypertables
ORDER BY hypertable_schema, hypertable_name;
hypertable_schema | hypertable_name | owner | num_dimensions | num_chunks | compression_enabled | is_distributed | replication_factor | data_nodes | tablespaces
-------------------+-----------------+--------------------+----------------+------------+---------------------+----------------+--------------------+---------------------------+-------------
public | disttable | cluster_super_user | 1 | 0 | f | t | 1 | {data_node_1,data_node_2} |
public | nondisttable | cluster_super_user | 1 | 0 | f | f | | |
(2 rows)
-- Test size functions on empty distributed hypertable.
--
-- First, show the output from standard PG size functions. The
-- functions are expected to remove 0 table bytes for the distributed
-- hypertable since it doesn't have local storage.
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 0 | 0
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('disttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
(0 rows)
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 0 | 0
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
(0 rows)
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
0
(1 row)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
0
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
0 | 0 | 0 | 0 | data_node_1
0 | 0 | 0 | 0 | data_node_2
0 | 0 | 0 | 0 |
(3 rows)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 0 | 0 | 0 |
(1 row)
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
-- Create primary key index and check how it affects the size of the
-- empty hypertables.
ALTER TABLE nondisttable ADD CONSTRAINT nondisttable_pkey PRIMARY KEY (time);
ALTER TABLE disttable ADD CONSTRAINT disttable_pkey PRIMARY KEY (time);
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
-- Note that the empty disttable is three times the size of the
-- nondisttable since it has primary key indexes on two data nodes in
-- addition to the access node.
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
24576
(1 row)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
8192
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
0 | 8192 | 0 | 8192 | data_node_1
0 | 8192 | 0 | 8192 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 8192 | 0 | 8192 |
(1 row)
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
--------------+------------+-------------+-------------+-------------+-------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('disttable_pkey');
hypertable_index_size
-----------------------
24576
(1 row)
SELECT * FROM hypertable_index_size('nondisttable_pkey');
hypertable_index_size
-----------------------
8192
(1 row)
-- Test size functions on tables with an empty chunk
INSERT INTO nondisttable VALUES ('2017-01-01 06:01', 1, 1.1);
INSERT INTO disttable SELECT * FROM nondisttable;
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('disttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 0 | 0
(1 row)
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
8192 | 8192 | 16384 | 24576
(1 row)
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
49152
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
8192 | 24576 | 0 | 32768 | data_node_1
0 | 8192 | 0 | 8192 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
32768
(1 row)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
8192 | 24576 | 0 | 32768 |
(1 row)
-- Delete all data, but keep chunks
DELETE FROM nondisttable;
DELETE FROM disttable;
VACUUM FULL ANALYZE nondisttable;
VACUUM FULL ANALYZE disttable;
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch)
FROM show_chunks('disttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size
---------------+------------------+-----------------
0 | 0 | 0
(1 row)
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
pg_table_size | pg_relation_size | pg_indexes_size | pg_total_relation_size
---------------+------------------+-----------------+------------------------
0 | 0 | 8192 | 8192
(1 row)
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
32768
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
0 | 16384 | 0 | 16384 | data_node_1
0 | 8192 | 0 | 8192 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
16384
(1 row)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
0 | 16384 | 0 | 16384 |
(1 row)
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | 0 | 8192 | 0 | 8192 | data_node_1
(1 row)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | 0 | 8192 | 0 | 8192 |
(1 row)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('disttable_pkey');
hypertable_index_size
-----------------------
32768
(1 row)
SELECT * FROM hypertable_index_size('nondisttable_pkey');
hypertable_index_size
-----------------------
16384
(1 row)
-- Test size functions on non-empty hypertable
INSERT INTO nondisttable VALUES
('2017-01-01 06:01', 1, 1.1),
('2017-01-01 08:01', 1, 1.2),
('2018-01-02 08:01', 2, 1.3),
('2019-01-01 09:11', 3, 2.1),
('2017-01-01 06:05', 1, 1.4);
INSERT INTO disttable VALUES
('2017-01-01 06:01', 1, 1.1),
('2017-01-01 08:01', 1, 1.2),
('2018-01-02 08:01', 2, 1.3),
('2019-01-01 09:11', 3, 2.1),
('2017-01-01 06:05', 1, 1.4);
SELECT * FROM timescaledb_information.data_nodes ORDER BY node_name;
node_name | owner | options
-------------+--------------------+------------------------------------------------
data_node_1 | cluster_super_user | {host=localhost,port=55432,dbname=backend_2_1}
data_node_2 | cluster_super_user | {host=localhost,port=55432,dbname=backend_x_2}
(2 rows)
INSERT INTO disttable SELECT * FROM nondisttable;
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
98304
(1 row)
SELECT * FROM timescaledb_information.hypertables ORDER BY hypertable_schema, hypertable_name;
hypertable_schema | hypertable_name | owner | num_dimensions | num_chunks | compression_enabled | is_distributed | replication_factor | data_nodes | tablespaces
-------------------+-----------------+--------------------+----------------+------------+---------------------+----------------+--------------------+---------------------------+-------------
public | disttable | cluster_super_user | 1 | 3 | f | t | 1 | {data_node_1,data_node_2} |
public | nondisttable | cluster_super_user | 1 | 3 | f | f | | |
(2 rows)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
81920
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
16384 | 32768 | 0 | 49152 | data_node_1
8192 | 16384 | 0 | 24576 | data_node_2
(2 rows)
16384 | 40960 | 0 | 57344 | data_node_1
8192 | 24576 | 0 | 32768 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
24576 | 49152 | 0 | 73728 |
24576 | 57344 | 0 | 81920 |
(1 row)
SELECT * FROM hypertable_size('disttable') ;
hypertable_size
-----------------
73728
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | 8192 | 16384 | 0 | 24576 | data_node_1
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 16384 | 0 | 24576 | data_node_2
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 16384 | 0 | 24576 | data_node_1
(3 rows)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | 8192 | 16384 | 0 | 24576 |
_timescaledb_internal | _hyper_1_3_chunk | 8192 | 16384 | 0 | 24576 |
_timescaledb_internal | _hyper_1_4_chunk | 8192 | 16384 | 0 | 24576 |
(3 rows)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
(0 rows)
SELECT * FROM hypertable_index_size('disttable_pkey');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_size('nondisttable') ;
SELECT * FROM hypertable_index_size('nondisttable_pkey');
hypertable_index_size
-----------------------
57344
(1 row)
-- Enable compression
ALTER TABLE nondisttable
SET (timescaledb.compress,
timescaledb.compress_segmentby='device',
timescaledb.compress_orderby = 'time DESC');
ALTER TABLE disttable
SET (timescaledb.compress,
timescaledb.compress_segmentby='device',
timescaledb.compress_orderby = 'time DESC');
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
73728
98304
(1 row)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
81920
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
16384 | 40960 | 0 | 57344 | data_node_1
8192 | 24576 | 0 | 32768 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
24576 | 57344 | 0 | 81920 |
(1 row)
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | 8192 | 16384 | 0 | 24576 | data_node_1
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 16384 | 0 | 24576 | data_node_2
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 16384 | 0 | 24576 | data_node_1
(3 rows)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | 8192 | 16384 | 0 | 24576 |
_timescaledb_internal | _hyper_1_3_chunk | 8192 | 16384 | 0 | 24576 |
_timescaledb_internal | _hyper_1_4_chunk | 8192 | 16384 | 0 | 24576 |
(3 rows)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------
2 | 0 | | | | | | | | | data_node_1
1 | 0 | | | | | | | | | data_node_2
(2 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
3 | 0 | | | | | | | | |
(1 row)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
-----------------------+-----------------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | Uncompressed | | | | | | | | | data_node_1
_timescaledb_internal | _dist_hyper_2_5_chunk | Uncompressed | | | | | | | | | data_node_2
_timescaledb_internal | _dist_hyper_2_6_chunk | Uncompressed | | | | | | | | | data_node_1
(3 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
-----------------------+------------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | Uncompressed | | | | | | | | |
_timescaledb_internal | _hyper_1_3_chunk | Uncompressed | | | | | | | | |
_timescaledb_internal | _hyper_1_4_chunk | Uncompressed | | | | | | | | |
(3 rows)
SELECT * FROM hypertable_index_size('disttable_pkey');
hypertable_index_size
-----------------------
73728
(1 row)
SELECT * FROM hypertable_index_size('nondisttable_pkey');
hypertable_index_size
-----------------------
57344
(1 row)
-- Compress two chunks (out of three) to see effect of compression
SELECT compress_chunk(ch)
FROM show_chunks('disttable') ch
LIMIT 2;
compress_chunk
---------------------------------------------
_timescaledb_internal._dist_hyper_2_2_chunk
_timescaledb_internal._dist_hyper_2_5_chunk
(2 rows)
SELECT compress_chunk(ch)
FROM show_chunks('nondisttable') ch
LIMIT 2;
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
_timescaledb_internal._hyper_1_3_chunk
(2 rows)
SELECT * FROM hypertable_size('disttable');
hypertable_size
-----------------
131072
(1 row)
SELECT * FROM hypertable_size('nondisttable');
hypertable_size
-----------------
114688
(1 row)
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
16384 | 49152 | 8192 | 73728 | data_node_1
8192 | 32768 | 8192 | 49152 | data_node_2
0 | 8192 | 0 | 8192 |
(3 rows)
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-----------
24576 | 73728 | 16384 | 114688 |
(1 row)
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+-----------------------+-------------+-------------+-------------+-------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | 8192 | 24576 | 8192 | 40960 | data_node_1
_timescaledb_internal | _dist_hyper_2_5_chunk | 8192 | 24576 | 8192 | 40960 | data_node_2
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 16384 | 0 | 24576 | data_node_1
(3 rows)
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-----------------------+------------------+-------------+-------------+-------------+-------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | 8192 | 24576 | 8192 | 40960 |
_timescaledb_internal | _hyper_1_3_chunk | 8192 | 24576 | 8192 | 40960 |
_timescaledb_internal | _hyper_1_4_chunk | 8192 | 16384 | 0 | 24576 |
(3 rows)
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------
2 | 1 | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 | data_node_1
1 | 1 | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 | data_node_2
(2 rows)
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
total_chunks | number_compressed_chunks | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
--------------+--------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
3 | 2 | 16384 | 32768 | 0 | 49152 | 16384 | 32768 | 16384 | 65536 |
(1 row)
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
-----------------------+-----------------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------
_timescaledb_internal | _dist_hyper_2_2_chunk | Compressed | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 | data_node_1
_timescaledb_internal | _dist_hyper_2_5_chunk | Compressed | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 | data_node_2
_timescaledb_internal | _dist_hyper_2_6_chunk | Uncompressed | | | | | | | | | data_node_1
(3 rows)
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
chunk_schema | chunk_name | compression_status | before_compression_table_bytes | before_compression_index_bytes | before_compression_toast_bytes | before_compression_total_bytes | after_compression_table_bytes | after_compression_index_bytes | after_compression_toast_bytes | after_compression_total_bytes | node_name
-----------------------+------------------+--------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-------------------------------+-------------------------------+-------------------------------+-------------------------------+-----------
_timescaledb_internal | _hyper_1_1_chunk | Compressed | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 |
_timescaledb_internal | _hyper_1_3_chunk | Compressed | 8192 | 16384 | 0 | 24576 | 8192 | 16384 | 8192 | 32768 |
_timescaledb_internal | _hyper_1_4_chunk | Uncompressed | | | | | | | | |
(3 rows)
SELECT * FROM hypertable_index_size('disttable_pkey');
hypertable_index_size
-----------------------
57344
(1 row)
SELECT * FROM hypertable_index_size('nondisttable_pkey');
hypertable_index_size
-----------------------
40960
(1 row)
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER

View File

@ -107,10 +107,11 @@ SELECT * FROM hypertable_detailed_size('dist_table'::regclass)
ORDER BY node_name;;
table_bytes | index_bytes | toast_bytes | total_bytes | node_name
-------------+-------------+-------------+-------------+-------------
16384 | 65536 | 8192 | 90112 | view_node_1
16384 | 65536 | 8192 | 90112 | view_node_2
16384 | 65536 | 0 | 81920 | view_node_3
(3 rows)
16384 | 81920 | 8192 | 106496 | view_node_1
16384 | 81920 | 8192 | 106496 | view_node_2
16384 | 81920 | 0 | 98304 | view_node_3
0 | 16384 | 0 | 16384 |
(4 rows)
---tables with special characters in the name ----
CREATE TABLE "quote'tab" ( a timestamp, b integer);
@ -133,8 +134,7 @@ SELECT * FROM chunks_detailed_size( '"quote''tab"') ORDER BY chunk_name, node_n
_timescaledb_internal | _dist_hyper_2_6_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
_timescaledb_internal | _dist_hyper_2_7_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
| | | | | | view_node_3
(9 rows)
(8 rows)
CREATE TABLE "special#tab" ( a timestamp, b integer);
SELECT create_hypertable( 'special#tab', 'a', 'b', replication_factor=>2, chunk_time_interval=>INTERVAL '1 day');
@ -156,12 +156,11 @@ SELECT * FROM chunks_detailed_size( '"special#tab"') ORDER BY chunk_name, node_
_timescaledb_internal | _dist_hyper_3_8_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | view_node_1
_timescaledb_internal | _dist_hyper_3_9_chunk | 8192 | 32768 | 0 | 40960 | view_node_2
| | | | | | view_node_3
(9 rows)
(8 rows)
SELECT * FROM hypertable_index_size( 'dist_table_time_idx') ;
hypertable_index_size
-----------------------
81920
114688
(1 row)

View File

@ -121,6 +121,7 @@ set(SOLO_TESTS
continuous_aggs_ddl
continuous_aggs_dump
data_fetcher
dist_util
move-11
move-12
move-13

View File

@ -110,29 +110,173 @@ SELECT key, value FROM _timescaledb_catalog.metadata WHERE key LIKE 'dist_uuid';
-- Test space reporting functions for distributed and non-distributed tables
\c frontend_2 :ROLE_CLUSTER_SUPERUSER
CREATE TABLE nondisttable(time timestamptz PRIMARY KEY, device int CHECK (device > 0), temp float);
CREATE TABLE disttable(time timestamptz PRIMARY KEY, device int CHECK (device > 0), temp float);
SELECT * FROM create_hypertable('nondisttable', 'time');
SELECT * FROM create_distributed_hypertable('disttable', 'time');
CREATE TABLE nondisttable(time timestamptz, device int CHECK (device > 0), temp float);
CREATE TABLE disttable(time timestamptz, device int CHECK (device > 0), temp float);
SELECT * FROM create_hypertable('nondisttable', 'time', create_default_indexes => false);
SELECT * FROM create_distributed_hypertable('disttable', 'time', create_default_indexes => false);
SELECT node_name FROM timescaledb_information.data_nodes
ORDER BY node_name;
SELECT * FROM timescaledb_information.hypertables
ORDER BY hypertable_schema, hypertable_name;
-- Test size functions on empty distributed hypertable.
--
-- First, show the output from standard PG size functions. The
-- functions are expected to remove 0 table bytes for the distributed
-- hypertable since it doesn't have local storage.
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('disttable') ch;
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
-- Create primary key index and check how it affects the size of the
-- empty hypertables.
ALTER TABLE nondisttable ADD CONSTRAINT nondisttable_pkey PRIMARY KEY (time);
ALTER TABLE disttable ADD CONSTRAINT disttable_pkey PRIMARY KEY (time);
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
-- Note that the empty disttable is three times the size of the
-- nondisttable since it has primary key indexes on two data nodes in
-- addition to the access node.
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_index_size('disttable_pkey');
SELECT * FROM hypertable_index_size('nondisttable_pkey');
-- Test size functions on tables with an empty chunk
INSERT INTO nondisttable VALUES ('2017-01-01 06:01', 1, 1.1);
INSERT INTO disttable SELECT * FROM nondisttable;
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('disttable') ch;
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
-- Delete all data, but keep chunks
DELETE FROM nondisttable;
DELETE FROM disttable;
VACUUM FULL ANALYZE nondisttable;
VACUUM FULL ANALYZE disttable;
SELECT pg_table_size('disttable'), pg_relation_size('disttable'), pg_indexes_size('disttable'), pg_total_relation_size('disttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch)
FROM show_chunks('disttable') ch;
SELECT pg_table_size('nondisttable'), pg_relation_size('nondisttable'), pg_indexes_size('nondisttable'), pg_total_relation_size('nondisttable');
SELECT pg_table_size(ch), pg_relation_size(ch), pg_indexes_size(ch), pg_total_relation_size(ch)
FROM show_chunks('nondisttable') ch;
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_index_size('disttable_pkey');
SELECT * FROM hypertable_index_size('nondisttable_pkey');
-- Test size functions on non-empty hypertable
INSERT INTO nondisttable VALUES
('2017-01-01 06:01', 1, 1.1),
('2017-01-01 08:01', 1, 1.2),
('2018-01-02 08:01', 2, 1.3),
('2019-01-01 09:11', 3, 2.1),
('2017-01-01 06:05', 1, 1.4);
INSERT INTO disttable VALUES
('2017-01-01 06:01', 1, 1.1),
('2017-01-01 08:01', 1, 1.2),
('2018-01-02 08:01', 2, 1.3),
('2019-01-01 09:11', 3, 2.1),
('2017-01-01 06:05', 1, 1.4);
INSERT INTO disttable SELECT * FROM nondisttable;
SELECT * FROM timescaledb_information.data_nodes ORDER BY node_name;
SELECT * FROM timescaledb_information.hypertables ORDER BY hypertable_schema, hypertable_name;
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM hypertable_size('disttable') ;
SELECT * FROM hypertable_size('nondisttable') ;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_index_size('disttable_pkey');
SELECT * FROM hypertable_index_size('nondisttable_pkey');
-- Enable compression
ALTER TABLE nondisttable
SET (timescaledb.compress,
timescaledb.compress_segmentby='device',
timescaledb.compress_orderby = 'time DESC');
ALTER TABLE disttable
SET (timescaledb.compress,
timescaledb.compress_segmentby='device',
timescaledb.compress_orderby = 'time DESC');
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_index_size('disttable_pkey');
SELECT * FROM hypertable_index_size('nondisttable_pkey');
-- Compress two chunks (out of three) to see effect of compression
SELECT compress_chunk(ch)
FROM show_chunks('disttable') ch
LIMIT 2;
SELECT compress_chunk(ch)
FROM show_chunks('nondisttable') ch
LIMIT 2;
SELECT * FROM hypertable_size('disttable');
SELECT * FROM hypertable_size('nondisttable');
SELECT * FROM hypertable_detailed_size('disttable') ORDER BY node_name;
SELECT * FROM hypertable_detailed_size('nondisttable') ORDER BY node_name;
SELECT * FROM chunks_detailed_size('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunks_detailed_size('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_compression_stats('disttable') ORDER BY node_name;
SELECT * FROM hypertable_compression_stats('nondisttable') ORDER BY node_name;
SELECT * FROM chunk_compression_stats('disttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM chunk_compression_stats('nondisttable') ORDER BY chunk_schema, chunk_name, node_name;
SELECT * FROM hypertable_index_size('disttable_pkey');
SELECT * FROM hypertable_index_size('nondisttable_pkey');
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER
SET client_min_messages TO ERROR;