【单选题】在 KingbaseES V8 中,把表从一个表空间移动到另一个表空间会锁表吗?
解题思路:
创建表空间 tbs01:
1 2 3
| [root@kes ~]# mkdir /tbs01 [root@kes ~]# chown -R kingbase:kingbase /tbs01/ [root@kes ~]# chmod -R 700 /tbs01/
|
查看准备环境:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| test=# create tablespace tbs01 location '/tbs01'; CREATE TABLESPACE
test=# \db 表空间列表 名称 | 拥有者 | 所在地
sys_default | system | sys_global | system | sysaudit | system | tbs01 | system | /tbs01 (4 行记录)
test=# \dt 关联列表 架构模式 | 名称 | 类型 | 拥有者
public | t1 | 数据表 | lucifer (1 行记录)
test=# select oid,relname from sys_class where relname='t1'; oid | relname
16513 | t1 (1 行记录)
|
另一个会话查看当前表是否存在锁:
1 2 3 4
| test=# select * from sys_locks where relation=16513; locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
(0 行记录)
|
模拟表移动表空间:
1 2 3 4
| test=# begin; BEGIN test=# alter table t1 set tablespace tbs01; ALTER TABLE
|
打开另一个会话查看表是否存在锁:
1 2 3 4 5 6
| test=# select * from sys_locks where relation=16513; locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
relation | 14509 | 16513 | | | | | | | | 7/35962 | 61872 | AccessExclusiveLock | t | f (1 行记录)
|
原会话回滚移动表空间的事务:
1 2
| test=# rollback; ROLLBACK
|
在新的会话中再次查看锁是否存在:
1 2 3 4
| test=# select * from sys_locks where relation=16513; locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath
(0 行记录)
|
此时,表的锁已经消失,所以,KingbaseES 数据库中表移动表空间会产生锁。