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

本文详细介绍了达梦数据库控制文件的内容,包括数据库名称、版本、表空间信息等,并演示了如何使用dmctlcvt工具将控制文件转换为文本格式,以便于理解和编辑。此外,还介绍了如何通过修改控制文件文本内容,实现数据文件位置的变更。

一、 查看控制文件内容

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

  • 数据库名称;
  • 数据库服务器模式;
  • 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>
<think>嗯,用户想在达梦数据库重建备库,我需要详细回答操作步骤。首先,我得回忆一下达梦数据库的相关知识,尤其是备库重建的流程。根据之前学过的内容,达梦数据库是基于主备架构的,重建备库通常涉及数据备份、配置参数、同步数据等步骤。 首先,用户可能需要停止当前的备库服务,防止在重建过程中出现数据冲突。我记得在引用[3]中有提到数据库安装和用户权限的设置,可能需要使用dmdba用户来执行相关操作。所以停止备库应该用systemctl命令或者直接调用服务脚本。 接下来,主库需要生成备份。这里要用到达梦的RMAN工具,对吗?主库执行全量备份,生成备份文件,并记录归档日志信息。备份路径可能需要指定,比如/data/backup,同时备份完成后要备份归档日志,确保数据一致性。这部分需要确保主库处于归档模式,并且备份正确完成。 然后,用户需要将备份文件传输到备库服务器。使用scp或者rsync命令,确保备库有正确的目录结构,并且权限设置正确,比如chown给dmdba用户。这部分可能需要参考引用[3]中的目录创建和权限设置步骤。 接下来是备库的还原与恢复。使用dmrman工具,执行restore和recover命令,指定备份文件和目标库路径。这里需要注意主库和备库的实例名是否一致,可能需要调整dm.ini配置文件中的参数,比如INSTANCE_NAME。引用[3]中的配置步骤可能会有帮助。 然后是配置主备同步,修改dm.ini和dmmal.ini文件,设置MAL系统和守护进程配置。这部分可能需要引用[2]中的索引创建例子,但这里更多是配置文件的调整。需要确保主库和备库的MAL_INST_HOST、MAL_PORT等参数正确,避免网络连接问题。 启动备库到mount状态,并设置OGUID,开启守护进程。这里可能需要使用SQL语句ALTER DATABASE MOUNT和MODIFY DATABASE ADD STANDBY LOGFILE。然后启动守护进程,确保同步正常。 最后验证同步状态,查询V$ARCH_STATUS和V$RLOG视图,确认数据是否一致。如果遇到问题,可能需要检查网络、权限、配置文件是否正确,以及日志中的错误信息。 用户可能遇到的问题包括备份失败、网络传输问题、配置文件错误、权限不足等,需要逐一排查。例如,备份时如果路径不存在,需要先创建目录;传输文件时如果权限不对,会导致备库无法访问备份文件;配置文件中的端口冲突也会导致同步失败。 另外,用户可能不知道如何正确使用dmrman工具,或者如何设置OGUID,这些都需要在步骤中详细说明。引用[1]提到了性能优化,可能在重建备库后,用户还需要考虑创建索引来提升查询效率,但这个问题可能属于后续优化步骤,不是当前的重点。 总结下来,重建备库的流程包括停止服务、备份主库、传输备份、还原恢复、配置同步、启动备库和验证状态。需要确保每一步都正确执行,并且配置文件参数无误。如果用户按照步骤操作,应该能够成功重建备库。同时,要提醒用户注意权限和路径问题,这些都是常见的错误点。</think>### 达梦数据库重建备库操作指南 #### 一、准备工作 1. **停止当前备库服务** 若备库正在运行,需先停止服务: ```bash systemctl stop DmServiceStandby # 根据实际服务名调整 ``` 2. **主库生成全量备份** 使用达梦RMAN工具对主库执行全量备份: ```bash dmrman CTLSTMT="BACKUP DATABASE FULL TO BACKUP_NAME BACKUPSET '/data/backup/full_bak'" ``` 备份完成后,记录归档日志位置: ```sql ALTER SYSTEM ARCHIVE LOG CURRENT; -- 强制切换归档日志[^3] ``` 3. **传输备份文件到备库服务器** 将主库备份文件复制到备库服务器相同路径: ```bash scp -r /data/backup/full_bak standby_server:/data/backup/ ``` --- #### 二、重建备库操作步骤 1. **还原数据库** 在备库服务器使用`dmrman`工具还原数据库: ```bash dmrman CTLSTMT="RESTORE DATABASE '/dm/data/DAMENG/dm.ini' FROM BACKUPSET '/data/backup/full_bak'" ``` 2. **恢复数据库到最新状态** 执行恢复命令并应用归档日志: ```bash dmrman CTLSTMT="RECOVER DATABASE '/dm/data/DAMENG/dm.ini' FROM BACKUPSET '/data/backup/full_bak' WITH ARCHIVEDIR '/data/arch'" ``` 3. **更新数据库模式** 修改备库实例为`Standby`模式: ```sql ALTER DATABASE MODIFY STANDBY; -- 通过SQL命令行工具执行[^1] ``` 4. **配置主备同步参数** 编辑备库的`dm.ini`文件,确保以下参数与主库匹配: ```ini INSTANCE_NAME = Standby MAL_INST_HOST = 192.168.1.100 # 主库IP MAL_INST_PORT = 5266 ``` 5. **启动备库服务** ```bash systemctl start DmServiceStandby ``` --- #### 三、验证同步状态 1. **查询主备同步状态** 在主库执行: ```sql SELECT * FROM V$ARCH_STATUS; -- 查看归档发送状态[^2] ``` 2. **检查备库数据一致性** 在备库执行: ```sql SELECT * FROM V$RLOG; -- 验证日志应用进度 ``` --- #### 四、常见问题处理 1. **备份文件权限问题** 确保备库用户`dmdba`对备份目录有读写权限: ```bash chown -R dmdba:dinstall /data/backup # 参考权限设置[^3] ``` 2. **网络连通性检查** 使用`telnet`验证主备端口(如`5266`)是否开放。 3. **日志不连续错误** 若出现归档缺失,需手动补充缺失的归档文件。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值