timescaledb/test/expected/chunk_utils.out
gayyappan 91fe723d3a Drop chunks from materialized hypertables
Add support for dropping chunks from materialized
hypertables. drop_chunks_policy can now be set up
for materialized hypertables.
2020-02-26 11:50:58 -05:00

1456 lines
78 KiB
Plaintext

-- 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.
-- Set this variable to avoid using a hard-coded path each time query
-- results are compared
\set QUERY_RESULT_TEST_EQUAL_RELPATH 'include/query_result_test_equal.sql'
CREATE OR REPLACE FUNCTION dimension_get_time(
hypertable_id INT
)
RETURNS _timescaledb_catalog.dimension LANGUAGE SQL STABLE AS
$BODY$
SELECT *
FROM _timescaledb_catalog.dimension d
WHERE d.hypertable_id = dimension_get_time.hypertable_id AND
d.interval_length IS NOT NULL
$BODY$;
-- Make sure drop_chunks when there are no tables succeeds
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => INTERVAL \'1 hour\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(INTERVAL \'1 hour\', verbose => true)::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 0 | 0
(1 row)
CREATE TABLE PUBLIC.drop_chunk_test1(time bigint, temp float8, device_id text);
CREATE TABLE PUBLIC.drop_chunk_test2(time bigint, temp float8, device_id text);
CREATE TABLE PUBLIC.drop_chunk_test3(time bigint, temp float8, device_id text);
CREATE INDEX ON drop_chunk_test1(time DESC);
-- show_chunks() returns 0 rows when there are no hypertables
SELECT show_chunks();
show_chunks
-------------
(0 rows)
SELECT create_hypertable('public.drop_chunk_test1', 'time', chunk_time_interval => 1, create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------------------
(1,public,drop_chunk_test1,t)
(1 row)
SELECT create_hypertable('public.drop_chunk_test2', 'time', chunk_time_interval => 1, create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------------------
(2,public,drop_chunk_test2,t)
(1 row)
SELECT create_hypertable('public.drop_chunk_test3', 'time', chunk_time_interval => 1, create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-------------------------------
(3,public,drop_chunk_test3,t)
(1 row)
-- Add space dimensions to ensure chunks share dimension slices
SELECT add_dimension('public.drop_chunk_test1', 'device_id', 2);
add_dimension
-----------------------------------------
(4,public,drop_chunk_test1,device_id,t)
(1 row)
SELECT add_dimension('public.drop_chunk_test2', 'device_id', 2);
add_dimension
-----------------------------------------
(5,public,drop_chunk_test2,device_id,t)
(1 row)
SELECT add_dimension('public.drop_chunk_test3', 'device_id', 2);
add_dimension
-----------------------------------------
(6,public,drop_chunk_test3,device_id,t)
(1 row)
--should work becasue so far all tables have time column type of bigint
SELECT show_chunks();
show_chunks
-------------
(0 rows)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+--------------+-------------+-------------+-----------
(0 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
--------+------+------+-------
(0 rows)
SELECT _timescaledb_internal.get_partition_for_key('dev1'::text);
get_partition_for_key
-----------------------
1129986420
(1 row)
SELECT _timescaledb_internal.get_partition_for_key('dev7'::varchar(5));
get_partition_for_key
-----------------------
449729092
(1 row)
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(1, 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(2, 2.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(3, 3.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(4, 4.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(5, 5.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test1 VALUES(6, 6.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(1, 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(2, 2.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(3, 3.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(4, 4.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(5, 5.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test2 VALUES(6, 6.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(1, 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(2, 2.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(3, 3.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(4, 4.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(5, 5.0, 'dev7');
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(6, 6.0, 'dev7');
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
1 | 1 | _timescaledb_internal | _hyper_1_1_chunk | 1 | 2
2 | 1 | _timescaledb_internal | _hyper_1_2_chunk | 2 | 3
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
5 | 1 | _timescaledb_internal | _hyper_1_5_chunk | 5 | 6
6 | 1 | _timescaledb_internal | _hyper_1_6_chunk | 6 | 7
7 | 2 | _timescaledb_internal | _hyper_2_7_chunk | 1 | 2
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(12 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_1_1_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_2_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_5_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_6_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_7_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_13_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_14_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_15_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_16_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_17_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_18_chunk | table | default_perm_user
(18 rows)
-- next two calls of show_chunks should give same set of chunks as above when combined
SELECT show_chunks('drop_chunk_test1');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
_timescaledb_internal._hyper_1_2_chunk
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
_timescaledb_internal._hyper_1_5_chunk
_timescaledb_internal._hyper_1_6_chunk
(6 rows)
SELECT * FROM show_chunks('drop_chunk_test2');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_2_7_chunk
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_10_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
(6 rows)
CREATE VIEW dependent_view AS SELECT * FROM _timescaledb_internal._hyper_1_1_chunk;
\set ON_ERROR_STOP 0
SELECT drop_chunks();
ERROR: older_than and newer_than timestamps provided to drop_chunks cannot both be NULL
SELECT drop_chunks(2);
ERROR: cannot drop table _timescaledb_internal._hyper_1_1_chunk because other objects depend on it
SELECT drop_chunks(NULL::interval);
ERROR: older_than and newer_than timestamps provided to drop_chunks cannot both be NULL
SELECT drop_chunks(NULL::int);
ERROR: older_than and newer_than timestamps provided to drop_chunks cannot both be NULL
SELECT drop_chunks('haha', 'drop_chunk_test3');
ERROR: time constraint arguments of "drop_chunks" should have one of acceptable time column types: SMALLINT, INT, BIGINT, TIMESTAMP, TIMESTAMPTZ, DATE
SELECT show_chunks('drop_chunk_test3', 'haha');
ERROR: time constraint arguments of "show_chunks" should have one of acceptable time column types: SMALLINT, INT, BIGINT, TIMESTAMP, TIMESTAMPTZ, DATE
-- should error because wrong time type
SELECT drop_chunks(now(), 'drop_chunk_test3');
ERROR: time constraint arguments of "drop_chunks" should have same type as time column of the hypertable
SELECT show_chunks('drop_chunk_test3', now());
ERROR: time constraint arguments of "show_chunks" should have same type as time column of the hypertable
-- should error because of wrong relative order of time constraints
SELECT show_chunks('drop_chunk_test1', older_than=>3, newer_than=>4);
ERROR: When both older_than and newer_than are specified, older_than must refer to a time that is more recent than newer_than so that a valid overlapping range is specified
\set ON_ERROR_STOP 1
--should always work regardless of time column types of hypertables
SELECT show_chunks();
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
_timescaledb_internal._hyper_1_2_chunk
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
_timescaledb_internal._hyper_1_5_chunk
_timescaledb_internal._hyper_1_6_chunk
_timescaledb_internal._hyper_2_7_chunk
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_10_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
_timescaledb_internal._hyper_3_13_chunk
_timescaledb_internal._hyper_3_14_chunk
_timescaledb_internal._hyper_3_15_chunk
_timescaledb_internal._hyper_3_16_chunk
_timescaledb_internal._hyper_3_17_chunk
_timescaledb_internal._hyper_3_18_chunk
(18 rows)
-- should work vecause so far all tables have time column type of bigint
SELECT show_chunks(newer_than => 2);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_1_2_chunk
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
_timescaledb_internal._hyper_1_5_chunk
_timescaledb_internal._hyper_1_6_chunk
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_10_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
_timescaledb_internal._hyper_3_14_chunk
_timescaledb_internal._hyper_3_15_chunk
_timescaledb_internal._hyper_3_16_chunk
_timescaledb_internal._hyper_3_17_chunk
_timescaledb_internal._hyper_3_18_chunk
(15 rows)
-- show created constraints and dimension slices for each chunk
SELECT c.table_name, cc.constraint_name, ds.id AS dimension_slice_id, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
FULL OUTER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
ORDER BY c.id;
table_name | constraint_name | dimension_slice_id | range_start | range_end
-------------------+-----------------+--------------------+----------------------+---------------------
_hyper_1_1_chunk | constraint_1 | 1 | 1 | 2
_hyper_1_1_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_2_chunk | constraint_3 | 3 | 2 | 3
_hyper_1_2_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_3_chunk | constraint_4 | 4 | 3 | 4
_hyper_1_3_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_4_chunk | constraint_5 | 5 | 4 | 5
_hyper_1_4_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_5_chunk | constraint_7 | 7 | 5 | 6
_hyper_1_5_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_6_chunk | constraint_8 | 8 | 6 | 7
_hyper_1_6_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_2_7_chunk | constraint_9 | 9 | 1 | 2
_hyper_2_7_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_8_chunk | constraint_11 | 11 | 2 | 3
_hyper_2_8_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_9_chunk | constraint_12 | 12 | 3 | 4
_hyper_2_9_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_10_chunk | constraint_13 | 13 | 4 | 5
_hyper_2_10_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_11_chunk | constraint_15 | 15 | 5 | 6
_hyper_2_11_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_12_chunk | constraint_16 | 16 | 6 | 7
_hyper_2_12_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_3_13_chunk | constraint_17 | 17 | 1 | 2
_hyper_3_13_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_14_chunk | constraint_19 | 19 | 2 | 3
_hyper_3_14_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_15_chunk | constraint_20 | 20 | 3 | 4
_hyper_3_15_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_16_chunk | constraint_21 | 21 | 4 | 5
_hyper_3_16_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_17_chunk | constraint_23 | 23 | 5 | 6
_hyper_3_17_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_18_chunk | constraint_24 | 24 | 6 | 7
_hyper_3_18_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
(36 rows)
SELECT * FROM _timescaledb_catalog.dimension_slice ORDER BY id;
id | dimension_id | range_start | range_end
----+--------------+----------------------+---------------------
1 | 1 | 1 | 2
2 | 4 | 1073741823 | 9223372036854775807
3 | 1 | 2 | 3
4 | 1 | 3 | 4
5 | 1 | 4 | 5
6 | 4 | -9223372036854775808 | 1073741823
7 | 1 | 5 | 6
8 | 1 | 6 | 7
9 | 2 | 1 | 2
10 | 5 | 1073741823 | 9223372036854775807
11 | 2 | 2 | 3
12 | 2 | 3 | 4
13 | 2 | 4 | 5
14 | 5 | -9223372036854775808 | 1073741823
15 | 2 | 5 | 6
16 | 2 | 6 | 7
17 | 3 | 1 | 2
18 | 6 | 1073741823 | 9223372036854775807
19 | 3 | 2 | 3
20 | 3 | 3 | 4
21 | 3 | 4 | 5
22 | 6 | -9223372036854775808 | 1073741823
23 | 3 | 5 | 6
24 | 3 | 6 | 7
(24 rows)
-- Drop one chunk "manually" and verify that dimension slices and
-- constraints are cleaned up. Each chunk has two constraints and two
-- dimension slices. Both constraints should be deleted, but only one
-- slice should be deleted since the space-dimension slice is shared
-- with other chunks in the same hypertable
DROP TABLE _timescaledb_internal._hyper_2_7_chunk;
-- Two constraints deleted compared to above
SELECT c.table_name, cc.constraint_name, ds.id AS dimension_slice_id, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
FULL OUTER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
ORDER BY c.id;
table_name | constraint_name | dimension_slice_id | range_start | range_end
-------------------+-----------------+--------------------+----------------------+---------------------
_hyper_1_1_chunk | constraint_1 | 1 | 1 | 2
_hyper_1_1_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_2_chunk | constraint_3 | 3 | 2 | 3
_hyper_1_2_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_3_chunk | constraint_4 | 4 | 3 | 4
_hyper_1_3_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_4_chunk | constraint_5 | 5 | 4 | 5
_hyper_1_4_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_5_chunk | constraint_7 | 7 | 5 | 6
_hyper_1_5_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_6_chunk | constraint_8 | 8 | 6 | 7
_hyper_1_6_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_2_8_chunk | constraint_11 | 11 | 2 | 3
_hyper_2_8_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_9_chunk | constraint_12 | 12 | 3 | 4
_hyper_2_9_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_10_chunk | constraint_13 | 13 | 4 | 5
_hyper_2_10_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_11_chunk | constraint_15 | 15 | 5 | 6
_hyper_2_11_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_12_chunk | constraint_16 | 16 | 6 | 7
_hyper_2_12_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_3_13_chunk | constraint_17 | 17 | 1 | 2
_hyper_3_13_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_14_chunk | constraint_19 | 19 | 2 | 3
_hyper_3_14_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_15_chunk | constraint_20 | 20 | 3 | 4
_hyper_3_15_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_16_chunk | constraint_21 | 21 | 4 | 5
_hyper_3_16_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_17_chunk | constraint_23 | 23 | 5 | 6
_hyper_3_17_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_18_chunk | constraint_24 | 24 | 6 | 7
_hyper_3_18_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
(34 rows)
-- Only one dimension slice deleted
SELECT * FROM _timescaledb_catalog.dimension_slice ORDER BY id;
id | dimension_id | range_start | range_end
----+--------------+----------------------+---------------------
1 | 1 | 1 | 2
2 | 4 | 1073741823 | 9223372036854775807
3 | 1 | 2 | 3
4 | 1 | 3 | 4
5 | 1 | 4 | 5
6 | 4 | -9223372036854775808 | 1073741823
7 | 1 | 5 | 6
8 | 1 | 6 | 7
10 | 5 | 1073741823 | 9223372036854775807
11 | 2 | 2 | 3
12 | 2 | 3 | 4
13 | 2 | 4 | 5
14 | 5 | -9223372036854775808 | 1073741823
15 | 2 | 5 | 6
16 | 2 | 6 | 7
17 | 3 | 1 | 2
18 | 6 | 1073741823 | 9223372036854775807
19 | 3 | 2 | 3
20 | 3 | 3 | 4
21 | 3 | 4 | 5
22 | 6 | -9223372036854775808 | 1073741823
23 | 3 | 5 | 6
24 | 3 | 6 | 7
(23 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => 2)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(2, CASCADE=>true)::TEXT'
\set ECHO errors
psql:include/query_result_test_equal.sql:14: NOTICE: drop cascades to view dependent_view
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 2 | 2
(1 row)
SELECT c.table_name, cc.constraint_name, ds.id AS dimension_slice_id, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (c.id = cc.chunk_id)
FULL OUTER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.id = cc.dimension_slice_id)
ORDER BY c.id;
table_name | constraint_name | dimension_slice_id | range_start | range_end
-------------------+-----------------+--------------------+----------------------+---------------------
_hyper_1_2_chunk | constraint_3 | 3 | 2 | 3
_hyper_1_2_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_3_chunk | constraint_4 | 4 | 3 | 4
_hyper_1_3_chunk | constraint_2 | 2 | 1073741823 | 9223372036854775807
_hyper_1_4_chunk | constraint_5 | 5 | 4 | 5
_hyper_1_4_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_5_chunk | constraint_7 | 7 | 5 | 6
_hyper_1_5_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_1_6_chunk | constraint_8 | 8 | 6 | 7
_hyper_1_6_chunk | constraint_6 | 6 | -9223372036854775808 | 1073741823
_hyper_2_8_chunk | constraint_11 | 11 | 2 | 3
_hyper_2_8_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_9_chunk | constraint_12 | 12 | 3 | 4
_hyper_2_9_chunk | constraint_10 | 10 | 1073741823 | 9223372036854775807
_hyper_2_10_chunk | constraint_13 | 13 | 4 | 5
_hyper_2_10_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_11_chunk | constraint_15 | 15 | 5 | 6
_hyper_2_11_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_2_12_chunk | constraint_16 | 16 | 6 | 7
_hyper_2_12_chunk | constraint_14 | 14 | -9223372036854775808 | 1073741823
_hyper_3_14_chunk | constraint_19 | 19 | 2 | 3
_hyper_3_14_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_15_chunk | constraint_20 | 20 | 3 | 4
_hyper_3_15_chunk | constraint_18 | 18 | 1073741823 | 9223372036854775807
_hyper_3_16_chunk | constraint_21 | 21 | 4 | 5
_hyper_3_16_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_17_chunk | constraint_23 | 23 | 5 | 6
_hyper_3_17_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
_hyper_3_18_chunk | constraint_24 | 24 | 6 | 7
_hyper_3_18_chunk | constraint_22 | 22 | -9223372036854775808 | 1073741823
(30 rows)
SELECT * FROM _timescaledb_catalog.dimension_slice ORDER BY id;
id | dimension_id | range_start | range_end
----+--------------+----------------------+---------------------
2 | 4 | 1073741823 | 9223372036854775807
3 | 1 | 2 | 3
4 | 1 | 3 | 4
5 | 1 | 4 | 5
6 | 4 | -9223372036854775808 | 1073741823
7 | 1 | 5 | 6
8 | 1 | 6 | 7
10 | 5 | 1073741823 | 9223372036854775807
11 | 2 | 2 | 3
12 | 2 | 3 | 4
13 | 2 | 4 | 5
14 | 5 | -9223372036854775808 | 1073741823
15 | 2 | 5 | 6
16 | 2 | 6 | 7
18 | 6 | 1073741823 | 9223372036854775807
19 | 3 | 2 | 3
20 | 3 | 3 | 4
21 | 3 | 4 | 5
22 | 6 | -9223372036854775808 | 1073741823
23 | 3 | 5 | 6
24 | 3 | 6 | 7
(21 rows)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
2 | 1 | _timescaledb_internal | _hyper_1_2_chunk | 2 | 3
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
5 | 1 | _timescaledb_internal | _hyper_1_5_chunk | 5 | 6
6 | 1 | _timescaledb_internal | _hyper_1_6_chunk | 6 | 7
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(10 rows)
-- next two calls of show_chunks should give same set of chunks as above when combined
SELECT show_chunks('drop_chunk_test1');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_1_2_chunk
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
_timescaledb_internal._hyper_1_5_chunk
_timescaledb_internal._hyper_1_6_chunk
(5 rows)
SELECT * FROM show_chunks('drop_chunk_test2');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_10_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
(5 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_1_2_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_5_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_6_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_14_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_15_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_16_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_17_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_18_chunk | table | default_perm_user
(15 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(\'drop_chunk_test1\', older_than => 3)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(3, \'drop_chunk_test1\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
5 | 1 | _timescaledb_internal | _hyper_1_5_chunk | 5 | 6
6 | 1 | _timescaledb_internal | _hyper_1_6_chunk | 6 | 7
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(9 rows)
\dt "_timescaledb_internal".*
List of relations
Schema | Name | Type | Owner
-----------------------+------------------------+-------+-------------------
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_5_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_6_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_14_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_15_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_16_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_17_chunk | table | default_perm_user
_timescaledb_internal | _hyper_3_18_chunk | table | default_perm_user
_timescaledb_internal | bgw_job_stat | table | super_user
_timescaledb_internal | bgw_policy_chunk_stats | table | super_user
(16 rows)
-- next two calls of show_chunks should give same set of chunks as above when combined
SELECT show_chunks('drop_chunk_test1');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
_timescaledb_internal._hyper_1_5_chunk
_timescaledb_internal._hyper_1_6_chunk
(4 rows)
SELECT * FROM show_chunks('drop_chunk_test2');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_10_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
(5 rows)
-- 2,147,483,647 is the largest int so this tests that BIGINTs work
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(\'drop_chunk_test3\', older_than => 2147483648)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(2147483648, \'drop_chunk_test3\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 5 | 5
(1 row)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2' OR h.table_name = 'drop_chunk_test3')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
5 | 1 | _timescaledb_internal | _hyper_1_5_chunk | 5 | 6
6 | 1 | _timescaledb_internal | _hyper_1_6_chunk | 6 | 7
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(9 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_5_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_6_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
(9 rows)
\set ON_ERROR_STOP 0
-- should error because no hypertable
SELECT drop_chunks(5, 'drop_chunk_test4');
ERROR: "drop_chunk_test4" is not a hypertable or a continuous aggregate view
SELECT show_chunks('drop_chunk_test4');
ERROR: relation "drop_chunk_test4" does not exist at character 20
SELECT show_chunks('drop_chunk_test4', 5);
ERROR: relation "drop_chunk_test4" does not exist at character 20
\set ON_ERROR_STOP 1
DROP TABLE _timescaledb_internal._hyper_1_6_chunk;
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1' OR h.table_name = 'drop_chunk_test2')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
5 | 1 | _timescaledb_internal | _hyper_1_5_chunk | 5 | 6
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(8 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_5_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
(8 rows)
-- newer_than tests
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(hypertable=>\'drop_chunk_test1\', newer_than=>5)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(table_name=>\'drop_chunk_test1\', newer_than=>5, verbose => true)::TEXT'
\set ECHO errors
psql:include/query_result_test_equal.sql:14: INFO: dropping chunk _timescaledb_internal._hyper_1_5_chunk
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+------------------+-------------+-----------
3 | 1 | _timescaledb_internal | _hyper_1_3_chunk | 3 | 4
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
(2 rows)
SELECT show_chunks('drop_chunk_test1');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_1_3_chunk
_timescaledb_internal._hyper_1_4_chunk
(2 rows)
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_1_3_chunk | table | default_perm_user
_timescaledb_internal | _hyper_1_4_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_10_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
(7 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(hypertable=>\'drop_chunk_test1\', older_than=>4, newer_than=>3)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(table_name=>\'drop_chunk_test1\', older_than=>4, newer_than=>3)::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public' AND (h.table_name = 'drop_chunk_test1')
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+------------------+-------------+-----------
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
(1 row)
-- the call of show_chunks should give same set of chunks as above
SELECT show_chunks('drop_chunk_test1');
show_chunks
----------------------------------------
_timescaledb_internal._hyper_1_4_chunk
(1 row)
-- testing drop_chunks when only schema is specified.
\set ON_ERROR_STOP 0
SELECT drop_chunks(schema_name=>'public');
ERROR: older_than and newer_than timestamps provided to drop_chunks cannot both be NULL
SELECT drop_chunks(null::bigint, schema_name=>'public');
ERROR: older_than and newer_than timestamps provided to drop_chunks cannot both be NULL
\set ON_ERROR_STOP 1
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public'
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
4 | 1 | _timescaledb_internal | _hyper_1_4_chunk | 4 | 5
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
10 | 2 | _timescaledb_internal | _hyper_2_10_chunk | 4 | 5
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(6 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than=>5, newer_than=>4)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(5, schema_name=>\'public\', newer_than=>4)::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 2 | 2
(1 row)
SELECT c.id AS chunk_id, c.hypertable_id, c.schema_name AS chunk_schema, c.table_name AS chunk_table, ds.range_start, ds.range_end
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
INNER JOIN dimension_get_time(h.id) time_dimension ON(true)
INNER JOIN _timescaledb_catalog.dimension_slice ds ON (ds.dimension_id = time_dimension.id)
INNER JOIN _timescaledb_catalog.chunk_constraint cc ON (cc.dimension_slice_id = ds.id AND cc.chunk_id = c.id)
WHERE h.schema_name = 'public'
ORDER BY c.id;
chunk_id | hypertable_id | chunk_schema | chunk_table | range_start | range_end
----------+---------------+-----------------------+-------------------+-------------+-----------
8 | 2 | _timescaledb_internal | _hyper_2_8_chunk | 2 | 3
9 | 2 | _timescaledb_internal | _hyper_2_9_chunk | 3 | 4
11 | 2 | _timescaledb_internal | _hyper_2_11_chunk | 5 | 6
12 | 2 | _timescaledb_internal | _hyper_2_12_chunk | 6 | 7
(4 rows)
CREATE TABLE PUBLIC.drop_chunk_test_ts(time timestamp, temp float8, device_id text);
SELECT create_hypertable('public.drop_chunk_test_ts', 'time', chunk_time_interval => interval '1 minute', create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
---------------------------------
(4,public,drop_chunk_test_ts,t)
(1 row)
CREATE TABLE PUBLIC.drop_chunk_test_tstz(time timestamptz, temp float8, device_id text);
SELECT create_hypertable('public.drop_chunk_test_tstz', 'time', chunk_time_interval => interval '1 minute', create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-----------------------------------
(5,public,drop_chunk_test_tstz,t)
(1 row)
SET timezone = '+1';
INSERT INTO PUBLIC.drop_chunk_test_ts VALUES(now()-INTERVAL '5 minutes', 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test_ts VALUES(now()+INTERVAL '5 minutes', 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test_tstz VALUES(now()-INTERVAL '5 minutes', 1.0, 'dev1');
INSERT INTO PUBLIC.drop_chunk_test_tstz VALUES(now()+INTERVAL '5 minutes', 1.0, 'dev1');
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_4_19_chunk |
_timescaledb_internal._hyper_4_20_chunk |
(2 rows)
SELECT * FROM test.show_subtables('drop_chunk_test_tstz');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_5_21_chunk |
_timescaledb_internal._hyper_5_22_chunk |
(2 rows)
BEGIN;
SELECT show_chunks('drop_chunk_test_ts');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_4_19_chunk
_timescaledb_internal._hyper_4_20_chunk
(2 rows)
SELECT show_chunks('drop_chunk_test_ts', now()::timestamp-interval '1 minute');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_4_19_chunk
(1 row)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(newer_than => interval \'1 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(newer_than => interval \'1 minute\', table_name => \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => interval \'6 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(older_than => interval \'6 minute\', table_name => \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 0 | 0
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_4_19_chunk |
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(interval \'1 minute\', \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-------+------------
(0 rows)
SELECT show_chunks(hypertable => 'drop_chunk_test_tstz');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_5_21_chunk
_timescaledb_internal._hyper_5_22_chunk
(2 rows)
SELECT show_chunks(hypertable => 'drop_chunk_test_tstz', older_than => now() - interval '1 minute', newer_than => now() - interval '6 minute');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_5_21_chunk
(1 row)
SELECT show_chunks(hypertable => 'drop_chunk_test_tstz', newer_than => now() - interval '1 minute');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_5_22_chunk
(1 row)
SELECT show_chunks(hypertable => 'drop_chunk_test_tstz', older_than => now() - interval '1 minute');
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_5_21_chunk
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable => \'drop_chunk_test_tstz\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(interval \'1 minute\', \'drop_chunk_test_tstz\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_tstz');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_5_22_chunk |
(1 row)
ROLLBACK;
BEGIN;
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(newer_than => interval \'6 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(newer_than => interval \'6 minute\', table_name => \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 2 | 2
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-------+------------
(0 rows)
ROLLBACK;
BEGIN;
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(interval \'1 minute\', \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_4_20_chunk |
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable => \'drop_chunk_test_tstz\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(interval \'1 minute\', \'drop_chunk_test_tstz\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_tstz');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_5_22_chunk |
(1 row)
ROLLBACK;
BEGIN;
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => now()::timestamp-interval \'1 minute\', hypertable => \'drop_chunk_test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(now()::timestamp-interval \'1 minute\', \'drop_chunk_test_ts\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_ts');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_4_20_chunk |
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => now()-interval \'1 minute\', hypertable => \'drop_chunk_test_tstz\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(now()-interval \'1 minute\', \'drop_chunk_test_tstz\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_tstz');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_5_22_chunk |
(1 row)
ROLLBACK;
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
_timescaledb_internal | _hyper_4_19_chunk | table | default_perm_user
_timescaledb_internal | _hyper_4_20_chunk | table | default_perm_user
_timescaledb_internal | _hyper_5_21_chunk | table | default_perm_user
_timescaledb_internal | _hyper_5_22_chunk | table | default_perm_user
(8 rows)
SELECT show_chunks();
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_2_8_chunk
_timescaledb_internal._hyper_2_9_chunk
_timescaledb_internal._hyper_2_11_chunk
_timescaledb_internal._hyper_2_12_chunk
_timescaledb_internal._hyper_4_19_chunk
_timescaledb_internal._hyper_4_20_chunk
_timescaledb_internal._hyper_5_21_chunk
_timescaledb_internal._hyper_5_22_chunk
(8 rows)
\set ON_ERROR_STOP 0
SELECT show_chunks(older_than=>4);
ERROR: cannot call "show_chunks" on all hypertables when all hypertables do not have the same time dimension type
SELECT drop_chunks(4);
ERROR: time constraint arguments of "drop_chunks" should have same type as time column of the hypertable
SELECT drop_chunks(interval '1 minute');
ERROR: can only use "drop_chunks" with an INTERVAL for TIMESTAMP, TIMESTAMPTZ, and DATE types
SELECT drop_chunks(interval '1 minute', 'drop_chunk_test3');
ERROR: can only use "drop_chunks" with an INTERVAL for TIMESTAMP, TIMESTAMPTZ, and DATE types
SELECT drop_chunks(now()-interval '1 minute', 'drop_chunk_test_ts');
ERROR: time constraint arguments of "drop_chunks" should have same type as time column of the hypertable
SELECT drop_chunks(now()::timestamp-interval '1 minute', 'drop_chunk_test_tstz');
ERROR: time constraint arguments of "drop_chunks" should have same type as time column of the hypertable
SELECT drop_chunks(5, schema_name=>'public', newer_than=>4);
ERROR: time constraint arguments of "drop_chunks" should have same type as time column of the hypertable
\set ON_ERROR_STOP 1
\dt "_timescaledb_internal"._hyper*
List of relations
Schema | Name | Type | Owner
-----------------------+-------------------+-------+-------------------
_timescaledb_internal | _hyper_2_11_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_12_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_8_chunk | table | default_perm_user
_timescaledb_internal | _hyper_2_9_chunk | table | default_perm_user
_timescaledb_internal | _hyper_4_19_chunk | table | default_perm_user
_timescaledb_internal | _hyper_4_20_chunk | table | default_perm_user
_timescaledb_internal | _hyper_5_21_chunk | table | default_perm_user
_timescaledb_internal | _hyper_5_22_chunk | table | default_perm_user
(8 rows)
CREATE TABLE PUBLIC.drop_chunk_test_date(time date, temp float8, device_id text);
SELECT create_hypertable('public.drop_chunk_test_date', 'time', chunk_time_interval => interval '1 day', create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
-----------------------------------
(6,public,drop_chunk_test_date,t)
(1 row)
SET timezone = '+100';
INSERT INTO PUBLIC.drop_chunk_test_date VALUES(now()-INTERVAL '2 day', 1.0, 'dev1');
BEGIN;
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 day\', hypertable => \'drop_chunk_test_date\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(interval \'1 day\', \'drop_chunk_test_date\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_date');
Child | Tablespace
-------+------------
(0 rows)
ROLLBACK;
BEGIN;
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => (now()-interval \'1 day\')::date, hypertable => \'drop_chunk_test_date\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks((now()-interval \'1 day\')::date, \'drop_chunk_test_date\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('drop_chunk_test_date');
Child | Tablespace
-------+------------
(0 rows)
ROLLBACK;
SET timezone TO '-5';
CREATE TABLE chunk_id_from_relid_test(time bigint, temp float8, device_id int);
SELECT hypertable_id FROM create_hypertable('chunk_id_from_relid_test', 'time', chunk_time_interval => 10) \gset
NOTICE: adding not-null constraint to column "time"
INSERT INTO chunk_id_from_relid_test VALUES (0, 1.1, 0), (0, 1.3, 11), (12, 2.0, 0), (12, 0.1, 11);
SELECT _timescaledb_internal.chunk_id_from_relid(tableoid) FROM chunk_id_from_relid_test;
chunk_id_from_relid
---------------------
24
24
25
25
(4 rows)
DROP TABLE chunk_id_from_relid_test;
CREATE TABLE chunk_id_from_relid_test(time bigint, temp float8, device_id int);
SELECT hypertable_id FROM create_hypertable('chunk_id_from_relid_test',
'time', chunk_time_interval => 10,
partitioning_column => 'device_id',
number_partitions => 3) \gset
NOTICE: adding not-null constraint to column "time"
INSERT INTO chunk_id_from_relid_test VALUES (0, 1.1, 2), (0, 1.3, 11), (12, 2.0, 2), (12, 0.1, 11);
SELECT _timescaledb_internal.chunk_id_from_relid(tableoid) FROM chunk_id_from_relid_test;
chunk_id_from_relid
---------------------
26
27
28
29
(4 rows)
\set ON_ERROR_STOP 0
SELECT _timescaledb_internal.chunk_id_from_relid('pg_type'::regclass);
ERROR: chunk not found
SELECT _timescaledb_internal.chunk_id_from_relid('chunk_id_from_relid_test'::regclass);
ERROR: chunk not found
-- test drop/show_chunks on custom partition types
CREATE FUNCTION extract_time(a jsonb)
RETURNS TIMESTAMPTZ
LANGUAGE SQL
AS $$ SELECT (a->>'time')::TIMESTAMPTZ $$ IMMUTABLE;
CREATE TABLE test_weird_type(a jsonb);
SELECT create_hypertable('test_weird_type', 'a',
time_partitioning_func=>'extract_time'::regproc,
chunk_time_interval=>'2 hours'::interval);
NOTICE: adding not-null constraint to column "a"
create_hypertable
------------------------------
(9,public,test_weird_type,t)
(1 row)
INSERT INTO test_weird_type VALUES ('{"time":"2019/06/06 1:00+0"}'), ('{"time":"2019/06/06 5:00+0"}');
SELECT * FROM test.show_subtables('test_weird_type');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_9_30_chunk |
_timescaledb_internal._hyper_9_31_chunk |
(2 rows)
SELECT show_chunks(hypertable => 'test_weird_type', older_than=>'2019/06/06 4:00+0'::TIMESTAMPTZ);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_9_30_chunk
(1 row)
SELECT show_chunks(hypertable => 'test_weird_type', older_than=>'2019/06/06 10:00+0'::TIMESTAMPTZ);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_9_30_chunk
_timescaledb_internal._hyper_9_31_chunk
(2 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => \'2019/06/06 5:00+0\'::TIMESTAMPTZ, hypertable => \'test_weird_type\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(\'2019/06/06 5:00+0\'::TIMESTAMPTZ, \'test_weird_type\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('test_weird_type');
Child | Tablespace
-----------------------------------------+------------
_timescaledb_internal._hyper_9_31_chunk |
(1 row)
SELECT show_chunks('test_weird_type', older_than=>'2019/06/06 4:00+0'::TIMESTAMPTZ);
show_chunks
-------------
(0 rows)
SELECT show_chunks('test_weird_type', older_than=>'2019/06/06 10:00+0'::TIMESTAMPTZ);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_9_31_chunk
(1 row)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than => \'2019/06/06 6:00+0\'::TIMESTAMPTZ, hypertable => \'test_weird_type\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(\'2019/06/06 6:00+0\'::TIMESTAMPTZ, \'test_weird_type\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('test_weird_type');
Child | Tablespace
-------+------------
(0 rows)
SELECT show_chunks('test_weird_type', older_than=>'2019/06/06 10:00+0'::TIMESTAMPTZ);
show_chunks
-------------
(0 rows)
DROP TABLE test_weird_type;
CREATE FUNCTION extract_int_time(a jsonb)
RETURNS BIGINT
LANGUAGE SQL
AS $$ SELECT (a->>'time')::BIGINT $$ IMMUTABLE;
CREATE TABLE test_weird_type_i(a jsonb);
SELECT create_hypertable('test_weird_type_i', 'a',
time_partitioning_func=>'extract_int_time'::regproc,
chunk_time_interval=>5);
NOTICE: adding not-null constraint to column "a"
create_hypertable
---------------------------------
(10,public,test_weird_type_i,t)
(1 row)
INSERT INTO test_weird_type_i VALUES ('{"time":"0"}'), ('{"time":"5"}');
SELECT * FROM test.show_subtables('test_weird_type_i');
Child | Tablespace
------------------------------------------+------------
_timescaledb_internal._hyper_10_32_chunk |
_timescaledb_internal._hyper_10_33_chunk |
(2 rows)
SELECT show_chunks('test_weird_type_i', older_than=>5);
show_chunks
------------------------------------------
_timescaledb_internal._hyper_10_32_chunk
(1 row)
SELECT show_chunks('test_weird_type_i', older_than=>10);
show_chunks
------------------------------------------
_timescaledb_internal._hyper_10_32_chunk
_timescaledb_internal._hyper_10_33_chunk
(2 rows)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than=>5, hypertable => \'test_weird_type_i\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(5, \'test_weird_type_i\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('test_weird_type_i');
Child | Tablespace
------------------------------------------+------------
_timescaledb_internal._hyper_10_33_chunk |
(1 row)
SELECT show_chunks('test_weird_type_i', older_than=>5);
show_chunks
-------------
(0 rows)
SELECT show_chunks('test_weird_type_i', older_than=>10);
show_chunks
------------------------------------------
_timescaledb_internal._hyper_10_33_chunk
(1 row)
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(older_than=>10, hypertable => \'test_weird_type_i\')::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(10, \'test_weird_type_i\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
SELECT * FROM test.show_subtables('test_weird_type_i');
Child | Tablespace
-------+------------
(0 rows)
SELECT show_chunks('test_weird_type_i', older_than=>10);
show_chunks
-------------
(0 rows)
DROP TABLE test_weird_type_i CASCADE;
\c :TEST_DBNAME :ROLE_SUPERUSER
ALTER TABLE drop_chunk_test2 OWNER TO :ROLE_DEFAULT_PERM_USER_2;
--drop chunks 3 will have a chunk we a dependent object (a view)
--we create the dependent object now
INSERT INTO PUBLIC.drop_chunk_test3 VALUES(1, 1.0, 'dev1');
SELECT c.schema_name as chunk_schema, c.table_name as chunk_table
FROM _timescaledb_catalog.chunk c
INNER JOIN _timescaledb_catalog.hypertable h ON (c.hypertable_id = h.id)
WHERE h.schema_name = 'public' AND h.table_name = 'drop_chunk_test3'
ORDER BY c.id \gset
create view dependent_view as SELECT * FROM :"chunk_schema".:"chunk_table";
ALTER TABLE drop_chunk_test3 OWNER TO :ROLE_DEFAULT_PERM_USER_2;
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER_2
\set ON_ERROR_STOP 0
SELECT drop_chunks(table_name=>'drop_chunk_test1', older_than=>4, newer_than=>3);
ERROR: must be owner of hypertable "drop_chunk_test1"
SELECT drop_chunks(2, CASCADE=>true, verbose => true);
ERROR: must be owner of hypertable "drop_chunk_test1"
--works with modified owner tables
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(hypertable=>\'drop_chunk_test2\', older_than=>4, newer_than=>3)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(table_name=>\'drop_chunk_test2\', older_than=>4, newer_than=>3)::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
--this fails because there is a dependent object
SELECT drop_chunks(table_name=>'drop_chunk_test3', older_than=>100);
ERROR: cannot drop table _timescaledb_internal._hyper_3_34_chunk because other objects depend on it
--this will succeed even though there is a depenent object I don't have permission
--to drop. This matches PostgreSQL semantics.
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT show_chunks(hypertable=>\'drop_chunk_test3\', older_than=>100)::REGCLASS::TEXT'
\set QUERY2 'SELECT drop_chunks(table_name=>\'drop_chunk_test3\', older_than=>100, cascade=>true)::TEXT'
\set ECHO errors
psql:include/query_result_test_equal.sql:14: NOTICE: drop cascades to view dependent_view
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
----------------+-------------------------+-------------------------
0 | 1 | 1
(1 row)
\set ON_ERROR_STOP 1
--drop chunks from hypertable with same name in different schema
-- order of schema in search_path matters --
\c :TEST_DBNAME :ROLE_SUPERUSER
drop table chunk_id_from_relid_test;
drop table drop_chunk_test1;
drop table drop_chunk_test2;
drop table drop_chunk_test3;
CREATE SCHEMA try_schema;
GRANT CREATE ON SCHEMA try_schema TO :ROLE_DEFAULT_PERM_USER;
GRANT USAGE ON SCHEMA try_schema TO :ROLE_DEFAULT_PERM_USER;
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
CREATE TABLE try_schema.drop_chunk_test_date(time date, temp float8, device_id text);
SELECT create_hypertable('try_schema.drop_chunk_test_date', 'time', chunk_time_interval => interval '1 day', create_default_indexes=>false);
NOTICE: adding not-null constraint to column "time"
create_hypertable
----------------------------------------
(11,try_schema,drop_chunk_test_date,t)
(1 row)
INSERT INTO public.drop_chunk_test_date VALUES( '2020-01-10', 100, 'hello');
INSERT INTO try_schema.drop_chunk_test_date VALUES( '2020-01-10', 100, 'hello');
set search_path to try_schema, public;
SELECT show_chunks(hypertable=>'public.drop_chunk_test_date', older_than=>'1 day'::interval);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_6_35_chunk
(1 row)
SELECT show_chunks(hypertable=>'try_schema.drop_chunk_test_date', older_than=>'1 day'::interval);
show_chunks
------------------------------------------
_timescaledb_internal._hyper_11_36_chunk
(1 row)
SELECT drop_chunks(table_name=>'drop_chunk_test_date', older_than=> '1 day'::interval);
drop_chunks
------------------------------------------
_timescaledb_internal._hyper_11_36_chunk
(1 row)
--drop_chunks without schema_name and table_name
INSERT INTO public.drop_chunk_test_date VALUES( '2020-02-11', 100, 'hello');
INSERT INTO try_schema.drop_chunk_test_date VALUES( '2020-02-10', 100, 'hello');
SELECT show_chunks(hypertable=>'public.drop_chunk_test_date', older_than=>'1 day'::interval);
show_chunks
-----------------------------------------
_timescaledb_internal._hyper_6_35_chunk
_timescaledb_internal._hyper_6_37_chunk
(2 rows)
SELECT show_chunks(hypertable=>'try_schema.drop_chunk_test_date', older_than=>'1 day'::interval);
show_chunks
------------------------------------------
_timescaledb_internal._hyper_11_38_chunk
(1 row)
SELECT drop_chunks( older_than=> '1 day'::interval);
drop_chunks
------------------------------------------
_timescaledb_internal._hyper_11_38_chunk
(1 row)