在数据库的运维过程中,经常会进行硬件升级,更换主机或者依照当前生产库形成测试环境,这时就需要形成一个与原库相同的目标库。此时,进行物理迁移则是比较便捷的方法,其主要则是将源库相关文件直接复制到目标主机,将配置文件进行修改,与目标库相匹配,尔后在目标主机中注册服务,启动迁移后的实例。物理迁移操作上比较简单,要求两个库在版本上保持一致,以减少迁移风险和操作难度。
两个主机环境为64位centos 7.2,如下示:
[root@dwm Desktop]# uname -a
Linux dwm 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@dwm Desktop]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
待迁移的数据库版本为64位DM8信息如下:
为了确认待复制文件的详细信息,通过动态视图进行查询,
SQL> select tablespace_name, file_name, bytes/1024/1024 as "size(M)" from dba_data_files;
LINEID TABLESPACE_NAME FILE_NAME size(M)
---------- --------------- ----------------------------- --------------------
1 SYSTEM /dm8/data/DAMENG/SYSTEM.DBF 23
2 DMHR /dm8/data/DAMENG/DMHR.DBF 128
3 BOOKSHOP /dm8/data/DAMENG/BOOKSHOP.DBF 150
4 MAIN /dm8/data/DAMENG/MAIN.DBF 128
5 TEMP /dm8/data/DAMENG/TEMP.DBF 10
6 ROLL /dm8/data/DAMENG/ROLL.DBF 128
6 rows got
used time: 2.845(ms). Execute id is 7.
查询配置文件路径参数,目标库可以根据存储实际情况对路径进行修改,也可以按照原库的位置不做改动,只要配置文件和实际的存储位置保持一致即可。
SQL> select para_name, para_value from v$dm_ini where para_name like '%PATH%';
LINEID PARA_NAME PARA_VALUE
---------- ----------------- ------------------------
1 CTL_PATH /dm8/data/DAMENG/dm.ctl
2 CTL_BAK_PATH /dm8/data/DAMENG/ctl_bak
3 SYSTEM_PATH /dm8/data/DAMENG
4 CONFIG_PATH /dm8/data/DAMENG
5 TEMP_PATH /dm8/data/DAMENG
6 BAK_PATH /dm8/data/DAMENG/bak
7 AUD_PATH NULL
8 DFS_PATH $/DAMENG
9 SVR_LOG_FILE_PATH ../log
10 TRACE_PATH /dm8/data/DAMENG/trace
11 DCR_PATH NULL
11 rows got
used time: 3.067(ms). Execute id is 10.
为了确保数据一致性,在进行迁移,将实例关闭。
目标数据库相同版本的数据库已经安装,并且拥有一个实例,服务端口为5236,为了区分,我们将原库实例进行修改,在目标数据库的对应端口5237的数据库实例。
复制相关文件至目标主机,原目录为/dm8/data/DAMENG,目标文件目录为/dm8/data/DAMENG2:
[dmdba@localhost DAMENG]$ scp *.* dmdba@192.168.56.105:/dm8/data/DAMENG2
The authenticity of host '192.168.56.105 (192.168.56.105)' can't be established.
ECDSA key fingerprint is dc:d6:a1:b2:c2:7d:e0:60:c9:ec:3e:19:18:85:2a:e8.
Are you sure you want to continue connecting (yes/no)? YES
Warning: Permanently added '192.168.56.105' (ECDSA) to the list of known hosts.
dmdba@192.168.56.105's password:
BOOKSHOP.DBF 100% 150MB 75.0MB/s 00:02
DAMENG01.log 100% 256MB 64.0MB/s 00:04
DAMENG02.log 100% 256MB 64.0MB/s 00:04
dm.ctl 100% 6144 6.0KB/s 00:00
DMHR.DBF 100% 128MB 64.0MB/s 00:02
dm.ini 100% 48KB 48.1KB/s 00:00
dminit20210306001532.log 100% 808 0.8KB/s 00:00
dm_service.prikey 100% 633 0.6KB/s 00:00
MAIN.DBF 100% 128MB 64.0MB/s 00:02
rep_conflict.log 100% 12 0.0KB/s 00:00
ROLL.DBF 100% 128MB 64.0MB/s 00:02
sqllog.ini 100% 479 0.5KB/s 00:00
SYSTEM.DBF 100% 23MB 23.0MB/s 00:00
TEMP.DBF 100% 10MB 10.0MB/s 00:00
在目标主机上进行确认:
[dmdba@dwm DAMENG2]$ pwd
/dm8/data/DAMENG2
[dmdba@dwm DAMENG2]$ ls
BOOKSHOP.DBF dm.ctl dminit20210306001532.log rep_conflict.log SYSTEM.DBF
DAMENG01.log DMHR.DBF dm_service.prikey ROLL.DBF TEMP.DBF
DAMENG02.log dm.ini MAIN.DBF sqllog.ini
修改配置文件:
批量修改命令执行后,提示共有6处进行了修改。
由于对路径进行了修改,所以还要修改控制文件,确保其中信息与实际一致,否则启动时报错。达梦数据库使用dmctlcvt 工具对控制文件修改。
[dmdba@dwm bin]$ ./dmctlcvt help
DMCTLCVT V8
Format: ./dmctlcvt KEYWORD=value
Note: ctl file name must be dm.ctl or dmmpp.ctl or dss.ctl
Keyword Explanation
--------------------------------------------------------------------------------
TYPE 1 convert ctl file(dm.ctl or dmmpp.ctl or dss.ctl) to txt file
2 convert txt file to ctl file(dm.ctl or dmmpp.ctl or dss.ctl)
SRC Source file
DEST Destination file
DCR_INI the path of dmdcr.ini
DFS_INI the path of dmdfs.ini
HELP Show this help info
Example:
./dmctlcvt TYPE=1 SRC=/opt/dmdbms/data/dameng/dm.ctl DEST=/opt/dmdbms/data/dameng/dmctl.txt
./dmctlcvt TYPE=2 SRC=/opt/dmdbms/data/dameng/dmctl.txt DEST=/opt/dmdbms/data/dameng/dm.ctl
参照该工具自带的说明及示例命令,对目标主机中实例控制文件进行修改,首先生成文本文件。
对该文本文件进行修改:
检查修改成功后,将文本文件转化为二进制文件:
将实例注册到系统服务
启动实例
[root@dwm system]# systemctl start DmServiceDM2
Job for DmServiceDM2.service failed because the control process exited with error code. See "systemctl status DmServiceDM2.service" and "journalctl -xe" for details.
未能成功启动,查看详细信息,
[root@dwm system]# systemctl status DmServiceDM2
● DmServiceDM2.service - Dameng Database Service(DmServiceDM2).
Loaded: loaded (/usr/lib/systemd/system/DmServiceDM2.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2021-05-13 12:41:05 CST; 29s ago
Process: 5204 ExecStart=/dm8/bin/DmServiceDM2 start (code=exited, status=1/FAILURE)
May 13 12:40:50 dwm systemd[1]: Starting Dameng Database Service(DmServiceD.....
May 13 12:41:05 dwm DmServiceDM2[5204]: [38B blob data]
May 13 12:41:05 dwm DmServiceDM2[5204]: file dm.key not found, use default l...!
May 13 12:41:05 dwm DmServiceDM2[5204]: Read ini error, name:CTL_PATH, value...l
May 13 12:41:05 dwm DmServiceDM2[5204]: dmserver startup failed, code = -803...]
May 13 12:41:05 dwm DmServiceDM2[5204]: nsvr_ini_file_read failed, [code: -803]
May 13 12:41:05 dwm systemd[1]: DmServiceDM2.service: control process exite...=1
May 13 12:41:05 dwm systemd[1]: Failed to start Dameng Database Service(DmS.....
May 13 12:41:05 dwm systemd[1]: Unit DmServiceDM2.service entered failed state.
May 13 12:41:05 dwm systemd[1]: DmServiceDM2.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
到日志文件中寻找更确切的信息:
[dmdba@dwm log]$ cat DmServiceDM2.log
file dm.key not found, use default license!
Read ini error, name:CTL_PATH, value:dm8/data/DAMENG2/dm.ctl
dmserver startup failed, code = -803 [Invalid ini config value]
nsvr_ini_file_read failed, [code: -803]
经排查是路径替换过程中少了一个/,导致路径异常。
再次修改后,重新启动实例。
这次启动正常,连接实例,检查数据库状态。
端口5237为我们迁移后的实例,进行连接入库。
[dmdba@dwm bin]$ rlwrap ./disql sysdba/dameng123:5237
Server[LOCALHOST:5237]:mode is normal, state is open
login used time: 6.018(ms)
disql V8
SQL> select * from v$database;
LINEID NAME
---------- ------
CREATE_TIME
----------------------------------------------------------------------------------------------------
ARCH_MODE
---------
LAST_CKPT_TIME
----------------------------------------------------------------------------------------------------
STATUS$ ROLE$ MAX_SIZE TOTAL_SIZE DSC_NODES
----------- ----------- -------------------- -------------------- -----------
OPEN_COUNT STARTUP_COUNT
----------- --------------------
LAST_STARTUP_TIME
----------------------------------------------------------------------------------------------------
1 DAMENG
2021-03-06 00:15:34
N
NULL
4 0 0 56192 1
12 1
2021-05-13 12:51:26
used time: 3.147(ms). Execute id is 4.
SQL> select * from v$instance;
LINEID NAME INSTANCE_NAME INSTANCE_NUMBER HOST_NAME SVR_VERSION
---------- -------- ------------- --------------- --------- --------------------------
DB_VERSION
-------------------
START_TIME
----------------------------------------------------------------------------------------------------
STATUS$ MODE$ OGUID DSC_SEQNO DSC_ROLE
------- ------ ----------- ----------- --------
1 DMSERVER DMSERVER 1 dwm DM Database Server x64 V8
DB Version: 0x7000a
2021-05-13 12:51:24
OPEN NORMAL 0 0 NULL
used time: 1.461(ms). Execute id is 5.
SQL>
通过上面的操作步骤,数据库的物理迁移工作完成,实例运行正常,状态为可用。在迁移过程中需要注意是保证目标库的路径和dm.ini和dm.ctl中的完全一致。另外,文件复制后保持属性不变,即属主属组和读写权限是正确的。