您的位置:首页 > 其它

oradim工具建立新的实例、启动实例、删除实例、删除监听服务

2012-07-04 14:51 246 查看
最近在看一本oracle书,讲到用dbca(数据库配置助手)来建立数据库,然后作者用oradim命令行方式又建了一个新的实例,对于书中提到的命令行,不太清楚什么意思,书中的命令行大概是这样的:

C:\Documents and Settings\Administrator>oradim -new -sid wc -startmode manual -s
pfile
实例已创建。

C:\Documents and Settings\Administrator>oradim -edit -sid wc -startmode auto -sr
vcstart system

C:\Documents and Settings\Administrator>


于是查了一下oracle文档,引用自这个链接http://docs.oracle.com/cd/E11882_01/win.112/e10845/create.htm#NTQRF05011

下面是最主要的命令行选项说明:


Creating an Instance

To use ORADIM to create an instance, enter:
oradim [-NEW -SID SID] | -SRVC service_name | -ASMSID SID | -ASMSRVC service_name
[-SYSPWD password] [-STARTMODE auto | manual] [-SRVCSTART system | demand]
[-PFILE filename | -SPFILE] [-SHUTMODE normal | immediate | abort] [-TIMEOUT
secs] [-RUNAS osusr/ospass]

where

-NEW
indicates that you are creating a new instance. This is a mandatory parameter.

-SID
SID
is the name of
the instance to create.

-SRVC
service_name
is the
name of the service to create (
OracleService
SID
).

-ASMSID
SID
is the name
of the Automatic Storage Management instance to create.

-ASMSRVC
service_name
is
the name of the Automatic Storage Management service to create.

-SYSPWD
password
is the
system password.

-STARTMODE
auto
|
manual
indicates
whether to start the instance when the Oracle Database service is started. Default is
manual
.

-SRVCSTART system | demand
indicates whether to start the Oracle Database service on computer restart. Default is
demand.
Here,
system
specifies
that the service be configured to automatically start when the system boots or reboots.
Demand
specifies that the user has to explicitly start the service.

-PFILE
filename
is the
initialization parameter file to be used with this instance. Ensure that you specify the complete path name of this file, including drive letter.

-SPFILE
indicates that a server parameter file (SPFILE) be used during startup instead of a PFILE.

-SHUTMODE normal|immediate|abort
specifies how to stop an instance. This is an optional parameter. If you do not specify how to stop an instance, then
normal
is
the default mode.
-SHUTMODE
requires an argument and the default is
immediate.
If
SHUTMODE
is
omitted, then there is no attempt made to shutdown the instance when the service is shutdown.

-TIMEOUT
secs
sets the
maximum time to wait (in seconds) before the service for a particular
SID
stops. The default is 90 seconds.
It cannot be used without the
SHUTDOWN
argument.

-RUNAS osusr/ospass
("run as") sets the operating system user with which the Oracle service logs on to the system. You supply an operating system user name and
password, and the service logs on and runs with the privileges of that user. If omitted, the service logs on to the system using the Local system account, which is a privileged user.

首先用上面oracle文档中的内容来看一下书上命令行用到的各种选项的意义:

1.-new:要创建一个新的实例。

2.-sid wc:指出了要创建的实例名,这里的实例名是wc。

3.-startmode manual:指定了在oracle服务启动的时候,是否启动实例,这里指定手动,默认选项也是手动的,也就是说在windows中服务启动了,在任务管理器里你能看到oarcle.exe这个进程了,但是数据库实例并没有启动。另外,在windows中,像oracle(SQL server也一样)这样的后台进程,就是没有用户界面的服务器程序,一般是作为服务启动的,这个和linux是不一样的。

4.-startmode auto:指定在oarcle服务启动的时候,也同时启动实例。

5.-srvcstart system:指定在电脑启动或重启之后,是否自动启动oracle数据库服务,system表示自动启动,而demand表示用户必须显式启动服务(命令:net start oracleserviceWC)。



6.-spfile:指定在startup期间使用服务器参数文件spfile,而不是pfile文件,这样的话startup的时候就不用指定pfile文件的路径,而是会到$ORACLE_HOME\database\SPFILE[sid].ora文件,当然这里只是新建了一个实例,还没有创建spfile文件。

7.还有一些选项是上面的命令行中没有的,不过挺有意思。

-startup -sid sid:启动实例。

-starttype srvc | inst | srvc,inst:启动方式,可以是只启动服务,启动实例(服务必须先启动),同时启动服务和实例。

-shutdown -sid sid:关闭实例。

-shuttype srvc | inst | srvc,inst:关闭方式,可以是只关闭服务,只关闭实例,同时关闭服务和实例。注意第一个选项,虽说是只关闭服务,但是如果实例是通过启动服务后再启动的,那么关闭服务后发现在任务管理器中找不到oracle.exe这个进程了,可想而知,实例也被关闭了;但如果实例启动之前oracle.exe只是作为一个普通程序运行,而不是服务运行的话,那么当然关闭实例只是关闭实例,这个oracle.exe的进程还在任务管理器中,只是由于释放了实例占用的SGA(共享全局区)内存后,内存的使用量下降了很多,看下面的例子:

第一个窗口启动oracle:

C:\Documents and Settings\Administrator>oracle wc
Press CTRL-C to exit server:

第二窗口启动实例:

C:\Documents and Settings\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 7月 4 16:49:22 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

已连接到空闲例程。

SQL> startup
ORACLE 例程已经启动。

Total System Global Area  603979776 bytes
Fixed Size                  1250380 bytes
Variable Size             167775156 bytes
Database Buffers          427819008 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
数据库已经打开。
SQL>

第三个窗口是关闭实例,但是oracle.exe还在,只是内存使用量减少:

C:\Documents and Settings\Administrator>oradim -shutdown -sid wc -shuttype inst
-shutmode immediate

C:\Documents and Settings\Administrator>


接下来在第二个窗口中退出sqlplus,再此连接实例,再次启动数据库:

C:\Documents and Settings\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 7月 4 16:57:28 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> exit
ERROR:
ORA-03113: 通信通道的文件结束

从 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options(情况复杂) 断开

C:\Documents and Settings\Administrator>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 7月 4 16:59:24 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

已连接到空闲例程。

SQL> startup
ORACLE 例程已经启动。

Total System Global Area  603979776 bytes
Fixed Size                  1250380 bytes
Variable Size             167775156 bytes
Database Buffers          427819008 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
数据库已经打开。
SQL>


-shutmode normal | immediate | abort:关闭模式,正常关闭,立即关闭,还是异常退出。

好,实例创建完成了,命令行中的意思也明白了,接下来我想要启动新的实例,注意不是启动oracleserviceWC这个数据库服务,其实在上面第一个命令oradim -new -sid wc -startmode manual -spfile执行后,不仅创建了实例及这个实例对应的windows服务(服务名OracleServiceWC),而且看上面的图你也会发现,这个服务显示"已启动"。

那么要启动实例,必须有参数文件,要加载并打开数据库,必须有密码文件,控制文件,各类数据文件,联机重做日志等文件,那怎么办呢?

其实很简单,我们可以重用之前已经用dbca工具建立的那个数据库orcl里的文件:

1.新建参数文件,其实就是复制原来实例orcl的参数文件,注意spfile参数文件名的路径($ORACLE_HOME\database)和格式(SPFILE[SID].ora):

C:\>copy E:\oracle\product\10.2.0\db_1\database\SPFILEORCL.ora E:\oracle\product
\10.2.0\db_1\database\SPFILEWC.ORA
已复制         1 个文件。


2. 这么多文件中,可以不建立密码文件,在windows中只要E:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\sqlnet.ora文件中:

SQLNET.AUTHENTICATION_SERVICES设置为NTS或者ALL,那么在本地登录的时候会使用操作系统认证,说白了就是登陆不需要输入用户名密码,会自动使用当前登录到windows的用户,比如Administrator用户的安全凭证来登陆oracle,如果设为其他值都不能启动操作系统认证。

不过这里还是建立一个密码文件,注意密码文件的路径($ORACLE_HOME\database)和格式(PWD[SID].ora):

C:\>orapwd file=E:\oracle\product\10.2.0\db_1\database\PWDwc.ora password=wc entries=30


3.在参数文件中有一个参数control_files指定了控制文件的路径,而控制文件中记录了所有数据文件,联机重做日志文件的路径,所以控制文件、数据文件、日志文件都不需要新建,直接用orcl的就行。

C:\>set ORACLE_SID=wc

C:\>sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 7月 4 15:44:23 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

已连接到空闲例程。

SQL> startup nomount
ORACLE 例程已经启动。

Total System Global Area  603979776 bytes
Fixed Size                  1250380 bytes
Variable Size             163580852 bytes
Database Buffers          432013312 bytes
Redo Buffers                7135232 bytes

SQL> alter database mount;

数据库已更改。

SQL> alter database open;

数据库已更改。

SQL>

行了,实例WC启动并打开了数据库,需要注意的是这条命令:set ORACLE_SID=wc,如果不输入的话后面sqlplus连接实例的时候会报错,之所以会报错是因为系统中现在有2个实例:orcl、wc,在用sqlplus / as sysdba命令来连接实例的时候,到底是连接哪个实例呢?是连接orcl还是wc呢,从实际情况上看,sqlplus会连接到orcl,然后报“协议适配器错误”,通过 set ORACLE_SID=wc其实就是指定了sqlplus /
as sysdba命令要连接到wc实例。

4、删除实例

C:\Users\Administrator>oradim -delete -sid orcl


5、删除监听服务

windows键+R建,在弹出的运行框中输入:regedit

找到这个路径: \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\OracleOraDb11g_home1TNSListener

删除这个目录就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: