
达梦数据库教程(10)达梦数据库控制文件介绍
一、达梦数据库控制文件介绍
达梦数据库在初始化完成后会为每个实例创建一个名为 dm.ctl 的二进制控制文件。该文件记录了数据库必要的初始信息,如果缺少该文件,数据库无法正常运行,该配置文件的路径通过初始化参数指定
bin/dminit help|grep -i CTL # CTL_PATH 控制文件路径例如:CTL_PATH=/data/dmdbms/DAMENG/dm.ctl
当数据库执行表空间 DDL 等操作后会同步修改控制文件内容。为了避免修改过程中数据库或者服务器出现故障导致控制文件损坏,所以会自动进行备份操作,备份路径通过 CTL_BAK_PATH 参数指定,备份策略如下:
· 修改 dm.ctl 之前先执行一次备份,等 dm.ctl 修改成功后自动将备份删除,如果 dm.ctl 修改失败或中途出现故障,则保留备份文件。
· 修改 dm.ctl 成功之后,根据 dm.ini 中指定的 CTL_BAK_PATH/CTL_BAK_NUM 对最新的 dm.ctl 执行备份,生成备份文件时根据指定的 CTL_BAK_NUM 判断是否删除老的备份文件。如果指定的 CTL_BAK_PATH 是非法路径,则不再生成备份文件。
二、查看控制文件参数
1、通过show parameter语句查看
SQL> show parameter CTL
2、通过v$parameter视图查看
SQL> select name,type,value,default_value,isdefault from v$parameter where name like '%CTL%';
三、控制文件转储
由于控制文件是二进制格式,无法直接查看。所以需要先转储为普通文本格式,使用到的工具是dmctlcvt。该工具可以将存储文件转换为文本或者将文本转回为控制文件,在进行转储时控制文件名称必须为dm.ctl、dmmpp.ctl、dss.ctl
1、dmctlcvt语法格式
主要通过type来决定转换的方向,TYPE=1表示转换控制文件为文本文件;TYPE=2转换文本文件为控制文件
./dmctlcvt TYPE=[1,2] SRC=源文件路径 DEST=目标文件路径
2、dmctlcvt示例
· 将控制文件转储为文本
./dmctlcvt TYPE=1 SRC=/data/dmdbms/DAMENG/dm.ctl DEST=/tmp/dmctl.txt
· 将文本转储为控制文件
./dmctlcvt TYPE=2 SRC=/opt/dmdbms/data/dameng/dmctl.txt DEST=/opt/dmdbms/data/dameng/dm.ctl
3、查看转储文件内容
[dmdba@centos1 bin]$ cat /tmp/dmctl.txt ############################################################################## ## please do not adjust parameter order, ensure the ctl have no difference ### ########################################################################## # database name dbname=DAMENG #数据库名 # server mode svr_mode=0 #数据库服务器模式 #OGUID oguid=0 #OGUID 唯一标识 # db server version version=134284368 # database version db_version=458765 # pseg version pseg_version=458763 #SGUID sguid=2046675788 #NEXT_TS_ID next_ts_id=6 #DSC_NODES dsc_nodes=1 #NEXT_HTS_ID next_htsid=129 #TIME_FLAG time_flag=170 #MDIR_FLAG mdir_flag=31 #STARTUP_CNT startup_cnt=3 #数据库启动次数 #LAST_STARTUP_TIME last_startup_time=DATETIME '2025-06-09 21:13:05' #数据库最后一次启动时间 #DM7_DCT_VERSION dm7_dct_version=11 #DM8_DCT_VERSION dm8_dct_version=113 #=============================================== #=============================================== # table space name ts_name=SYSTEM # table space ID ts_id=0 # table space status ts_state=0 # table space cache ts_cache= # DSC node number ts_nth=0 # DSC optimized node number ts_opt_node=0 # table space quota state ts_quota_state=0 # table space create time ts_create_time=DATETIME '2025-06-03 07:27:22' # table space modify time ts_modify_time=DATETIME '2025-06-03 07:27:22' # table space encrypt flag ts_encrypt_flag=0 # table space copy num ts_copy_num=3 # table space region size flag ts_size_flag=0 # table space region huge size flag ts_huge_size_flag=0 #----------------------------------------------- # file path fil_path=/data/dmdbms/DAMENG/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=DATETIME '2025-06-03 07:27:22' # file modify time fil_modify_time=DATETIME '2025-06-03 07:27:22' # the max size of file fil_max_size=0 # next size of file fil_next_size=0 # whether the file is in creating fil_in_creating=0 #=============================================== # table space name ts_name=ROLL # table space ID ts_id=1 # table space status ts_state=0 # table space cache ts_cache= # DSC node number ts_nth=0 # DSC optimized node number ts_opt_node=0 # table space quota state ts_quota_state=0 # table space create time ts_create_time=DATETIME '2025-06-03 07:27:22' # table space modify time ts_modify_time=DATETIME '2025-06-03 07:27:22' # table space encrypt flag ts_encrypt_flag=0 # table space copy num ts_copy_num=3 # table space region size flag ts_size_flag=0 # table space region huge size flag ts_huge_size_flag=0 #----------------------------------------------- # file path fil_path=/data/dmdbms/DAMENG/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=DATETIME '2025-06-03 07:27:22' # file modify time fil_modify_time=DATETIME '2025-06-03 07:27:22' # the max size of file fil_max_size=0 # next size of file fil_next_size=0 # whether the file is in creating fil_in_creating=0 #=============================================== # table space name ts_name=RLOG # table space ID ts_id=2 # table space status ts_state=0 # table space cache ts_cache= # DSC node number ts_nth=0 # DSC optimized node number ts_opt_node=0 # table space quota state ts_quota_state=0 # table space create time ts_create_time=DATETIME '2025-06-03 07:27:22' # table space modify time ts_modify_time=DATETIME '2025-06-03 07:27:22' # table space encrypt flag ts_encrypt_flag=0 # table space copy num ts_copy_num=0 # table space region size flag ts_size_flag=0 # table space region huge size flag ts_huge_size_flag=0 #----------------------------------------------- # file path fil_path=/data/dmdbms/DAMENG/DAMENG01.log # mirror path mirror_path= # file id fil_id=0 # whether the file is auto extend autoextend=1 # file create time fil_create_time=DATETIME '2025-06-03 07:27:22' # file modify time fil_modify_time=DATETIME '2025-06-03 07:27:22' # the max size of file fil_max_size=0 # next size of file fil_next_size=0 # whether the file is in creating fil_in_creating=0 # file path fil_path=/data/dmdbms/DAMENG/DAMENG02.log # mirror path mirror_path= # file id fil_id=1 # whether the file is auto extend autoextend=1 # file create time fil_create_time=DATETIME '2025-06-03 07:27:22' # file modify time fil_modify_time=DATETIME '2025-06-03 07:27:22' # the max size of file fil_max_size=0 # next size of file fil_next_size=0 # whether the file is in creating fil_in_creating=0 #=============================================== # table space name ts_name=MAIN # table space ID ts_id=4 # table space status ts_state=0 # table space cache ts_cache= # DSC node number ts_nth=0 # DSC optimized node number ts_opt_node=0 # table space quota state ts_quota_state=1 # table space create time ts_create_time=DATETIME '2025-06-03 07:27:22' # table space modify time ts_modify_time=DATETIME '2025-06-03 07:27:22' # table space encrypt flag ts_encrypt_flag=0 # table space copy num ts_copy_num=3 # table space region size flag ts_size_flag=0 # table space region huge size flag ts_huge_size_flag=0 #----------------------------------------------- # file path fil_path=/data/dmdbms/DAMENG/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=DATETIME '2025-06-03 07:27:22' # file modify time fil_modify_time=DATETIME '2025-06-03 07:27:22' # the max size of file fil_max_size=0 # next size of file fil_next_size=0 # whether the file is in creating fil_in_creating=0 #----------------------------------------------- # huge path huge_path=/data/dmdbms/DAMENG/HMAIN # huge path create time huge_create_time=DATETIME '2025-06-03 07:27:22' # huge path modify time huge_modify_time=DATETIME '2025-06-03 07:27:22' #=============================================== # table space name ts_name=YWPIE #表空间信息,这里是自建的YWPIE表空间和相关信息 # table space ID ts_id=5 # table space status ts_state=0 # table space cache ts_cache=NORMAL # DSC node number ts_nth=0 # DSC optimized node number ts_opt_node=0 # table space quota state ts_quota_state=1 # table space create time ts_create_time=DATETIME '2025-06-09 05:59:23' # table space modify time ts_modify_time=DATETIME '2025-06-09 05:59:23' # table space encrypt flag ts_encrypt_flag=0 # table space copy num ts_copy_num=0 # table space region size flag ts_size_flag=0 # table space region huge size flag ts_huge_size_flag=0 #----------------------------------------------- # file path fil_path=/data/dmdbms/DAMENG/YWPIE01.DBF # mirror path mirror_path= # file id fil_id=0 # whether the file is auto extend autoextend=1 # file create time fil_create_time=DATETIME '2025-06-09 05:59:23' # file modify time fil_modify_time=DATETIME '2025-06-09 05:59:23' # the max size of file fil_max_size=0 # next size of file fil_next_size=128 # whether the file is in creating fil_in_creating=0 #===============================================
四、控制文件实际的运用
1、通过控制文件修改数据文件的路径
· 非控制文件修改数据文件路径的方法
#脱机 SQL> ALTER TABLESPACE YWPIE OFFLINE; #修改路径 SQL> ALTER TABLESPACE YWPIE RENAME DATAFILE '/data/dmdbms/ywpie/ywpie01.dbf' TO '/dm8/data/ywpie/ywpie01.dbf'; #联机 SQL> ALTER TABLESPACE YWPIE ONLINE;
· 使用控制文件修改数据文件路径的方法
# 停库 SQL> shutdown immediate; # 转储控制文件为文本 cp /data/dmdbms/DAMENG/dm.ctl /data/dmdbms/DAMENG/dm.ctl.bak dmctlcvt TYPE=1 SRC=/data/dmdbms/DAMENG/dm.ctl DEST=/tmp/dmctl.txt #修改文本文件内容 vi /dm8/tmp/20250306_dmctl.txt fil_path=新地址 #迁移数据文件 mv /data/dmdbms/ywpie/ywpie01.dbf /dm8/data/ywpie/ywpie01.dbf # 转储文本为二进制 dmctlcvt TYPE=2 SRC=/tmp/dmctl.txt DEST=/data/dmdbms/DAMENG/dm.ctl # 启动数据库后验证 SQL> select TABLESPACE_NAME,FILE_ID,FILE_NAME,STATUS from dba_data_files
2、控制文件异常的恢复
· 模拟控制文件损坏
mv /data/dmdbms/DAMENG/dm.ctl /data/dmdbms/DAMENG/dm.ctl.bak
· 此时备份无法正常运行,切换表空间导致数据库异常崩溃
alter tablespace cjc datafile '/data/dmdbms/ywpie/ywpie01.dbf' autoextend on maxsize 1024; 报错:连接丢失 实例自动中断,日志如下: 2025-03-06 09:39:12.870 [ERROR] database P0000020622 T0000000000000022139 os_file_open_normal_rw error! path: '/data/dmdbms/DAMENG/dm.ctl', code: 2, desc: No such file or directory 2025-03-06 09:39:12.870 [ERROR] database P0000020622 T0000000000000022139 os_file_open_normal_rd error! path: '/data/dmdbms/DAMENG/dm.ctl', code: 2, desc: No such file or directory 2025-03-06 09:39:12.870 [FATAL] database P0000020622 T0000000000000022139 [for dem]SYSTEM SHUTDOWN ABORT. 2025-03-06 09:39:12.870 [FATAL] database P0000020622 T0000000000000022139 ctl_info_get failed! check if dm.ctl is exist? check dmserver user has privilege to access dm.ctl? maybe can repair it by backup control file dm.ctl.bak in ctl_path or system_path 2025-03-06 09:39:12.870 [INFO] database P0000020622 T0000000000000022139 total 2 rfil opened!
· 查看控制文件自动备份
ls -lrth /dm8/data/ctl_bak/ -rw-r--r-- 1 dmdba dinstall 6.0K Mar 5 16:15 dm_20250305161500_934284.ctl -rw-r--r-- 1 dmdba dinstall 6.0K Mar 5 16:49 dm_20250305164947_819619.ctl -rw-r--r-- 1 dmdba dinstall 6.0K Mar 5 17:35 dm_20250305173551_791733.ctl
· 通过备份文件恢复控制文件
cp /dm8/data/ctl_bak/dm_20250305173551_791733.ctl /data/dmdbms/DAMENG/dm.ctl
· 启动数据库验证
disql SYSDBA/******:5236 服务器[LOCALHOST:5238]:处于普通打开状态 登录使用时间 : 3.077(ms) disql V8
· 再次调整控制文件,可以正常执行
SQL> alter tablespace cjc datafile '/dm8/data/cjc/tmp/cjctbs01.dbf' autoextend on maxsize 1024;
文章评论