KingbaseES V8R3数据库运维案例之---自定义表空间物理迁移
案例说明:
当前数据库实例创建了自定义表空间,由于磁盘空间将满,需将数据库迁移到另外的主机下;本案例采用离线手工拷贝方式将数据data目录及表空间链接目录(数据存储)迁移到异机后,恢复表空间的使用。
适用版本:
KingbaseES V8R3/R6
1、查看数据库表空间信息
TEST=# \db
List of tablespaces
Name | Owner | Location
-------------+--------+--------------------------
SYS_DEFAULT | SYSTEM |
SYS_GLOBAL | SYSTEM |
users | SYSTEM | /data/kingbase/tps/users
(3 rows)
# 表空间中创建对象
TEST=# create table tbs1 (id int) tablespace users;
CREATE TABLE
TEST=# \d tbs1
Table "PUBLIC.tbs1"
Column | Type | Modifiers
--------+---------+-----------
id | INTEGER |
Tablespace: "users"
TEST=# insert into tbs1 values (10);
INSERT 0 1
TEST=# select * from tbs1;
id
----
10
(1 row)
2、查看表空间文件存储
# 自定义表空data下的文件链接
[kingbase@node101 ~]$ cd /data/kingbase/v8r3_370/data/sys_tblspc/
[kingbase@node101 sys_tblspc]$ ls -lh
total 0
lrwxrwxrwx 1 kingbase kingbase 24 Jul 13 10:29 16389 -> /data/kingbase/tps/users
# 查看表空间存储目录
[kingbase@node101 sys_tblspc]$ ls -lh
total 0
lrwxrwxrwx 1 kingbase kingbase 24 Jul 13 10:29 16389 -> /data/kingbase/tps/users
[kingbase@node101 sys_tblspc]$ ls -lh /data/kingbase/tps/users
total 0
drwx------ 3 kingbase kingbase 18 Jul 13 10:30 SYS_V008R003_201608131
# 表空间下对象存储信息
[kingbase@node101 sys_tblspc]$ ls -lh /data/kingbase/tps/users/SYS_V008R003_201608131
total 0
drwx------ 2 kingbase kingbase 18 Jul 13 10:30 14945
3、停止数据库服务迁移数据
1)停止数据库服务
[kingbase@node101 bin]$ ./sys_ctl stop -D /data/kingbase/v8r3_370/data/
waiting for server to shut down.... done
server stopped
2)拷贝data目录到异机
[kingbase@node101 v8r3_370]$ scp -r data node102:/data/kingbase/
# 在新主机配置data目录权限
[kingbase@node102 kingbase]$ chmod 700 data
3)拷贝表空间存储目录和文件
# 新主机创建表空间对应的存储目录
[kingbase@node102 sys_tblspc]$ mkidr -p /data/kingbase/tps/users
# 拷贝表空间数据到新主机
[kingbase@node101 v8r3_370]$ cd /data/kingbase/tps/users
[kingbase@node101 users]$ scp -r * node102:/data/kingbase/tps/users
4、在新主机创建表空间存储目录的链接
1)迁移后表空间存储信息
如下所示,表空间存储从异机copy后原符号链接被取消:
[kingbase@node102 data]$ cd sys_tblspc/
[kingbase@node102 sys_tblspc]$ ls -lh
total 0
drwx------ 3 kingbase kingbase 35 Jul 13 11:04 16389
[kingbase@node102 sys_tblspc]$ ls -lh 16389/
total 0
drwx------ 3 kingbase kingbase 18 Jul 13 11:04 SYS_V008R003_201608131
2)表空间信息查询
如下所示,启动实例后,表空间信息读取错误:
[kingbase@node102 bin]$ ./ksql -U SYSTEM -W 123456 TEST -p 54321
ksql (V008R003C002B0370)
Type "help" for help.
TEST=# \db
ERROR: could not read symbolic link "sys_tblspc/16389": Invalid argument
3)创建表空间存储链接
[kingbase@node102 sys_tblspc]$ ls -lh
total 0
drwx------ 3 kingbase kingbase 35 Jul 13 14:51 16389
# 创建表空间存储链接
[kingbase@node102 sys_tblspc]$ mv 16389 16389.bk
[kingbase@node102 sys_tblspc]$ ln -sf /data/kingbase/tps/users 16389
[kingbase@node102 sys_tblspc]$ ls -lh
total 0
lrwxrwxrwx 1 kingbase kingbase 24 Jul 13 14:52 16389 -> /data/kingbase/tps/users
drwx------ 3 kingbase kingbase 35 Jul 13 14:51 16389.bk
[kingbase@node102 sys_tblspc]$ cd 16389
[kingbase@node102 16389]$ ls -lh
total 0
drwx------ 3 kingbase kingbase 18 Jul 13 10:57 SYS_V008R003_201608131
4)查询表空间及对象数据
如下所示,表空间和数据对象访问正常:
TEST=# \db
List of tablespaces
Name | Owner | Location
-------------+--------+--------------------------
SYS_DEFAULT | SYSTEM |
SYS_GLOBAL | SYSTEM |
users | SYSTEM | /data/kingbase/tps/users
(3 rows)
TEST=# \d tbs1
Table "PUBLIC.tbs1"
Column | Type | Modifiers
--------+---------+-----------
id | INTEGER |
Tablespace: "users"
TEST=# select * from tbs1;
id
----
10
(1 row)
5、总结
对于自定义表空间可以采用离线方式,迁移其存储空间。