Postgresql TimescaleDB:了解创建超表后的返回值和填充超表后的块创建
我的数据库中有一个名为Postgresql TimescaleDB:了解创建超表后的返回值和填充超表后的块创建,postgresql,timescaledb,Postgresql,Timescaledb,我的数据库中有一个名为price(有264行)的现有表,我将其转换为一个超表price\u超表,具体操作如下: CREATE TABLE price_hypertable (LIKE price INCLUDING DEFAULTS INCLUDING CONSTRAINTS EXCLUDING INDEXES); SELECT create_hypertable('price_hypertable', 'start'); 它给我的结果如下: create_hypertable
price
(有264行)的现有表,我将其转换为一个超表price\u超表
,具体操作如下:
CREATE TABLE price_hypertable (LIKE price INCLUDING DEFAULTS INCLUDING CONSTRAINTS EXCLUDING INDEXES);
SELECT create_hypertable('price_hypertable', 'start');
它给我的结果如下:
create_hypertable
-------------------------------
(4,public,price_hypertable,t)
(1 row)
insert into price_hypertable select * from price;
我做的下一件事是填充price\u hypertable
,如下所示:
create_hypertable
-------------------------------
(4,public,price_hypertable,t)
(1 row)
insert into price_hypertable select * from price;
我得到了以下结果:
INSERT 0 264
现在,我想检查创建的块,为此我做了:
select public.show_chunks('price_hypertable');
我得到的结果是:
show_chunks
----------------------------------------
_timescaledb_internal._hyper_4_3_chunk
_timescaledb_internal._hyper_4_4_chunk
(2 rows)
当我这样做时:
select * from _timescaledb_internal._hyper_4_3_chunk;
select * from _timescaledb_internal._hyper_4_4_chunk ;
我看到264条分为以下几部分:
create_hypertable
-------------------------------
(4,public,price_hypertable,t)
(1 row)
insert into price_hypertable select * from price;
\u timescaledb\u internal.\u hyper\u 4\u 3\u chunk
有98行
\u timescaledb\u internal.\u hyper\u 4\u 4\u chunk
有166行
我对这些步骤及其输出有几个问题:
4
和t
代表什么吗
选择create_hypertable('price_hypertable','start')代码>
price\u超链接表后,数据会自动分割成块,但大小不同。为什么会发生这种情况?为什么数据不能一分为二(每个数据块中有132行,而不是98行和166行)
感谢您的帮助。谢谢你的第二个问题: 如果不明确指定
chunk\u time\u interval
,默认值为7天:请参阅。因此,每个区块中的行数取决于数据的分布(根据开始日期-时间列)。对于第一个问题,执行以下命令更容易看到它们代表什么
create_hypertable('price_hypertable','start')中选择*;
这会产生如下结果:
hypertable_id | schema_name | table_name | created
---------------+-------------+--------------------+---------
4 | public | price_hypertable | t
关于第二个问题,我已经回答了。这是因为行是根据时间排序到桶中的,它们的间隔不一定相等。没有自动选择每个铲斗的正确间隔
您可以在中找到有关返回值的信息,其中还讨论了可用于设置块大小的参数
chunk\u time\u interval
。这是一个有用的建议。非常感谢。你能解释一下你所说的“根据时间将行排序到桶中”是什么意思吗?@Junkrat也许“group”是一个更好的词,但我使用了“sorted”这个不太严格的词。Hypertables“切分”时间上的行,这意味着可以为bucket分配一个时间范围,例如12:00:00-13:00:00。此存储桶将包含时间在此范围内的所有行。