签到成功

知道了

CNDBA社区CNDBA社区

DM7 达梦数据库 查看并重建控制文件 操作示例

2019-08-27 15:50 1080 0 原创 DM 达梦
作者: Dave

1 查看控制文件内容

在之前的博客里我们了解到了控制文件:https://www.cndba.cn/dave/article/3574

https://www.cndba.cn/dave/article/3574

DM7 达梦数据库 物理结构 说明
https://www.cndba.cn/dave/article/3571https://www.cndba.cn/dave/article/3574

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

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

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

https://www.cndba.cn/dave/article/3574
https://www.cndba.cn/dave/article/3574

[dave@www.cndba.cn cndba]$ 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
[dave@www.cndba.cn cndba]$

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

[dave@www.cndba.cn bin]$ find /dm -name dmctlcvt
/dm/dmdbms/bin/dmctlcvt
[dave@www.cndba.cn 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

[dave@www.cndba.cn bin]$ 

[dave@www.cndba.cn cndba]$ find /dm -name *.ctl
/dm/dmdbms/data/cndba/dm.ctl

生成文本文件:

[dave@www.cndba.cn cndba]$ 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!
[dave@www.cndba.cn cndba]$

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

https://www.cndba.cn/dave/article/3574
https://www.cndba.cn/dave/article/3574

[dave@www.cndba.cn cndba]$ 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

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

[dave@www.cndba.cn cndba]$

2 重建控制文件

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

按DM刚说的规则,我们通过重建控制的方式,更改一下数据文件的位置。 https://www.cndba.cn/dave/article/3574https://www.cndba.cn/dave/article/3574

#停库,并重新生成控制文件的文本:
[dave@www.cndba.cn cndba]$ service DmServicedave stop
Stopping DmServicedave:                                    [ OK ]
[dave@www.cndba.cn cndba]$ 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!
[dave@www.cndba.cn cndba]$ 


#移动Dave表空间数据文件的位置:
[dave@www.cndba.cn cndba]$ pwd
/dm/dmdbms/data/cndba
[dave@www.cndba.cn cndba]$ mv DAVE02.DBF ../
[dave@www.cndba.cn cndba]$ ls ../
cndba  DAVE02.DBF
[dave@www.cndba.cn cndba]$ 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
[dave@www.cndba.cn cndba]$ 


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

#重建控制文件:
[dave@www.cndba.cn cndba]$ 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!
[dave@www.cndba.cn cndba]$ 

#起库验证:修改数据文件位置成功
[dave@www.cndba.cn cndba]$ service DmServicedave start
Starting DmServicedave:                                    [ OK ]
[dave@www.cndba.cn cndba]$ 

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>

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Dave

Dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 1835
    原创
  • 2
    翻译
  • 423
    转载
  • 123
    评论
  • 访问:3272741次
  • 积分:2903
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by ZhiXinTech · 皖ICP备19020168号·

        QQ交流群