Linux 平台达梦数据库启动与关闭

  • DM DB 的启动过程
    • 读取配置文件 (.ini)
    • 读取控制文件 (dm.ctl)
    • 读取重做日志文件 ().log) 和 数据文件 (*.DBF)
  • DM DB 的状态
    • 配置状态 (MOUNT):不允许访问数据库对象,只能进行控制文件维护、归档配置、数据库模式修改等操作;
    • 打开状态 (OPEN):不能进行控制文件维护、归档配置等操作,可以访问数据库对象,对外提供正常的数据库服务;
    • 挂起状态 (SUSPEND):与 OPEN 状态的唯一区别就是,限制磁盘写入功能;一旦修改了数据页,触发 REDO 日志、数据页刷盘,当前用户将被挂起。

OPEN 状态与 MOUNT 和 SUSPEND 能相互转换,但是 MOUNT 和 SUSPEND 之间不能相互转换。

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

三种模式只能在 MOUNT 状态下设置,模式之间可以相互转换。

对于新初始化的库,首次启动不允许使用 mount 方式,需要先正常启动并正常退出,然后才允许 mount 方式启动。

一般情况下,数据库为 NORMAL 模式,如果不指定 MOUNT 状态启动,则自动启动到 OPEN 状态。

在需要对数据库配置时(如配置数据守护、数据复制),服务器需要指定 MOUNT 状态启动。当数据库模式为非 NORMAL 模式(PRIMARY、STANDBY 模式),无论是否指定启动状态,服务器启动时自动启动到 MOUNT 状态。

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

DM 服务查看器

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

查看服务状态

系统服务

在实例安装结束之后会创建,在操作系统直接对实例服务进行操作。Windows 则是直接在服务窗口进行。

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

命令行模式

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

dmserver [ini_file_path] [-noconsole] [mount]

说明:

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

当不确定启动参数的使用方法时,可以使用 help 参数,将打印出格式、参数说明和使用示例。使用方法如下:

dmserver help

当以控制台方式启动 Dmserver 时,用户可以在控制台输入一些命令,服务器将在控制台打印出相关信息或执行相关操作。

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

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

操作示例

查看 DM DB 的状态

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

[dmdba@dameng system]$ systemctl status DmServiceDMTEST
● DmServiceDMTEST.service - DM database instance service
Loaded: loaded (/usr/lib/systemd/system/DmServiceDMTEST.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/DmServiceDMTEST start (code=exited, status=0/SUCCESS)
Main PID: 24621 (code=exited, status=0/SUCCESS)
Tasks: 0
CGroup: /system.slice/DmServiceDMTEST.service
[dmdba@dameng system]$
通过 disql 来查看:
[dmdba@dameng ~]$ 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:关闭

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

[root@dm1 ~]# systemctl stop DmServiceDMTEST
[root@dm1 ~]# systemctl status DmServiceDMTEST
● DmServiceDMTEST.service - DM database instance service
Loaded: loaded (/usr/lib/systemd/system/DmServiceDMTEST.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/DmServiceDMTEST stop (code=exited, status=0/SUCCESS)
Process: 741 ExecStart=/dm/dmdbms/bin/DmServiceDMTEST 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 DmServiceDMTEST[741]: Starting DmServiceDMTEST: Last login: Fri Feb 23 12:10:04 CST 2029 on pts/6
Feb 23 12:26:34 dm1 DmServiceDMTEST[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 DmServiceDMTEST[2561]: [35B blob data]
Feb 23 12:34:40 dm1 systemd[1]: Stopped DM database instance service.
[root@dm1 ~]# systemctl start DmServiceDMTEST
[root@dm1 ~]# systemctl status DmServiceDMTEST
● DmServiceDMTEST.service - DM database instance service
Loaded: loaded (/usr/lib/systemd/system/DmServiceDMTEST.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/DmServiceDMTEST stop (code=exited, status=0/SUCCESS)
Process: 2621 ExecStart=/dm/dmdbms/bin/DmServiceDMTEST 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 DmServiceDMTEST[2621]: Starting DmServiceDMTEST: Last login: Fri Feb 23 12:28:13 CST 2029 on pts/1
Feb 23 12:35:12 dm1 DmServiceDMTEST[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 ~]#

使用命令行管理 DB

[dmdba@dameng ~]$ /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.
[dmdba@dameng ~]$

--启动到 mount 状态:
[dmdba@dameng ~]$ 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 &

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

--使用命令行启动后系统服务无法获取正确的状态:
[root@dm1 ~]# systemctl status DmServiceDMTEST
● DmServiceDMTEST.service - DM database instance service
Loaded: loaded (/usr/lib/systemd/system/DmServiceDMTEST.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/DmServiceDMTEST stop (code=exited, status=0/SUCCESS)
Process: 2621 ExecStart=/dm/dmdbms/bin/DmServiceDMTEST 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 DmServiceDMTEST[2621]: Starting DmServiceDMTEST: Last login: Fri Feb 23 12:28:13 CST 2029 on pts/1
Feb 23 12:35:12 dm1 DmServiceDMTEST[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 DmServiceDMTEST[2788]: [35B blob data]
Feb 23 12:38:36 dm1 systemd[1]: Stopped DM database instance service.
[root@dm1 ~]#

--后台启动实例,并使用 fg 命令调用到前台:
[dmdba@dameng ~]$ dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole &
[1] 5435
[dmdba@dameng ~]$ 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.

--将命令调用到前台
[dmdba@dameng ~]$ jobs -l
[1]+ 5435 Running dmserver /dm/dmdbms/data/cndba/dm.ini -noconsole &
[dmdba@dameng ~]$ 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.

切换实例状态

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 = <空间大小限制>]
微信扫码
分享文档
扫一扫
联系客服