Linux平台达梦数据库V7之控制文件管理
每个 DM 数据库都有一个名为 dm.ctl 的控制文件。控制文件是一个二进制文件,它记录了数据库必要的初始信息,如果控制文件损坏,数据库则无法正常启动。
二 控制文件内容
控制文件位置是在配置文件dm.ini中指定的:
[ IESDB]$ cat dm.ini |grep CTL
CTL_PATH = /usr/appsoft/dmdbms/data/IESDB/dm.ctl #ctl file path
CTL_BAK_PATH = /usr/appsoft/dmdbms/data/IESDB/ctl_bak #dm.ctl backup path
CTL_BAK_NUM = 10 #backup number of dm.ctl, allowed to keep one more backup file besides $pecified number.
RAC_N_CTLS = 10000 #Number Of LBS/GBS ctls
控制文件主要包含以下内容:
- 数据库名称;
- 数据库服务器模式;
- OGUID 唯一标识;
- 数据库服务器版本;
- 数据文件版本;
- 数据库的启动次数;
- 数据库最近一次启动时间;
- 表空间信息,包括表空间名,表空间物理文件路径等,记录了所有数据库中使用的表空间,数组的方式保存起来;
控制文件校验码,校验码由数据库服务器在每次修改控制文件后计算生成,保证控制文件合法性,防止文件损坏及手工修改。
三、控制文件转换
控制文件本身是二进制文件,无法正常查看其具体内容,达梦提供了转换工具dmctlcvt可以将其转换为文本文件,这样就可以方便修改和查看。
Dmctlcvt工具语法:
[ IESDB]$ dmctlcvt -h
DMCTLCVT V7.6.0.171-Build(2019.07.02-109059)ENTFormat: ./dmctlcvt KEYWORD=value
Note: ctl file name must be dm.ctl or dmmpp.ctl or dmwatcher.ctlKeyword Explanation
TYPE 1 convert ctl file(dm.ctl or dmmpp.ctl) to txt file
2 convert txt file to ctl file(dm.ctl or dmmpp.ctl)
3 convert txt file to ctl file(dmwatcher.ctl), the dest_file_path not include file name
4 convert ctl file(dmwatcher.ctl) to txt file
SRC Source file
DEST Destination file
DCR_INI the path of dmdcr.ini
HELP Show this help infoExample:
./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
./dmctlcvt TYPE=3 SRC=/opt/dmdbms/data/dameng/dmwatcher.txt DEST=/opt/dmdbms/data/dameng
./dmctlcvt TYPE=4 SRC=/opt/dmdbms/data/dameng/dmwatcher.ctl DEST=/opt/dmdbms/data/dameng/dmwatcher_ctl.txt
从语法中可以看到,TYPE为1或2时,支持控制文件与文本文件的相互转换。
下面我们将控制文件转换为文本文件,并查看一下其具体内容:
1.转换文本文件
[ IESDB]$ dmctlcvt TYPE=1 src=/usr/appsoft/dmdbms/data/IESDB/dm.ctl dest=/tmp/dmctl.txt
DMCTLCVT V7.6.0.171-Build(2019.07.02-109059)ENT
convert ctl to txt succes$!
2.查看文件内容
[ IESDB]$ cat /tmp/dmctl.txt
##############################################################################please do not adjust parameter order, ensure the ctl have no difference
##########################################################################
database name
dbname=IESDB
server mode
svr_mode=0
#OGUID
oguid=0db server version
version=117507755
database version
db_version=458762
pseg version
pseg_version=458762
#SGUID
sguid=-1677197550
#NEXT_TS_ID
next_ts_id=6
#RAC_NODES
rac_nodes=0
#NEXT_HTS_ID
next_htsid=1
#TIME_FLAG
time_flag=170
#STARTUP_CNT
startup_cnt=1
#LAST_STARTUP_TIME
last_startup_time=2020-5-26 15:21:53
#DM7_DCT_VERSION
dm7_dct_version=2
#DM8_DCT_VERSION
dm8_dct_version=0
#===============================================
#===============================================table space name
ts_name=SYSTEM
table space ID
ts_id=0
table space status
t$_state=0
table space cache
ts_cache=
RAC node number
ts_nth=0
table space create time
ts_create_time=2019-9-21 22:37:7
table space modify time
ts_modify_time=2019-9-21 22:37:7
table space encrypt flag
ts_encrypt_flag=0
#-----------------------------------------------file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/SYSTEM.DBF
mirror path
mirror_path=
file id
fil_id=0
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2019-9-21 22:37:7
file modify time
fil_modify_time=2019-9-21 22:37:7
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
#===============================================table space name
ts_name=ROLL
table space ID
ts_id=1
table space status
t$_state=0
table space cache
ts_cache=
RAC node number
ts_nth=0
table space create time
ts_create_time=2019-9-21 22:37:7
table space modify time
ts_modify_time=2019-9-21 22:37:7
table space encrypt flag
ts_encrypt_flag=0
#-----------------------------------------------file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/ROLL.DBF
mirror path
mirror_path=
file id
fil_id=0
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2019-9-21 22:37:7
file modify time
fil_modify_time=2019-9-21 22:37:7
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
#===============================================table space name
ts_name=RLOG
table space ID
ts_id=2
table space status
t$_state=0
table space cache
ts_cache=
RAC node number
ts_nth=0
table space create time
ts_create_time=2019-9-21 22:37:7
table space modify time
ts_modify_time=2019-9-21 22:37:7
table space encrypt flag
ts_encrypt_flag=0
#-----------------------------------------------file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/IESDB01.log
mirror path
mirror_path=
file id
fil_id=0
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2019-9-21 22:37:7
file modify time
fil_modify_time=2019-9-21 22:37:7
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/IESDB02.log
mirror path
mirror_path=
file id
fil_id=1
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2019-9-21 22:37:7
file modify time
fil_modify_time=2019-9-21 22:37:7
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
#===============================================table space name
ts_name=MAIN
table space ID
ts_id=4
table space status
t$_state=0
table space cache
ts_cache=
RAC node number
ts_nth=0
table space create time
ts_create_time=2019-9-21 22:37:8
table space modify time
ts_modify_time=2019-9-21 22:37:8
table space encrypt flag
ts_encrypt_flag=0
#-----------------------------------------------file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/MAIN.DBF
mirror path
mirror_path=
file id
fil_id=0
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2019-9-21 22:37:8
file modify time
fil_modify_time=2019-9-21 22:37:8
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
#===============================================table space name
ts_name=SEMITER
table space ID
ts_id=5
table space status
t$_state=0
table space cache
ts_cache=NORMAL
RAC node number
ts_nth=0
table space create time
ts_create_time=2020-5-26 14:58:40
table space modify time
ts_modify_time=2020-5-26 14:58:49
table space encrypt flag
ts_encrypt_flag=0
#-----------------------------------------------file path
fil_path=/usr/appsoft/dmdbms/data/IESDB/semiter01.dbf
mirror path
mirror_path=
file id
fil_id=0
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2020-5-26 14:58:40
file modify time
fil_modify_time=2020-5-26 14:58:40
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
file path
fil_path=/usr/appsoft/dmdbms/data/semiter02.dbf
mirror path
mirror_path=
file id
fil_id=1
whether the file is auto extend
autoextend=1
file create time
fil_create_time=2020-5-26 14:58:49
file modify time
fil_modify_time=2020-5-26 14:58:49
the max size of file
fil_max_size=0
next size of file
fil_next_size=0
#===============================================HUGE table space name
htsname=HMAIN
HUGE table space id
htsid=0
#HUGE table space share flag
htsflag=0HUGE table space create time
hts_create_time=2019-9-21 22:37:8
HUGE table space modify time
hts_modify_time=2019-9-21 22:37:8
HUGE table space path
htspath=/usr/appsoft/dmdbms/data/IESDB/HMAIN
#===============================================四 重建控制文件
我们可以根据控制文件的内容进行修改,并重建控制文件以完成实际修改。在数据库关闭状态下,我们可以将数据文件移动到其它位置,再修改控制文件中数据文件的路径,然后重建控制文件,来完成数据文件路径的更换。
其实,基本上涉及到路径修改的,都可以通过重建控制文件的方式来完成。
在oracle数据库中,即使控制文件损坏了,可以通过重建的方式来进行恢复,但达梦数据库如果控制文件损坏了,经过实验无法通过这种方式进行恢复;只能通过重建实例,必须相同环境的实例,包括数据库版本、操作系统版本、各种文件路径等。4.1 创建测试环境
1 SEMITER 5 /usr/appsoft/dmdbms/data/TEST/semiter02.dbf 128M
2 SEMITER 5 /usr/appsoft/dmdbms/data/TEST/semiter01.dbf 128M
已用时间: 2.918(毫秒). 执行号:19.4.2 关闭实例并转换控制文件为文本文件
1.关闭数据库实例:
[ data]# /etc/init.d/DmServiceTEST stop
Stopping DmServiceTEST: [ OK ]
2.转换控制文件
[ usr]$ dmctlcvt type=1 src=/usr/appsoft/dmdbms/data/TEST/dm.ctl dest=/tmp/semiter.txt
DMCTLCVT V7.6.0.171-Build(2019.07.02-109059)ENT
convert ctl to txt succes$!4.3 拷贝数据文件到新的路径
[ TEST]$ pwd
/usr/appsoft/dmdbms/data/TEST
[m3 TEST]$ mv semiter02.dbf ../4.4 修改文本文件中数据文件路径到新路径并重建控制文件
[ IESDB]$ cat /tmp/semiter.txt |grep semiter02.dbf
fil_path=/usr/appsoft/dmdbms/data/semiter02.dbf[ IESDB]$ dmctlcvt type=2 src=/tmp/semiter.txt dest=/usr/appsoft/dmdbms/data/IESDB/dm.ctl
DMCTLCVT V7.6.0.171-Build(2019.07.02-109059)ENT
convert txt to ctl succe$s!
[ IESDB]$4.5 启动数据库并进行验证
[ IESDB]$ /etc/init.d/DmServiceIESDB start
Starting DmServiceIESDB: [ OK ]SQL> select t.name tablespace_name,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 and t.name=‘SEMITER‘;
行号 tablespace_name file_id file_name total_space
1 SEMITER 5 /usr/appsoft/dmdbms/data/semiter02.dbf 128M
2 SEMITER 5 /usr/appsoft/dmdbms/data/IESDB/semiter01.dbf 128M
已用时间: 9.828(毫秒). 执行号:4.
从上面的输出中可以明显看到,semiter02.dbf的路径已经更改,至此我们就完成了达梦数据库下数据文件路径的修改。