我是靠谱客的博主 能干母鸡,最近开发中收集的这篇文章主要介绍达梦数据库如何变更数据文件目录达梦数据库如何变更数据文件目录,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

达梦数据库如何变更数据文件目录

在实际的生产环境中会遇到数据文件目录需要变更的情况,下面我来讲解下如何变更数据库目录从/data 转移到/data2
建议在操作之前先进行一个全备或者确定有近期完整的有效备份,防止操作失误无法进行后退。

方法一:针对数据量不大的情况下,可以使用重新初始化一个新的数据库实例在需要迁移的目录上,将数据通过dts、模式导出导入、dmrman备份恢复的方式恢复到新的数据库实例当中;这里我就不做过多赘述。可以从达梦云适配中心参考对应的指导文档。

链接: 达梦云适配中心.

方法二:对于数据量比较大,迁移数据时间超过预期的停机时间,我们可以变更数据文件目录到指定的目录下。

操作系统版本: Red Hat Enterprise Linux Server release 6.9 (Santiago)
数据库版本:DM V8

2.1 把data1目录下的数据转换到data2目录下
在这里插入图片描述
2.2 将数据拷贝至data2目录下,注意权限的问题。

[root@RH6 data1]# cp -r /data1/OADB/ /data2/
[root@RH6 data1]# ls -l /data*
/data1:
total 20
drwx------. 2 dmdba dinstall 16384 Apr  2 02:30 lost+found
drwxr-xr-x. 6 dmdba dinstall  4096 Apr  2 02:41 OADB

/data2:
total 20
drwx------. 2 root root 16384 Apr  2 02:31 lost+found
drwxr-xr-x. 6 root root  4096 Apr  2 02:44 OADB
[root@RH6 data1]# chown dmdba:dinstall /data2/ -R
[dmdba@RH6 bin]$ ls -l /data*
/data1:
total 20
drwx------. 2 dmdba dinstall 16384 Apr  2 02:30 lost+found
drwxr-xr-x. 6 dmdba dinstall  4096 Apr  2 02:41 OADB

/data2:
total 20
drwx------. 2 dmdba dinstall 16384 Apr  2 02:31 lost+found
drwxr-xr-x. 6 dmdba dinstall  4096 Apr  2 02:50 OADB
[dmdba@RH6 bin]$ 

2.3 替换配置文件中原来data1的目录名称更换为data2

[root@RH6 data1]# 
[dmdba@RH6 OADB]$ sed -i "s/data1/data2/g" dm.ini^C
[dmdba@RH6 OADB]$ cat dm.ini|grep PATH
		CTL_PATH                        = /data1/OADB/dm.ctl                   #ctl file path
		CTL_BAK_PATH                    = /data1/OADB/ctl_bak                 #dm.ctl backup path
		SYSTEM_PATH                     = /data1/OADB                                 #system path
		CONFIG_PATH                     = /data1/OADB                                 #config path
		TEMP_PATH                       = /data1/OADB                                 #temporary file path
		BAK_PATH                        = /data1/OADB/bak                         #backup file path
		DFS_PATH                        =                                                     #path of db_file in dfs
		REDOS_FILE_PATH_POLICY          = 0                     #Data files' path policy when standby instance applies CREATE TABLESPACE redo log. 0:use the same file name under system path, 1:use the same file path under the system path
		UNIX_SOCKET_PATHNAME            =                #Unix socket pathname.
		TRACE_PATH                      =                       #System trace path name
[dmdba@RH6 OADB]$ sed -i "s/data1/data2/g" dm.ini
[dmdba@RH6 OADB]$ cat dm.ini|grep PATH
		CTL_PATH                        = /data2/OADB/dm.ctl                   #ctl file path
		CTL_BAK_PATH                    = /data2/OADB/ctl_bak                 #dm.ctl backup path
		SYSTEM_PATH                     = /data2/OADB                                 #system path
		CONFIG_PATH                     = /data2/OADB                                 #config path
		TEMP_PATH                       = /data2/OADB                                 #temporary file path
		BAK_PATH                        = /data2/OADB/bak                         #backup file path
		DFS_PATH                        =                                                     #path of db_file in dfs
		REDOS_FILE_PATH_POLICY          = 0                     #Data files' path policy when standby instance applies CREATE TABLESPACE redo log. 0:use the same file name under system path, 1:use the same file path under the system path
		UNIX_SOCKET_PATHNAME            =                #Unix socket pathname.
		TRACE_PATH                      =                       #System trace path name
[dmdba@RH6 OADB]$

2.4 使用dmctlcvt转换控制文件,将控制文件中的路径也一并替换掉

[dmdba@RH6 bin]$ ./dmctlcvt help
DMCTLCVT V8
version: 03134283890-20220304-158322-10045

格式: ./dmctlcvt KEYWORD=value
注意: 控制文件名称必须指定为dm.ctl、dmmpp.ctl、dss.ctl

关键字              说明
--------------------------------------------------------------------------------
TYPE                1 转换控制文件为文本文件(源文件路径中控制文件名称必须是dm.ctl或dmmpp.ctl或dss.ctl)
                    2 转换文本文件为控制文件(目标文件路径中控制文件名称必须是dm.ctl或dmmpp.ctl或dss.ctl)
SRC                 源文件路径
DEST                目标文件路径
DCR_INI             dmdcr.ini文件路径
DFS_INI             dmdfs.ini文件路径
HELP                打印帮助信息

示例:
./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
[dmdba@RH6 bin]$ 
[dmdba@RH6 bin]$ 
[dmdba@RH6 bin]$ ./dmctlcvt type=1 src=/data2/OADB/dm.ctl dest=/home/dmdba/OAini.txt
DMCTLCVT V8
convert ctl to txt success!
[dmdba@RH6 bin]$ cat /home/dmdba/OAini.txt |grep data1
fil_path=/data1/OADB/SYSTEM.DBF
fil_path=/data1/OADB/ROLL.DBF
fil_path=/data1/OADB/OADB01.log
fil_path=/data1/OADB/OADB02.log
fil_path=/data1/OADB/MAIN.DBF
huge_path=/data1/OADB/HMAIN
[dmdba@RH6 bin]$ sed -i "s/data1/data2/g" /home/dmdba/OAini.txt 
[dmdba@RH6 bin]$ cat /home/dmdba/OAini.txt |grep data1
[dmdba@RH6 bin]$ cat /home/dmdba/OAini.txt |grep data2
fil_path=/data2/OADB/SYSTEM.DBF
fil_path=/data2/OADB/ROLL.DBF
fil_path=/data2/OADB/OADB01.log
fil_path=/data2/OADB/OADB02.log
fil_path=/data2/OADB/MAIN.DBF
huge_path=/data2/OADB/HMAIN
[dmdba@RH6 bin]$ ./dmctlcvt type=2 src=/home/dmdba/OAini.txt dest=/data2/OADB/dm.ctl 
DMCTLCVT V8
convert txt to ctl success!

2.5 替换掉之后启动新目录下的数据库实例

[dmdba@RH6 bin]$ 
[dmdba@RH6 bin]$ 
[dmdba@RH6 bin]$ 
[dmdba@RH6 bin]$ ./dmserver /data2/OADB/dm.ini 
file dm.key not found, use default license!
version info: develop
..........
iid page's trxid[5010]
NEXT TRX ID = 6012.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin ...
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
SYSTEM IS READY.

到这里目录更换完成,新的数据库目录下启动数据库正常!同样的如果数据文件创建错了,需要重新进行调整文件路径的话,也可以使用dmctlcvt来进行处理。

最后

以上就是能干母鸡为你收集整理的达梦数据库如何变更数据文件目录达梦数据库如何变更数据文件目录的全部内容,希望文章能够帮你解决达梦数据库如何变更数据文件目录达梦数据库如何变更数据文件目录所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部