timescaledb/sql/views_experimental.sql
gayyappan 9ea77fb97f Post release 2.4.0
Add tests to update from 2.4.0
Fix up version.config
Fix view creation stmt in views_experimental.sql that
causes extension update failures.
2021-07-30 17:51:30 -04:00

29 lines
1.4 KiB
SQL

-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
CREATE OR REPLACE VIEW timescaledb_experimental.chunk_replication_status AS
SELECT
h.schema_name AS hypertable_schema,
h.table_name AS hypertable_name,
c.schema_name AS chunk_schema,
c.table_name AS chunk_name,
h.replication_factor AS desired_num_replicas,
count(cdn.chunk_id) AS num_replicas,
array_agg(cdn.node_name) AS replica_nodes,
-- compute the set of data nodes that doesn't have the chunk
(SELECT array_agg(node_name) FROM
(SELECT node_name FROM _timescaledb_catalog.hypertable_data_node hdn
WHERE hdn.hypertable_id = h.id
EXCEPT
SELECT node_name FROM _timescaledb_catalog.chunk_data_node cdn
WHERE cdn.chunk_id = c.id
ORDER BY node_name) nodes) AS non_replica_nodes
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.chunk_data_node cdn ON (cdn.chunk_id = c.id)
INNER JOIN _timescaledb_catalog.hypertable h ON (h.id = c.hypertable_id)
GROUP BY h.id, c.id, hypertable_schema, hypertable_name, chunk_schema, chunk_name
ORDER BY h.id, c.id, hypertable_schema, hypertable_name, chunk_schema, chunk_name;
GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_experimental TO PUBLIC;