分类: DB2/Informix
2008-05-31 17:08:20
更改数据库服务器模式
在 Windows 中,数据库服务器作为服务运行。Windows 提供了一个服务控制应用程序(也称 Services 工具),用于启动、停止和暂停服务。这个服务控制应用程序在控制面板程序组中。数据库服务器的服务名称包括数据库服务器名称(ONCONFIG 文件中 DBSERVERNAME 的值)。例如,数据库服务器 windows_iif1110 的动态服务器服务是:
IBM Informix Database Server - windows_iif1110
在 UNIX 或 Linux 中,可以使用 onmonitor
命令更改数据库服务器的模式。
可以使用 Informix Server Administrator (ISA) 更改数据库服务器的模式。(要了解更多关于 ISA 的信息,请参阅 “”(IBM,2006)。)
离线(Offline)模式表示服务器没有运行,没有初始化共享内存,DBA 和用户(客户机)都不能访问数据库服务器。
如果初始化了共享内存,则可以执行以下命令将服务器改为离线模式:
$ onmode -k |
模式:离线
每当数据库服务器处于离线模式,DBA 试图通过执行数据库服务器的某个工具访问服务器时,DBA 可以看到如下所示的一条消息:
$ onstat – shared memory not initialized for INFORMIXSERVER 'gavea_iif1110_shm' |
客户机应用程序可以看到如下所示的错误消息:
$ dbaccess - run_query 25588: The appl process cannot connect to the database server gavea_iif1110_shm. |
初始化(initialization)模式是一种临时模式,当初始化服务器并将服务器从离线模式切换到静态(quiescent)模式时,就会出现初始化模式。
$ onmonitor
Dynamic Server: Status Parameters Dbspaces Mode Force-Ckpt ...
Change the Dynamic Server operating mode.
-----------------------------Off-Line------- Press CTRL-W for Help. --------
|
MODES: Startup On-Line singleUser Graceful-Shutdown ...
Bring Dynamic Server to quiescent mode from off-line.
-----------------------------Off-Line------- Press CTRL-W for Help. --------
|
Initializing, please wait ... Press Return to continue. |
$ oninit -v Checking group membership to determine server run mode...succeeded Reading configuration file '/usr3/informix/iif11.10/etc/onconfig.gavea_iif1110'...succeeded Creating /INFORMIXTMP/.infxdirs...succeeded Creating infos file "/usr3/informix/iif11.10/etc/.infos.gavea_iif1110_tcp"...succeeded Linking conf file "/usr3/informix/iif11.10/etc/.conf.gavea_iif1110_tcp"...succeeded Writing to infos file...succeeded Checking config parameters...succeeded Allocating and attaching to shared memory...succeeded Creating resident pool 1742 kbytes...succeeded Allocating 2016 kbytes for buffer pool of 2K page size...succeeded Allocating 4016 kbytes for buffer pool of 4K page size...succeeded Allocating 16016 kbytes for buffer pool of 16K page size...succeeded Initializing rhead structure...succeeded Initializing ASF...succeeded Initializing Dictionary Cache and SPL Routine Cache...succeeded Bringing up ADM VP...succeeded Creating VP classes...succeeded Onlining 0 additional cpu vps...succeeded Onlining 2 IO vps...succeeded Initialization of Encryption...succeeded Forking main_loop thread...succeeded Initializing DR structures...succeeded Forking 1 'soctcp' listener threads...succeeded Forking 1 'ipcshm' listener threads...succeeded Starting tracing...succeeded Initializing 20 flushers...succeeded Initializing log/checkpoint information...succeeded Opening primary chunks...succeeded Opening mirror chunks...succeeded Initializing dbspaces...succeeded Validating chunks...succeeded Initialize Async Log Flusher...succeeded Forking btree cleaner...succeeded Initializing DBSPACETEMP list...succeeded Checking database partition index...succeeded Initializing dataskip structure...succeeded Checking for temporary tables to drop...succeeded Forking onmode_mon thread...succeeded Starting scheduling system...succeeded Verbose output complete: mode = 5 $ |
这种模式总是必需的。在这种模式期间,会发生共享内存初始化,并且可以包括磁盘初始化。
在初始化过程中,数据库服务器搜索所有数据库空间,以发现临时表空间。这些临时表空间是由被异常终止的用户进程留下的,不能执行适当的清除。数据库服务器删除所有临时表空间,并回收(reclaim)磁盘空间。
默认情况下,初始化过程搜索和删除所有临时表空间。如果使用 oninit
的 –p
选项初始化数据库服务器,则数据库服务器省略这个步骤。这样可以加快初始化过程;但是,所有被使用的临时表空间和空间仍然留在服务器上,直到下一次在不使用 oninit
的 –p
选项的情况下进行初始化。
每当服务器从离线模式切换至静态模式、单用户(single-user)模式、或联机(online)模式时,服务器检查物理日志,确定服务器之前是否被适当地关闭。如果物理日志不为空,则表明服务器不是适当地离线的,数据库服务器开始快速恢复。如果物理日志为空,则表明服务器是适当地离线的,不需要快速恢复。
数据库保持快速恢复模式,直到逻辑与物理相一致。这可能需要花点时间,DBA 只能等待。
快速恢复在发生任何导致用于数据库服务器的内存的内容丢失的故障之后,将数据库服务器恢复至物理与逻辑相一致的状态。
在共享内存初始化过程中,数据库服务器检查物理日志的内容。如果数据库服务器是正常关闭的,则物理日志为空。从离线模式切换至静态模式时包含一个检查点,以刷新物理日志。因此,如果数据库服务器发现物理日志中存在页面,则表明数据库服务器是在失控情况下离线的,因此开始快速恢复。
在共享内存初始化过程中,快速恢复使数据库服务器返回到一致状态。所有被提交的事务将被恢复,所有未提交的事务则回滚。快速恢复的步骤如下:
在快速恢复的最后,从最近检查点到发生失控关闭这段时间内数据库上的所有更改都被应用到所有数据库空间。所有未提交的更改从逻辑日志回滚到磁盘(数据库空间)。
至此,数据库服务器已完成快速恢复并处于一致状态(物理和逻辑都一致),并切换至静态模式、单用户模式或联机模式。
共享内存初始化已完成,oninit 进程也在运行,共享内存资源已经分配,但是系统还不允许数据库用户的访问。
管理员使用这种模式来执行不需要执行 SQL 命令(DDL 和 DML 语句)的维护功能。
注意: 对于限制其他用户访问,且需要执行 DDL 和 DML 语句的任务, 请参阅 “单用户模式” 小节。
执行以下命令,将数据库服务器从离线模式切换至静态模式:
$ oninit -sv Checking group membership to determine server run mode...succeeded Reading configuration file '/usr3/informix/iif11.10/etc/onconfig.gavea_iif1110'...succeeded Creating /INFORMIXTMP/.infxdirs...succeeded Creating infos file "/usr3/informix/iif11.10/etc/.infos.gavea_iif1110_tcp"...succeeded Linking conf file "/usr3/informix/iif11.10/etc/.conf.gavea_iif1110_tcp"...succeeded Writing to infos file...succeeded Checking config parameters...succeeded Allocating and attaching to shared memory...succeeded Creating resident pool 1742 kbytes...succeeded Allocating 2016 kbytes for buffer pool of 2K page size...succeeded Allocating 4016 kbytes for buffer pool of 4K page size...succeeded Allocating 16016 kbytes for buffer pool of 16K page size...succeeded Initializing rhead structure...succeeded Initializing ASF...succeeded Initializing Dictionary Cache and SPL Routine Cache...succeeded Bringing up ADM VP...succeeded Creating VP classes...succeeded Onlining 0 additional cpu vps...succeeded Onlining 2 IO vps...succeeded Initialization of Encryption...succeeded Forking main_loop thread...succeeded Initializing DR structures...succeeded Forking 1 'soctcp' listener threads...succeeded Forking 1 'ipcshm' listener threads...succeeded Starting tracing...succeeded Initializing 20 flushers...succeeded Initializing log/checkpoint information...succeeded Opening primary chunks...succeeded Opening mirror chunks...succeeded Initializing dbspaces...succeeded Validating chunks...succeeded Initialize Async Log Flusher...succeeded Initializing DBSPACETEMP list...succeeded Checking database partition index...succeeded Initializing dataskip structure...succeeded Checking for temporary tables to drop...succeeded Forking onmode_mon thread...succeeded Verbose output complete: mode = 1 $ $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- Quiescent -- Up 00:02:06 -- 44724 Kbytes |
$ onmonitor
Dynamic Server: Status Parameters Dbspaces Mode Force-Ckpt ...
Status menu to view Dynamic Server.
-----------------------------Off-Line------- Press CTRL-W for Help. --------
|
MODES: Startup On-Line singleUser Graceful-Shutdown ...
Bring Dynamic Server to quiescent mode from off-line.
-----------------------------Quiescent------- Press CTRL-W for Help. --------
|
发出 IMMEDIATE SHUTDOWN
命令,将数据库服务器从离线模式或单用户模式切换至静态模式:
$ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- On-Line -- Up 00:15:12 -- 44724 Kbytes $ onmode -u This will perform an IMMEDIATE SHUTDOWN - Do you wish to continue (y/n)? y There are 0 user threads that will be killed. Do you wish to continue (y/n)? y $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- Quiescent -- Up 00:16:33 -- 44724 Kbytes $ |
$ onmonitor Dynamic Server: Status Parameters Dbspaces Mode Force-Ckpt ... Change the Dynamic Server operating mode. -----------------------------On-Line------- Press CTRL-W for Help. -------- MODES: ... Immediate-Shutdown Take-Offline Add-Proc Drop-Proc ... Bring Dynamic Server to quiescent mode immediately. -----------------------------On-Line------- Press CTRL-W for Help. -------- Do you really want to shutdown? (y/n) y -----------------------------On-Line------- Press CTRL-W for Help. -------- There are no user threads except the DAEMONS and ONMONITOR. |
实例进入静态模式:
MODES: ... Immediate-Shutdown Take-Offline Add-Proc Drop-Proc ... Bring Dynamic Server to quiescent mode immediately. -----------------------------Quiescent------- Press CTRL-W for Help. -------- |
注意: 一旦服务器使用了最后一个连接,数据库服务器结束所有活动会话,然后进入静态模式。要了解更多选项,请参阅 “其他数据库服务器模式 ” 小节中的关闭模式。
只有管理员(用户 informix)可以访问数据库服务器。
管理员使用单用户模式来执行维护任务,包括需要执行 SQL(DML 和 DDL 语句)的任务。管理员还可以在联机模式下执行所有其他功能。
欲将数据库服务器从离线模式切换至单用户模式,可发出以下命令:
$ oninit -j $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- Single-User -- Up 00:00:17 -- 52916 Kbytes $ |
$ onmonitor MODES: Startup On-Line singleUser Graceful-Shutdown ... Bring Dynamic Server to quiescent mode from off-line. -----------------------------Off-Line------- Press CTRL-W for Help. -------- The server goes to quiescent mode, then you chooses singleUser MODES: Startup On-Line singleUser Graceful-Shutdown ... Bring Dynamic Server to Single-User mode from On-Line or quiescent. -----------------------------Single-User------- Press CTRL-W for Help. -------- |
联机模式是数据库服务器的常规操作模式。任何经授权的用户都可以连接到数据库服务器,以及执行所有数据库活动。
欲将数据库服务器从离线模式切换至联机模式,可发出以下命令:
$ oninit -v Checking group membership to determine server run mode...succeeded Reading configuration file '/usr3/informix/iif11.10/etc/onconfig.gavea_iif1110'...succeeded Creating /INFORMIXTMP/.infxdirs...succeeded Creating infos file "/usr3/informix/iif11.10/etc/.infos.gavea_iif1110_tcp"...succeeded Linking conf file "/usr3/informix/iif11.10/etc/.conf.gavea_iif1110_tcp"...succeeded Writing to infos file...succeeded Checking config parameters...succeeded Allocating and attaching to shared memory...succeeded Creating resident pool 1742 kbytes...succeeded Allocating 2016 kbytes for buffer pool of 2K page size...succeeded Allocating 4016 kbytes for buffer pool of 4K page size...succeeded Allocating 16016 kbytes for buffer pool of 16K page size...succeeded Initializing rhead structure...succeeded Initializing ASF...succeeded Initializing Dictionary Cache and SPL Routine Cache...succeeded Bringing up ADM VP...succeeded Creating VP classes...succeeded Onlining 0 additional cpu vps...succeeded Onlining 2 IO vps...succeeded Initialization of Encryption...succeeded Forking main_loop thread...succeeded Initializing DR structures...succeeded Forking 1 'soctcp' listener threads...succeeded Forking 1 'ipcshm' listener threads...succeeded Starting tracing...succeeded Initializing 20 flushers...succeeded Initializing log/checkpoint information...succeeded Opening primary chunks...succeeded Opening mirror chunks...succeeded Initializing dbspaces...succeeded Validating chunks...succeeded Initialize Async Log Flusher...succeeded Forking btree cleaner...succeeded Initializing DBSPACETEMP list...succeeded Checking database partition index...succeeded Initializing dataskip structure...succeeded Checking for temporary tables to drop...succeeded Forking onmode_mon thread...succeeded Starting scheduling system...succeeded Verbose output complete: mode = 5 $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- On-Line -- Up 00:01:14 -- 52916 Kbytes |
$ onmonitor Dynamic Server: Status Parameters Dbspaces Mode Force-Ckpt ... Change the Dynamic Server operating mode. -----------------------------Off-Line------- Press CTRL-W for Help. -------- After selecting Startup: MODES: Startup On-Line singleUser Graceful-Shutdown ... Bring Dynamic Server to quiescent mode from off-line. -----------------------------Quiescent------- Press CTRL-W for Help. -------- Then Select On-Line MODES: Startup On-Line singleUser Graceful-Shutdown ... Bring Dynamic Server to on-line mode from quiescent or Single-User. -----------------------------On-Line------- Press CTRL-W for Help. -------- |
欲将数据库服务器从静态模式或单用户模式切换至联机模式,可使用以下命令:
$ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- Quiescent -- Up 00:06:56 -- 44724 Kbytes $ onmode -m $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- On-Line -- Up 00:07:07 -- 44724 Kbytes |
此外,数据库服务器还可以处于以下几种模式之一:
只读模式是 HDR 对中的辅助数据库服务器的常规操作模式。
数据库服务器不是通过执行某个命令,而是通过配置 HDR 进入此模式的。
关闭模式是一种短暂的模式。当数据库服务器从离线模式或单用户模式切换至静态模式时,就会出现关闭模式。在此模式下,当前用户可以访问系统,但是新用户不能访问系统。关闭模式一旦开始就不能取消。当最后一个连接被终止(断开)后,服务器从关闭模式切换至静态模式。
$ onstat -g ses IBM Informix Dynamic Server Version 11.10.UB4TL -- On-Line -- Up 00:24:10 -- 44724 Kbytes session #RSAM total used dynamic id user tty pid hostname threads memory memory explain 32 informix - 0 - 0 12288 8504 off 31 informix 4 6457 gavea.us 1 77824 72064 off 30 informix - 0 - 1 241664 201872 off 28 informix - 0 - 1 249856 203040 off 26 informix - 0 - 1 204800 163776 off 9 informix - 0 - 0 12288 8504 off 8 informix - 0 - 0 12288 8504 off 6 informix - 0 - 0 12288 9720 off 5 informix - 0 - 0 12288 9720 off 4 informix - 0 - 0 12288 8504 off 3 informix - 0 - 0 12288 8504 off 2 informix - 0 - 0 12288 8504 off See session 31 is connected to the instance Execute onmode to take instance to Shutdown mode $ onmode -sy Option -y answers yes automatically $ onstat - IBM Informix Dynamic Server Version 11.10.UB4TL -- Shutting Down -- Up 00:26:39 -- 44724 Kbytes |
注意: 如果存在活动连接,数据库服务器将保持关闭模式,直到最后一个连接断开。如果没有活动连接,服务器将立即切换至静态模式。