签到成功

知道了

CNDBA社区CNDBA社区

linux 平台 达梦DM 7 数据库 启动与关闭

2019-08-26 11:34 15074 0 原创 DM 达梦
作者: dave

在之前的博客我们了解了Linux 平台下DM7的安装,如下:

Linux 平台 达梦 DM7 单实例 安装手册 详细截图版
https://www.cndba.cn/dave/article/3565

在本篇博客里我们了解一下DM7的启动和关闭。

1 背景知识说明

1.1 DM DB的启动过程

DM的启动主要按如下三个步骤进行:

1.读取配置文件(.ini)
2.读取控制文件(dm.ctl)
3.读取重做日志文件(
.log) 和 数据文件(*.DBF)

1.2 DM DB的状态

DM 数据库包含以下几种状态:

  1. 配置状态(MOUNT):不允许访问数据库对象,只能进行控制文件维护、归档配置、数据库模式修改等操作;
  2. 打开状态(OPEN):不能进行控制文件维护、归档配置等操作,可以访问数据库对象,对外提供正常的数据库服务;
  3. 挂起状态(SUSPEND):与 OPEN 状态的唯一区别就是,限制磁盘写入功能;一旦修改了数据页,触发 REDO 日志、数据页刷盘,当前用户将被挂起。
    OPEN 状态与 MOUNT 和 SUSPEND 能相互转换,但是 MOUNT 和 SUSPEND 之间不能相互转换。

1.3 DM DB的模式

DM 数据库包含以下几种模式:

  1. 普通模式(NORMAL):用户可以正常访问数据库,操作没有限制;
  2. 主库模式(PRIMARY):用户可以正常访问数据库,所有对数据库对象的修改强制生成 REDO 日志,在归档有效时,发送 REDO 日志到备库;
  3. 备库模式(STANDBY):接收主库发送过来的 REDO 日志并重做。数据对用户只读。

三种模式只能在 MOUNT 状态下设置,模式之间可以相互转换。
对于新初始化的库,首次启动不允许使用 mount 方式,需要先正常启动并正常退出,然后才允许 mount 方式启动。
一般情况下,数据库为 NORMAL 模式,如果不指定 MOUNT 状态启动,则自动启动到 OPEN 状态。
在需要对数据库配置时(如配置数据守护、数据复制),服务器需要指定 MOUNT 状态启动。当数据库模式为非 NORMAL 模式(PRIMARY、STANDBY 模式),无论是否指定启动状态,服务器启动时自动启动到 MOUNT 状态。http://www.cndba.cn/cndba/dave/article/3566

1.4 DM DB的三种启动和关闭方式

启动和关闭DM DB有三种方式:

1.4.1 DM服务查看器

Windows可以通过菜单目录查看。 Linux 平台需要运行/dm/dmdbms/tool/dmservice.sh 启动。 如下图:

1.4.2 系统服务

在实例安装结束之后会创建,在操作系统直接对实例服务进行操作。Windows 则是直接在服务窗口进行。http://www.cndba.cn/cndba/dave/article/3566

启动:systemctl start DmServicedave.service
关闭:systemctl stop DmServicedave.service

我这里的测试平台是Linux7, Linux 6和 7 的在服务这块有一点区别:

http://www.cndba.cn/cndba/dave/article/3566

在Linux 6中,服务是放在/etc/rc.d/init.d目录下,会有一个”DmService+实例名”的文件服务文件,启动和关闭是执行service “DmServer+实例名” stop|start。
在Linux 7中,服务文件存放在/usr/lib/systemd/system目录下,名称改成:DmServicedave.service。http://www.cndba.cn/cndba/dave/article/3566

1.4.3 命令行模式

命令行模式使用dmserver命令来启动和关闭实例。该命令在DM_HOME/bin目录下。

命令行方式启动参数如下:http://www.cndba.cn/cndba/dave/article/3566

dmserver [ini_file_path] [-noconsole] [mount]
说明:
1. Dmserver 命令行启动参数可指定 dm.ini 文件的路径,非控制台方式启动及指定数据库是否以 MOUNT 状态启动。
2. Dmserver 启动时可不指定任何参数,默认使用当前目录下的 dm.ini 文件,如果当前目录不存在 dm.ini 文件,则无法启动;
3. Dmserver 启动时可以指定-noconsole 参数。如果以此方式启动,则无法通过在控制台中输入服务器命令。 

当不确定启动参数的使用方法时,可以使用 help 参数,将打印出格式、参数说明和使用示例。使用方法如下: 
dmserver help 
当以控制台方式启动 Dmserver 时,用户可以在控制台输入一些命令,服务器将在控制台打印出相关信息或执行相关操作。

1.4.4 命令行方式和其他两种方式的区别

命令行方式默认也是将数据库启动到open状态,但也可以在启动时指定启动到mount状态,从而可以维护开文件、进程归档配置、数据库普通模式或主备机模式切换等操作。 在进行备份恢复时也常用命令行模式启动。

2 操作示例

2.1 查看DM DB的状态

DB的状态通过DM服务查看器可以直接看到,也可以通过查看系统服务状态来查看,如下:

[dave@www.cndba.cn system]$ systemctl status DmServicedave
● DmServicedave.service - DM database instance service
   Loaded: loaded (/usr/lib/systemd/system/DmServicedave.service; enabled; vendor preset: disabled)
   Active: active (exited) since Fri 2029-02-23 01:37:37 CST; 10h ago
  Process: 24621 ExecStart=/dm/dmdbms/bin/DmServicedave start (code=exited, status=0/SUCCESS)
 Main PID: 24621 (code=exited, status=0/SUCCESS)
    Tasks: 0
   CGroup: /system.slice/DmServicedave.service
[dave@www.cndba.cn system]$

通过disql来查看:

http://www.cndba.cn/cndba/dave/article/3566
http://www.cndba.cn/cndba/dave/article/3566

[dave@www.cndba.cn ~]$ disql SYSDBA/SYSDBA

Server[LOCALHOST:5236]:mode is normal, state is open
login used time: 14.097(ms)
disql V7.6.0.145-Build(2019.03.20-104220)ENT 
SQL> select status$ from v$database;

LINEID     STATUS$    
---------- -----------
1          4

used time: 8.850(ms). Execute id is 2197.
SQL>

这里是用数字来表示状态的,这里一共有6种状态,如下:
1:启动;2:启动,redo 完成;3:MOUNT;4:打开;5:挂起;6:关闭

2.2 使用系统服务来启动和关闭DM 实例

[root@dm1 ~]# systemctl stop DmServicedave
[root@dm1 ~]# systemctl status DmServicedave
● DmServicedave.service - DM database instance service
   Loaded: loaded (/usr/lib/systemd/system/DmServicedave.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2029-02-23 12:34:40 CST; 7s ago
  Process: 2561 ExecStop=/dm/dmdbms/bin/DmServicedave stop (code=exited, status=0/SUCCESS)
  Process: 741 ExecStart=/dm/dmdbms/bin/DmServicedave start (code=exited, status=0/SUCCESS)
 Main PID: 741 (code=exited, status=0/SUCCESS)

Feb 23 12:26:16 dm1 systemd[1]: Starting DM database instance service...
Feb 23 12:26:16 dm1 su[824]: (to dmdba) root on none
Feb 23 12:26:19 dm1 DmServicedave[741]: Starting DmServicedave: Last login: Fri Feb 23 12:10:04 CST 2029 on pts/6
Feb 23 12:26:34 dm1 DmServicedave[741]: [11B blob data]
Feb 23 12:26:34 dm1 systemd[1]: Started DM database instance service.
Feb 23 12:34:35 dm1 systemd[1]: Stopping DM database instance service...
Feb 23 12:34:40 dm1 DmServicedave[2561]: [35B blob data]
Feb 23 12:34:40 dm1 systemd[1]: Stopped DM database instance service.

[root@dm1 ~]# systemctl start DmServicedave

[root@dm1 ~]# systemctl status DmServicedave
● DmServicedave.service - DM database instance service
   Loaded: loaded (/usr/lib/systemd/system/DmServicedave.service; enabled; vendor preset: disabled)
   Active: active (exited) since Fri 2029-02-23 12:35:12 CST; 1s ago
  Process: 2561 ExecStop=/dm/dmdbms/bin/DmServicedave stop (code=exited, status=0/SUCCESS)
  Process: 2621 ExecStart=/dm/dmdbms/bin/DmServicedave start (code=exited, status=0/SUCCESS)
 Main PID: 2621 (code=exited, status=0/SUCCESS)

Feb 23 12:34:57 dm1 systemd[1]: Starting DM database instance service...
Feb 23 12:34:57 dm1 su[2641]: (to dmdba) root on none
Feb 23 12:34:57 dm1 DmServicedave[2621]: Starting DmServicedave: Last login: Fri Feb 23 12:28:13 CST 2029 on pts/1
Feb 23 12:35:12 dm1 DmServicedave[2621]: [11B blob data]
Feb 23 12:35:12 dm1 systemd[1]: Started DM database instance service.
[root@dm1 ~]# 
[root@dm1 ~]# ps -ef|grep dm.ini
dmdba     2662     1  0 12:34 ?        00:00:00 /dm/dmdbms/bin/dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole
root      2765  2026  0 12:36 pts/0    00:00:00 grep --color=auto dm.ini
[root@dm1 ~]#

2.3 使用命令行管理DB

前面提到命令行直接使用命令操作。 dmserver 启动命令行窗口一直在,启动后直接输入exit即表示关闭实例。如果加上-noconsole选项,则不接受任何指令,可以直接按Ctrl+c 来终止程序并停止数据库。http://www.cndba.cn/cndba/dave/article/3566

[dave@www.cndba.cn ~]$ /dm/dmdbms/bin/dmserver /dm/dmdbms/data/cndba/dm.ini
file dm.key not found, use default license!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V7.6.0.145-Build(2019.03.20-104220)ENT  startup...
License will expire on 2029-03-09
ckpt lsn: 61183
ndct db load finished
ndct fill fast pool finished
set EP[0]'s pseg state to inactive
iid page's trxid = 2600
NEXT TRX ID = 2601
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
SYSTEM IS READY.

#输入其他指令,可以通过dmserver help 查看:
lock
----------------- object lock info ---------------
    addr       objid       mode      trx      wait
>> 0 object locks.

------------------- tid lock info ----------------
    addr       objid       mode      trx      wait
>> 0 object locks.

-----------------outer object lock info (dbms_lock)---------------
    addr       objid       mode      sess      wait_sess
#输入exit 关闭实例
exit
Server is stopping...
listener closed  and all sessions disconnected
purge undo records in usegs...OK
full check point starting...
generate force checkpoint, rlog free space, used space is (536457216, 405504)
ckpt_lsn, ckpt_fil, ckpt_off are set as (66044, 0, 10398720)
checkpoint: 3878 pages flushed.
checkpoint finished, rlog free space, used space is (536600064, 262656)
full check point end.
shutdown audit subsystem...OK
shutdown schedule subsystem...OK
shutdown timer successfully.
pre-shutdown MAL subsystem...OK
shutdown worker threads subsystem...OK
shutdown local parallel threads pool successfully.
shutdown replication subsystem...OK
shutdown sequence cache subsystem...OK
wait for mtsk link worker to exit..OK
shutdown mpp session subsystem...OK
wait for rapply is all over... OK
rapply worker threads exit successfully.
pre ending task & worker threads...OK
shutdown dblink subsystem...OK
shutdown session subsystem...OK
shutdown rollback segments purging subsystem...OK
shutdown rps subsystem...OK
shutdown transaction subsystem...OK
shutdown locking subsystem...OK
shutdown dbms_lock subsystem...OK
ending tsk and worker threads...OK
ckpt2_exec_immediately begin.
ckpt_lsn, ckpt_fil, ckpt_off are set as (66048, 0, 10661376)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536680448, 182272)
ckpt_lsn, ckpt_fil, ckpt_off are set as (70401, 0, 10843648)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862208, 512)
ckpt_lsn, ckpt_fil, ckpt_off are set as (70401, 0, 10844160)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
ckpt_lsn, ckpt_fil, ckpt_off are set as (70401, 0, 10844160)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
shutdown archive subsystem...OK
shutdown redo log subsystem...OK
shutdown MAL subsystem...OK
shutdown message compress subsystem successfully.
shutdown task subsystem...OK
shutdown trace subsystem...OK
shutdown svr_log subsystem...OK
shutdown plan cache subsystem...OK
shutdown file subsystem...OK
shutdown database dictionary subsystem...OK
shutdown mac cache subsystem...OK
shutdown dynamic login cache subsystem...OK
shutdown ifun/bifun/sfun/afun cache subsystem...OK
shutdown crypt subsystem...OK
shutdown pipe subsystem...OK
shutdown compress component...OK
shutdown slave redo subsystem...OK
shutdown kernel buffer subsystem...OK
shutdown SQL capture subsystem...OK
shutdown control file system...OK
shutdown dtype subsystem...OK
shutdown huge buffer and memory pools...OK
close lsnr socket
DM Database Server shutdown successfully.
[dave@www.cndba.cn ~]$ 

#启动到mount状态:
[dave@www.cndba.cn ~]$ dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole mount
file dm.key not found, use default license!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V7.6.0.145-Build(2019.03.20-104220)ENT  startup...
License will expire on 2029-03-09
ckpt lsn: 126426
ndct db load finished
ndct fill fast pool finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
SYSTEM IS READY.

以服务模式启动DB实例且不接收指令:

/dm/dmdbms/bin/dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole

使用命令行的方式启动DB缺点很明显,窗口必须一致存在,尝试将将命令放到后台执行:

/dm/dmdbms/bin/dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole &http://www.cndba.cn/cndba/dave/article/3566

实际测试发现一个问题,通过系统service 启动的实例,状态可以在DM service viewer中正确识别,但用命令行启动的实例,状态无法在系统服务和DM 服务查看中正确显示,也无法进行操作,也就是说,命令行启动的实例,只能通过命令行来关闭。 不过这个并不影响,可以直接使用linux 的fg命令将后台进程调到前台,在正常操作即可。 不建议直接在操作系统级别kill 进程。http://www.cndba.cn/cndba/dave/article/3566

#使用命令行启动后系统服务无法获取正确的状态:
[root@dm1 ~]# systemctl status DmServicedave
● DmServicedave.service - DM database instance service
   Loaded: loaded (/usr/lib/systemd/system/DmServicedave.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Fri 2029-02-23 12:38:36 CST; 42min ago
  Process: 2788 ExecStop=/dm/dmdbms/bin/DmServicedave stop (code=exited, status=0/SUCCESS)
  Process: 2621 ExecStart=/dm/dmdbms/bin/DmServicedave start (code=exited, status=0/SUCCESS)
 Main PID: 2621 (code=exited, status=0/SUCCESS)

Feb 23 12:34:57 dm1 systemd[1]: Starting DM database instance service...
Feb 23 12:34:57 dm1 su[2641]: (to dmdba) root on none
Feb 23 12:34:57 dm1 DmServicedave[2621]: Starting DmServicedave: Last login: Fri Feb 23 12:28:13 CST 2029 on pts/1
Feb 23 12:35:12 dm1 DmServicedave[2621]: [11B blob data]
Feb 23 12:35:12 dm1 systemd[1]: Started DM database instance service.
Feb 23 12:38:26 dm1 systemd[1]: Stopping DM database instance service...
Feb 23 12:38:36 dm1 DmServicedave[2788]: [35B blob data]
Feb 23 12:38:36 dm1 systemd[1]: Stopped DM database instance service.
[root@dm1 ~]# 

#后台启动实例,并使用fg命令调用到前台:
[dave@www.cndba.cn ~]$ dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole &
[1] 5435
[dave@www.cndba.cn ~]$ file dm.key not found, use default license!
version info: develop
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V7.6.0.145-Build(2019.03.20-104220)ENT  startup...
License will expire on 2029-03-09
ckpt lsn: 117208
ndct db load finished
ndct fill fast pool finished
set EP[0]'s pseg state to inactive
iid page's trxid = 2621
NEXT TRX ID = 2622
pseg recv finished
nsvr_startup end.
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
SYSTEM IS READY.

#将命令调用到前台
[dave@www.cndba.cn ~]$ jobs -l
[1]+  5435 Running                 dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole &
[dave@www.cndba.cn ~]$ fg 1
dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole

exit
^CServer is stopping...
listener closed  and all sessions disconnected
purge undo records in usegs...OK
full check point starting...
generate force checkpoint, rlog free space, used space is (536457216, 405504)
ckpt_lsn, ckpt_fil, ckpt_off are set as (122069, 0, 14882304)
checkpoint: 3232 pages flushed.
checkpoint finished, rlog free space, used space is (536602624, 260096)
full check point end.
shutdown audit subsystem...OK
shutdown schedule subsystem...OK
shutdown timer successfully.
pre-shutdown MAL subsystem...OK
shutdown worker threads subsystem...OK
shutdown local parallel threads pool successfully.
shutdown replication subsystem...OK
shutdown sequence cache subsystem...OK
wait for mtsk link worker to exit..OK
shutdown mpp session subsystem...OK
wait for rapply is all over... OK
rapply worker threads exit successfully.
pre ending task & worker threads...OK
shutdown dblink subsystem...OK
shutdown session subsystem...OK
shutdown rollback segments purging subsystem...OK
shutdown rps subsystem...OK
shutdown transaction subsystem...OK
shutdown locking subsystem...OK
shutdown dbms_lock subsystem...OK
ending tsk and worker threads...OK
ckpt2_exec_immediately begin.
ckpt_lsn, ckpt_fil, ckpt_off are set as (122073, 0, 15142400)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536680448, 182272)
ckpt_lsn, ckpt_fil, ckpt_off are set as (126426, 0, 15324672)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862208, 512)
ckpt_lsn, ckpt_fil, ckpt_off are set as (126426, 0, 15325184)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
ckpt_lsn, ckpt_fil, ckpt_off are set as (126426, 0, 15325184)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
shutdown archive subsystem...OK
shutdown redo log subsystem...OK
shutdown MAL subsystem...OK
shutdown message compress subsystem successfully.
shutdown task subsystem...OK
shutdown trace subsystem...OK
shutdown svr_log subsystem...OK
shutdown plan cache subsystem...OK
shutdown file subsystem...OK
shutdown database dictionary subsystem...OK
shutdown mac cache subsystem...OK
shutdown dynamic login cache subsystem...OK
shutdown ifun/bifun/sfun/afun cache subsystem...OK
shutdown crypt subsystem...OK
shutdown pipe subsystem...OK
shutdown compress component...OK
shutdown slave redo subsystem...OK
shutdown kernel buffer subsystem...OK
shutdown SQL capture subsystem...OK
shutdown control file system...OK
shutdown dtype subsystem...OK
shutdown huge buffer and memory pools...OK
close lsnr socket
DM Database Server shutdown successfully.
[dave@www.cndba.cn ~]$

2.4 切换实例状态

SQL> select status$ from v$database;

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

LINEID     STATUS$    
---------- -----------
1          4

used time: 7.105(ms). Execute id is 3.
SQL> alter database mount;
executed successfully
used time: 00:00:01.878. Execute id is 0.
SQL> select status$ from v$database;

LINEID     STATUS$    
---------- -----------
1          3

used time: 2.155(ms). Execute id is 4.
SQL>

其他修改选项可以参考官方手册:

ALTER DATABASE <修改数据库语句>;
<修改数据库语句>::= 
RESIZE LOGFILE <文件路径> TO <文件大小>|
ADD LOGFILE <文件说明项>{,<文件说明项>}|
RENAME LOGFILE <文件路径>{,<文件路径>} TO <文件路径>{,<文件路径>}|
MOUNT |
SUSPEND |
OPEN [FORCE] |
NORMAL |
PRIMARY|
STANDBY |
ARCHIVELOG |
NOARCHIVELOG |
<ADD|MODIFY|DELETE> ARCHIVELOG <归档配置语句> |
ARCHIVELOG CURRENT
<文件说明项> ::= <文件路径>SIZE <文件大小>
<归档配置语句>::= 'DEST = <归档目标>,TYPE = <归档类型>'
<归档类型>::=
LOCAL [<文件和路径设置>] |
REALTIME|
SYNC |
ASYNC ,TIMER_NAME = <定时器名称> | 
REMOTE ,ARCH_INCOMING_PATH = <远程归档路径>[<文件和路径设置>]| 
TIMELY
<文件和路径设置>::=[,FILE_SIZE = <文件大小>][,SPACE_LIMIT = <空间大小限制>]

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

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

dave

关注

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

  • 2261
    原创
  • 3
    翻译
  • 578
    转载
  • 191
    评论
  • 访问:8014172次
  • 积分:4346
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ