DM7表空间迁移

1、环境

数据库:DM7
操作系统:Red Hat 7.5

迁移表空间就是迁移表空间数据文件,将表空间数据文件(****.dbf)迁移到目标目录下.

2、开始迁移

两种迁移方式,一种不停库在线迁移,一种停掉数据库离线迁移。

2.1、在线迁移

 表空间名字:aaa
 表空间初始位置:/opt/dmdbms/data/
 表空间目标迁移位置:/opt/dmdbms/data/aaa/

2.1.1 查询表空间信息
可以看到表空间aaa有三个数据文件:aaa1.dbf aaa2.dbf aaa3.dbf

SQL> select t.name tablespace_name,t.STATUS$,t.id file_id,
d.path file_name,d.total_size*SF_GET_PAGE_SIZE()/1024/1024||'M' total_space from v$tablespace t, 
v$datafile d where t.id=d.group_id;

LINEID     TABLESPACE_NAME STATUS$     FILE_ID     FILE_NAME                          TOTAL_SPACE
---------- --------------- ----------- ----------- ---------------------------------- -----------
1          SYSTEM          0           0           /opt/dmdbms/data/DAMENG/SYSTEM.DBF 22M
2          aaa             0           6           /opt/dmdbms/data/aaa3.dbf          32M
3          aaa             0           6           /opt/dmdbms/data/aaa2.dbf          32M
4         aaa             0           6           /opt/dmdbms/data/aaa1.dbf          32M
5         MAIN            0           4           /opt/dmdbms/data/DAMENG/MAIN.DBF   128M
6         TEMP            0           3           /opt/dmdbms/data/DAMENG/TEMP.DBF   10M
7         ROLL            0           1           /opt/dmdbms/data/DAMENG/ROLL.DBF   128M

7 rows got

used time: 11.314(ms). Execute id is 31.

2.1.2修改表空间状态为offline

SQL> alter tablespace "aaa" offline;
executed successfully
used time: 194.622(ms). Execute id is 32.

2.1.3迁移表空间数据文件

SQL> alter tablespace "aaa" rename datafile '/opt/dmdbms/data/aaa1.dbf' to '/opt/dmdbms/data/aaa/aaa1.dbf';
executed successfully
used time: 392.133(ms). Execute id is 33.
SQL> alter tablespace "aaa" rename datafile '/opt/dmdbms/data/aaa2.dbf' to '/opt/dmdbms/data/aaa/aaa2.dbf';
executed successfully
used time: 387.649(ms). Execute id is 34.
SQL> alter tablespace "aaa" rename datafile '/opt/dmdbms/data/aaa3.dbf' to '/opt/dmdbms/data/aaa/aaa3.dbf';
executed successfully
used time: 279.840(ms). Execute id is 35.

2.1.4 修改表空间状态为online

SQL> alter tablespace "aaa" online;
executed successfully
used time: 11.191(ms). Execute id is 36.

2.1.5 查询表空间信息

SQL> select t.name tablespace_name,t.STATUS$,t.id file_id,d.path file_name,d.total_size*SF_GET_PAGE_SIZE()/1024/1024||'M' total_space from v$tablespace t,v$datafile d where t.id=d.group_id;

LINEID     TABLESPACE_NAME STATUS$     FILE_ID     FILE_NAME                          TOTAL_SPACE
---------- --------------- ----------- ----------- ---------------------------------- -----------
1          SYSTEM          0           0           /opt/dmdbms/data/DAMENG/SYSTEM.DBF 22M
2          aaa             0           6           /opt/dmdbms/data/aaa/aaa3.dbf      32M
3          aaa             0           6           /opt/dmdbms/data/aaa/aaa2.dbf      32M
4          aaa             0           6           /opt/dmdbms/data/aaa/aaa1.dbf      32M
5          MAIN            0           4           /opt/dmdbms/data/DAMENG/MAIN.DBF   128M
6          TEMP            0           3           /opt/dmdbms/data/DAMENG/TEMP.DBF   10M
7          ROLL            0           1           /opt/dmdbms/data/DAMENG/ROLL.DBF   128M

7 rows got

used time: 21.394(ms). Execute id is 37.

在线迁移成功。

2.2、离线迁移

 过程:
 1、 关闭数据库服务
 2、使用dmctlcvt工具将二进制控制文件dm.ctl转换为可编辑的文本文件dmctl.txt;
 3、修改dmctl.txt文件中表空间aaa的数据文件的路径;
 4、将dmctl.txt文件转换为二进制文件dm.ctl,并将dm.ctl文件放回原来的目录下;
 5、移动表空间aaa的数据文件到目标文件夹下;
 6、启动数据库服务

 表空间名字:aaa
 表空间初始位置:/opt/dmdbms/data/aaa
 表空间目标迁移位置:/dm/tablespacebak/

2.2.1、停止数据库服务

[dmdba@localhost bin]$ /opt/dmdbms/bin/DmServiceDM1 stop
Stopping DmServiceDM1:                                     [ OK ]

2.2.2 dmctlcvt转换控制文件

[dmdba@localhost bin]$ /opt/dmdbms/bin/dmctlcvt c2t /opt/dmdbms/data/DAMENG/dm.ctl /opt/dmdbms/data/dmctl.txt
DMCTLCVT V7.6.0.197-Build(2019.09.12-112648)ENT 
convert ctl to txt success!

2.2.3 修改控制文件

[dmdba@localhost bin]$ vi /opt/dmdbms/data/dmctl.txt

原路径:

[dmdba@localhost bin]$ cat /opt/dmdbms/data/dmctl.txt | grep aaa
ts_name=aaa
fil_path=/opt/dmdbms/data/aaa/aaa1.dbf
fil_path=/opt/dmdbms/data/aaa/aaa2.dbf
fil_path=/opt/dmdbms/data/aaa/aaa3.dbf

修改后的路径:

[dmdba@localhost bin]$ cat /opt/dmdbms/data/dmctl.txt | grep aaa
ts_name=aaa
fil_path=/dm/tablespacebak/aaa1.dbf
fil_path=/dm/tablespacebak/aaa2.dbf
fil_path=/dm/tablespacebak/aaa3.dbf

2.2.4 重建控制文件

[dmdba@localhost bin]$ /opt/dmdbms/bin/dmctlcvt t2c /opt/dmdbms/data/dmctl.txt /opt/dmdbms/data/DAMENG/dm.ctl
DMCTLCVT V7.6.0.197-Build(2019.09.12-112648)ENT 
convert txt to ctl success!

2.2.5 移动数据文件到新路径

[dmdba@localhost bin]$ mv /opt/dmdbms/data/aaa/aa* /dm/tablespacebak/

2.2.6 启动数据库

[dmdba@localhost bin]$ /opt/dmdbms/bin/DmServiceDM1 start
Starting DmServiceDM1:                                     [ OK ]

2.2.7 查询表空间信息

[dmdba@localhost bin]$ ./disql 
disql V7.6.0.197-Build(2019.09.12-112648)ENT 
username:
password:

Server[LOCALHOST:5236]:mode is normal, state is open
login used time: 9.207(ms)
SQL> select t.name tablespace_name,t.STATUS$,t.id file_id,d.path file_name,d.total_size*SF_GET_PAGE_SIZE()/1024/1024||'M' total_space from v$tablespace t,v$datafile d where t.id=d.group_id;

LINEID     TABLESPACE_NAME STATUS$     FILE_ID     FILE_NAME                          TOTAL_SPACE
---------- --------------- ----------- ----------- ---------------------------------- -----------
1          SYSTEM          0           0           /opt/dmdbms/data/DAMENG/SYSTEM.DBF 22M
2          aaa             0           6           /dm/tablespacebak/aaa3.dbf         32M
3          aaa             0           6           /dm/tablespacebak/aaa2.dbf         32M
4          aaa             0           6           /dm/tablespacebak/aaa1.dbf         32M
5          MAIN            0           4           /opt/dmdbms/data/DAMENG/MAIN.DBF   128M
6          TEMP            0           3           /opt/dmdbms/data/DAMENG/TEMP.DBF   10M
7          ROLL            0           1           /opt/dmdbms/data/DAMENG/ROLL.DBF   128M

7 rows got

used time: 21.734(ms). Execute id is 3.

成功将表空间数据文件迁移到目标目录。

你可能感兴趣的:(数据库)