KingbaseES sys_restore 恢复表时默认不包括表上的索引

前言

最近碰到一个案例,在使用sys_restore恢复指定表时,默认不恢复表上的索引,如果想恢复需要单独指定。

测试过程

[复制代码](javascript:void(0)😉

查看表的有关属性:test=# \d+ t
                                     Table "public.t"
 Column |  Type   | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+---------+--------------+-------------
 x      | integer |           |          |         | plain   |              |
Indexes:
    "t_inx" btree (x)
Check constraints:
    "check_x" CHECK (x < 10000000)
Access method: heap

备份指定t表:

[kingbase2@localhost V8]$ sys_dump -U system -d test -Fc -t t > t.dump

删除t表及其依赖:

test=# drop table t cascade;
DROP TABLE

恢复t表:

[kingbase2@localhost V8]$ sys_restore -U system -Fc -d test -t t t.dump

看结果check约束恢复回来,但是索引没有恢复回来。这里需要重建索引,或者在sys_restore中指定索引:

test=# \d+ t
Table "public.t"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+---------+--------------+-------------
x | integer | | | | plain | |
Check constraints:
"check_x" CHECK (x < 10000000)
Access method: heap

恢复指定索引:

[kingbase2@localhost V8]$ sys_restore -U system -Fc -d test -I t_inx t.dump

我们看到索引已经恢复回来了:

test=# \d+ t
Table "public.t"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+---------+--------------+-------------
x | integer | | | | plain | |
Indexes:
"t_inx" btree (x)
Check constraints:
"check_x" CHECK (x < 10000000)
Access method: heap

总结

使用sys_restore恢复表时,如果不在命令中指定索引,默认不包括索引,需要通过-I单独指定索引导入。当然也可以导入表以后在数据库内重建索引,不过这种方式建议不要在业务期间执行,因为即使使用INDEX CONCURRENTLY不阻塞DML语句,如果索引占用空间很大,可能也要花费大量时间建索引。

posted @   KINGBASE研究院  阅读(104)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2022-03-02 KingbaseES 函数稳定性与子查询提升
点击右上角即可分享
微信分享提示