本文已参与「新人创作礼亅活动,一起开启掘金创作之路。
postgresql 数据库 timescaledb数据库 创建超表 遇见的的问题 报错
前言 这几天对大量的旧表改为超表,记录遇到的问题
一 cannot create a unique index without the column "create_time" (used in partitioning)
报错详情
SELECT create_hypertable('hrmw.tb_cs', 'create_time', chunk_time_interval => INTERVAL '1 day')
> 错误: cannot create a unique index without the column "create_time" (used in partitioning)
解决方案 这个是因为你采用的的分区键(字段)不是唯一 把你的分区字段 改为主键 就可以了
这里主要你要创建的分区键一定要是主键,不是主键创建不了,如果表本身就有主键,那怎么办? 那就用你想要分区的列加上原有的列,创建一个复合主键,这样就解决了。 一定要注意这个问题,因为好多因为这个问题来问我的。
二 DETAIL: It is not possible to turn temporary or unlogged tables into hypertables
报错详情
SELECT create_hypertable('tb_copy1', 'create_time', chunk_time_interval => INTERVAL '1 day')
> ERROR: table "tb_hrmw_moni_target_error_copy1" has to be logged
DETAIL: It is not possible to turn temporary or unlogged tables into hypertables.
解决方案 这是因为你建的表示不记录的,需要改一下表的选项 或者把建表语句的UNLOGGED 去掉
三 ERROR: invalid INSERT on the root table of hypertable “超表名”
HINT: Make sure the TimescaleDB extension has been preloaded. 报错详情
ERROR: invalid INSERT on the root table of hypertable “超表名”
HINT: Make sure the TimescaleDB extension has been preloaded.
解决方案
这个一般是还原出现的多 我建议是把数据备份 重新创建超表 数据备份解决办法
如果还有啥问题欢迎来留言询问。