Skip to content

Instantly share code, notes, and snippets.

@binakot
Last active November 25, 2020 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binakot/ca70381cccc073e1ea2b9c34dcc63fe6 to your computer and use it in GitHub Desktop.
Save binakot/ca70381cccc073e1ea2b9c34dcc63fe6 to your computer and use it in GitHub Desktop.
Repartition mechanism on adding new data node to TimescaleDB cluster.
postgres=# SELECT * FROM timescaledb_information.hypertables;
-[ RECORD 1 ]-------+--------------------------
hypertable_schema | public
hypertable_name | telemetries
owner | postgres
num_dimensions | 2
num_chunks | 106
compression_enabled | f
is_distributed | t
replication_factor | 1
data_nodes | {data_node_1,data_node_2}
tablespaces |
postgres=# SELECT * FROM timescaledb_information.dimensions;
-[ RECORD 1 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 1
column_name | time
column_type | timestamp with time zone
dimension_type | Time
time_interval | 7 days
integer_interval |
integer_now_func |
num_partitions |
-[ RECORD 2 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 2
column_name | imei
column_type | text
dimension_type | Space
time_interval |
integer_interval |
integer_now_func |
num_partitions | 2
---
postgres=# SELECT * FROM attach_data_node('data_node_3', 'telemetries', repartition => TRUE);
NOTICE: the number of partitions in dimension "imei" was increased to 3
DETAIL: To make use of all attached data nodes, a distributed hypertable needs at least as many partitions in the first closed (space) dimension as there are attached data nodes.
-[ RECORD 1 ]------+------------
hypertable_id | 1
node_hypertable_id | 1
node_name | data_node_3
---
postgres=# SELECT * FROM timescaledb_information.hypertables;
-[ RECORD 1 ]-------+--------------------------------------
hypertable_schema | public
hypertable_name | telemetries
owner | postgres
num_dimensions | 2
num_chunks | 106
compression_enabled | f
is_distributed | t
replication_factor | 1
data_nodes | {data_node_1,data_node_2,data_node_3}
tablespaces |
postgres=# SELECT * FROM timescaledb_information.dimensions;
-[ RECORD 1 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 1
column_name | time
column_type | timestamp with time zone
dimension_type | Time
time_interval | 7 days
integer_interval |
integer_now_func |
num_partitions |
-[ RECORD 2 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 2
column_name | imei
column_type | text
dimension_type | Space
time_interval |
integer_interval |
integer_now_func |
num_partitions | 3
---
postgres=# SELECT * FROM set_number_partitions('telemetries', 12, 'imei');
-[ RECORD 1 ]---------+-
set_number_partitions |
---
postgres=# SELECT * FROM timescaledb_information.hypertables;
-[ RECORD 1 ]-------+--------------------------------------
hypertable_schema | public
hypertable_name | telemetries
owner | postgres
num_dimensions | 2
num_chunks | 106
compression_enabled | f
is_distributed | t
replication_factor | 1
data_nodes | {data_node_1,data_node_2,data_node_3}
tablespaces |
postgres=# SELECT * FROM timescaledb_information.dimensions;
-[ RECORD 1 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 1
column_name | time
column_type | timestamp with time zone
dimension_type | Time
time_interval | 7 days
integer_interval |
integer_now_func |
num_partitions |
-[ RECORD 2 ]-----+-------------------------
hypertable_schema | public
hypertable_name | telemetries
dimension_number | 2
column_name | imei
column_type | text
dimension_type | Space
time_interval |
integer_interval |
integer_now_func |
num_partitions | 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment