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语句,如果索引占用空间很大,可能也要花费大量时间建索引。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值