KCP 模拟题练习 02 - 移动表空间锁表

1 阅读1分钟

【单选题】在 KingbaseES V8 中,把表从一个表空间移动到另一个表空间会锁表吗?

  • 不会

解题思路:

创建表空间 tbs01:

[root@kes ~]# mkdir /tbs01
[root@kes ~]# chown -R kingbase:kingbase /tbs01/
[root@kes ~]# chmod -R 700 /tbs01/

查看准备环境:

-- 创建表空间 tbs01
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 行记录)

另一个会话查看当前表是否存在锁:

test=# select * from sys_locks where relation=16513;
 locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath 
----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
(0 行记录)

模拟表移动表空间:

test=# begin;
BEGIN
test=# alter table t1 set tablespace tbs01;
ALTER TABLE

打开另一个会话查看表是否存在锁:

-- 此时表已存在一个锁
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 行记录)

原会话回滚移动表空间的事务:

test=# rollback;
ROLLBACK

在新的会话中再次查看锁是否存在:

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 数据库中表移动表空间会产生锁。


📚 推荐阅读:DBA 学习之路

如果这篇文章对你有帮助,推荐访问我的 Oracle DBA 系统学习站点,涵盖 100 天完整学习路线:

  • 🔧 Oracle 安装部署 · RMAN 备份恢复 · Data Pump 数据迁移
  • 🏗️ RAC 高可用 · DataGuard 容灾 · 多租户架构
  • 🔍 故障排查 · 升级迁移 · GoldenGate 数据同步

👉 立即访问 ora100.com →