达梦数据库如何查看、重建控制文件

一、 查看控制文件内容

控制文件是一个二进制文件,它记录了数据库必要的初始信息,其中主要包含以下内容:

  • 数据库名称;
  • 数据库服务器模式;
  • OGUID 唯一标识;
  • 数据库服务器版本;
  • 数据文件版本;
  • 数据库的启动次数;
  • 数据库最近一次启动时间;
  • 表空间信息,包括表空间名,表空间物理文件路径等,记录了所有数据库中使用的表空间,数组的方式保存起来;
  • 控制文件校验码,校验码由数据库服务器在每次修改控制文件后计算生成,保证控制文件合法性,防止文件损坏及手工修改。

DM 数据库控制文件的位置是在dm.ini 文件中指定:

[dmdba@localhost dmdba]$ more dm.ini|grep CTL
        CTL_PATH                        = /dm/dmdbms/data/cndba/dm.ctl     #ctl file path
        CTL_BAK_PATH                    = /dm/dmdbms/data/cndba/ctl_bak    #dm.ctl backup path
        CTL_BAK_NUM                     = 10                       #backup number of dm.ctl, allowed to keep one more backup file besides specified number.
        RAC_N_CTLS                      = 10000                 #Number Of LBS/GBS ctls
[dmdba@localhost dmdba]$

我们可以利用dmctlcvt工具将二进制的文件转化成文本文件:

[dmdba@localhost bin]$ find /dm -name dmctlcvt
/dm/dmdbms/bin/dmctlcvt
[dmdba@localhost bin]$ dmctlcvt -help
DMCTLCVT V7.6.0.95-Build(2018.09.13-97108)ENT 

Format:  ./dmctlcvt KEYWORD=value
Note:    ctl file name must be dm.ctl or dmmpp.ctl or dmwatcher.ctl

Keyword             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 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
./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

[dmdba@localhost bin]$ 

[dmdba@localhost dmdba]$ find /dm -name *.ctl
/dm/dmdbms/data/cndba/dm.ctl

生成文本文件:

[dmdba@localhost dmdba]$ dmctlcvt type=1 src=/dm/dmdbms/data/cndba/dm.ctl dest=/tmp/cmctl.txt
DMCTLCVT V7.6.0.95-Build(2018.09.13-97108)ENT 
Can not open ini file !
convert ctl to txt success!
[dmdba@localhost dmdba]$

控制文件的完整内容如下:

[dmdba@localhost dmdba]$ cat /tmp/cmctl.txt 
##############################################################################
## please do not adjust parameter order, ensure the ctl have no difference ###
##########################################################################


# database name
dbname=cndba
# server mode
svr_mode=0
#OGUID
oguid=0
# db server version
version=117507679
# database version
db_version=458762
# pseg version
pseg_version=458762
#SGUID
sguid=-153990972
#NEXT_TS_ID
next_ts_id=10
#RAC_NODES
rac_nodes=0
#NEXT_HTS_ID
next_htsid=1
#TIME_FLAG
time_flag=170
#STARTUP_CNT
startup_cnt=2
#LAST_STARTUP_TIME
last_startup_time=2019-8-27 12:4:28

#===============================================
#===============================================

# table space name
ts_name=SYSTEM
 # table space ID
ts_id=0
# table space status
ts_state=0
# table space cache
ts_cache=
# RAC node number
ts_nth=0
# table space create time
ts_create_time=2029-2-23 22:49:38
# table space modify time
ts_modify_time=2029-2-23 22:49:38
# table space encrypt flag
ts_encrypt_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/dmdbms/data/cndba/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=2029-2-23 22:49:38
# file modify time
fil_modify_time=2029-2-23 22:49:38
# 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
ts_state=0
# table space cache
ts_cache=
# RAC node number
ts_nth=0
# table space create time
ts_create_time=2029-2-23 22:49:38
# table space modify time
ts_modify_time=2029-2-23 22:49:38
# table space encrypt flag
ts_encrypt_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/dmdbms/data/cndba/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=2029-2-23 22:49:38
# file modify time
fil_modify_time=2029-2-23 22:49:38
# 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
ts_state=0
# table space cache
ts_cache=
# RAC node number
ts_nth=0
# table space create time
ts_create_time=2029-2-23 22:49:38
# table space modify time
ts_modify_time=2029-2-23 22:49:38
# table space encrypt flag
ts_encrypt_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/dmdbms/data/cndba/cndba01.log
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=2029-2-23 22:49:38
# file modify time
fil_modify_time=2029-2-23 22:49:38
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0

# file path
fil_path=/dm/dmdbms/data/cndba/cndba02.log
# mirror path
mirror_path=
# file id
fil_id=1
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=2029-2-23 22:49:38
# file modify time
fil_modify_time=2029-2-23 22:49:38
# 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
ts_state=0
# table space cache
ts_cache=
# RAC node number
ts_nth=0
# table space create time
ts_create_time=2029-2-23 22:49:39
# table space modify time
ts_modify_time=2029-2-23 22:49:39
# table space encrypt flag
ts_encrypt_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/dmdbms/data/cndba/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=2029-2-23 22:49:39
# file modify time
fil_modify_time=2029-2-23 22:49:39
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0


#===============================================

# table space name
ts_name=DAVE
 # table space ID
ts_id=9
# table space status
ts_state=0
# table space cache
ts_cache=NORMAL
# RAC node number
ts_nth=0
# table space create time
ts_create_time=2029-2-24 11:17:31
# table space modify time
ts_modify_time=2029-2-24 11:17:31
# table space encrypt flag
ts_encrypt_flag=0

#-----------------------------------------------

# file path
fil_path=/dm/dmdbms/data/cndba/DAVE01.DBF
# mirror path
mirror_path=
# file id
fil_id=0
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=2029-2-24 11:17:31
# file modify time
fil_modify_time=2029-2-24 11:17:31
# the max size of file
fil_max_size=0
# next size of file
fil_next_size=0

# file path
fil_path=/dm/dmdbms/data/cndba/DAVE02.DBF
# mirror path
mirror_path=
# file id
fil_id=1
# whether the file is auto extend
autoextend=1
# file create time
fil_create_time=2029-2-24 11:17:31
# file modify time
fil_modify_time=2029-2-24 11:17:31
# 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=0
# HUGE table space create time
hts_create_time=2029-2-23 22:49:39
# HUGE table space modify time
hts_modify_time=2029-2-23 22:49:39
# HUGE table space path
htspath=/dm/dmdbms/data/cndba/HMAIN

#===============================================

[dmdba@localhost dmdba]$

二 重建控制文件

有了上面的内容之后,就可以根据这些内容,重建控制文件了。比如在DB关闭的情况下,我们可以将数据文件移动到其他位置,在修改控制文件中数据文件的对应位置,才重新生成控制文件。 基本上涉及路劲的修改,都可以采用这种重建控制文件当时进行。
  但是通过观察上节控制文件的内容,DM的控制文件和Oracle的控制文件还是有很大区别。 在Oracle中,在控制文件全部损坏的情况下,可以通过固定的语法来创建新的控制文件,但在DM中,这样操作感觉有点困难。

按DM刚说的规则,我们通过重建控制的方式,更改一下数据文件的位置。

#停库,并重新生成控制文件的文本:
[dmdba@localhost dmdba]$ service DmServicedave stop
Stopping DmServicedave:                                    [ OK ]
[dmdba@localhost dmdba]$ dmctlcvt type=1 src=/dm/dmdbms/data/cndba/dm.ctl dest=/tmp/dmctl.txt
DMCTLCVT V7.6.0.95-Build(2018.09.13-97108)ENT 
Can not open ini file !
convert ctl to txt success!
[dmdba@localhost dmdba]$ 


#移动Dave表空间数据文件的位置:
[dmdba@localhost dmdba]$ pwd
/dm/dmdbms/data/cndba
[dmdba@localhost dmdba]$ mv DAVE02.DBF ../
[dmdba@localhost dmdba]$ ls ../
cndba  DAVE02.DBF
[dmdba@localhost dmdba]$ ls
bak           dmarch_example.ini     dminit20290223224934.log  dm_service.prikey      MAIN.DBF            TEMP.DBF
BOOKSHOP.DBF  dm.ctl                 dminit_example.ini        dmtimer_example.ini    rep_conflict.log    trace
cndba01.log   dmdcr_cfg_example.ini  dminst.sys                dmwatcher_example.ini  ROLL.DBF
cndba02.log   dmdcr_example.ini      dmmal_example.ini         dmwatch_example.ini    sqllog_example.ini
ctl_bak       DMHR.DBF               dmmonitor_example.ini     dmwmon_example.ini     sqllog.ini
DAVE01.DBF    dm.ini                 dmmpp_example.ini         HMAIN                  SYSTEM.DBF
[dmdba@localhost dmdba]$ 


#修改文本中对应文件的位置:
[dmdba@localhost dmdba]$ cat /tmp/dmctl.txt |grep DAVE02
fil_path=/dm/dmdbms/data/DAVE02.DBF
[dmdba@localhost dmdba]$ 

#重建控制文件:
[dmdba@localhost dmdba]$ dmctlcvt type=2 src=/tmp/dmctl.txt dest=/dm/dmdbms/data/cndba/dm.ctl
DMCTLCVT V7.6.0.95-Build(2018.09.13-97108)ENT 
Can not open ini file !
convert txt to ctl success!
[dmdba@localhost dmdba]$ 

#起库验证:修改数据文件位置成功
[dmdba@localhost dmdba]$ service DmServicedave start
Starting DmServicedave:                                    [ OK ]
[dmdba@localhost dmdba]$ 

SQL>  select tablespace_name, file_name, status from dba_data_files order by 1;

Server[192.168.20.191:5236]:mode is normal, state is open
connected

LINEID     TABLESPACE_NAME FILE_NAME                          STATUS   
---------- --------------- ---------------------------------- ---------
1          BOOKSHOP        /dm/dmdbms/data/cndba/BOOKSHOP.DBF AVAILABLE
2          DAVE            /dm/dmdbms/data/DAVE02.DBF         AVAILABLE
3          DAVE            /dm/dmdbms/data/cndba/DAVE01.DBF   AVAILABLE
4          DMHR            /dm/dmdbms/data/cndba/DMHR.DBF     AVAILABLE
5          MAIN            /dm/dmdbms/data/cndba/MAIN.DBF     AVAILABLE
6          ROLL            /dm/dmdbms/data/cndba/ROLL.DBF     AVAILABLE
7          SYSTEM          /dm/dmdbms/data/cndba/SYSTEM.DBF   AVAILABLE
8          TEMP            /dm/dmdbms/data/cndba/TEMP.DBF     AVAILABLE

8 rows got

used time: 17.841(ms). Execute id is 3.
SQL>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值