Oracle中password file的作用及说明


在数据库没有启动之前,数据库内建用户是无法通过数据库来验证身份的。

口令文件中存放sysdba/sysoper用户的用户名及口令,允许用户通过口令文件验证,在数据库未启动之前登陆,从而启动数据库。

如果没有口令文件,在数据库未启动之前就只能通过操作系统认证.

使用Rman,很多时候需要在nomount,mount等状态对数据库进行处理
所以通常要求sysdba权限如果属于本地DBA组,可以通过操作系统认证登陆
如果是远程sysdba登陆,需要通过passwordfile认证.

1.remote_login_passwordfile = NONE

此时停用口令文件验证,Oracle数据库不允许远程SYSDBA/SYSOPER身份登录
无法通过远程进行数据库起停等操作管理

local:

> > [oracle@jumper oracle]$ sqlplus "/ as sysdba" >
> SQL*Plus: Release 9.2.0.3.0 - Production on Thu Apr 15 09:58:45 2004 >
> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. >
>
> Connected to: > Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production > With the Partitioning, OLAP and Oracle Data Mining options > JServer Release 9.2.0.3.0 - Production >
> SQL> alter user sys identified by oracle; >
> User altered. >
> SQL> show parameter pass >
> NAME TYPE VALUE > --------------------- ----------- ------------------------------ > remote_login_passwordfile string NONE >
>


remote:

> > E:\Oracle\ora92\bin>sqlplus /nolog
> >
> > SQL*Plus: Release 9.2.0.4.0 - > Production on 星期四 4月 15 09:39:22 2004
> >
> > Copyright (c) 1982, 2002, Oracle > Corporation. All rights reserved.
> >
> > SQL> connect sys/oracle@hsjf as > sysdba
> > ERROR:
> > ORA-01017: invalid username/password; logon denied
> >
> >


此处实际上是无法通过口令文件验证

2.remote_login_passwordfile = exclusive

> > SQL> alter system set remote_login_passwordfile=exclusive scope=spfile; >
> System altered. >
> SQL> startup force; > ORACLE instance started. >
> Total System Global Area 131142648 bytes > Fixed Size 451576 bytes > Variable Size 104857600 bytes > Database Buffers 25165824 bytes > Redo Buffers 667648 bytes > Database mounted. > Database opened. > SQL> show parameter pass >
> NAME TYPE VALUE > ------------------------------------ ----------- ------------------------------ > remote_login_passwordfile string EXCLUSIVE > SQL> alter user sys identified by oracle; >
> User altered. >
>


remote:

> > E:\Oracle\ora92\bin>sqlplus /nolog
> >
> > SQL*Plus: Release 9.2.0.4.0 - > Production on 星期四 4月 15 09:47:11 2004
> >
> > Copyright (c) 1982, 2002, Oracle > Corporation. All rights reserved.
> >
> > SQL> connect sys/oracle@hsjf as > sysdba
> > 已连接。
> > SQL> show user
> > USER 为"SYS"
> > SQL>
> >


这实际上就是通过口令文件验证登录的

3.进一步测试

如果此时我们删除passwdfile,sysdba/sysoper将无法认证,也就无法登陆数据库

Server:

> SQL> !
> [oracle@jumper oracle]$ cd $ORACLE_HOME/dbs
> [oracle@jumper dbs]$ ls orapwhsjf
> orapwhsjf
> [oracle@jumper dbs]$ mv orapwhsjf orapwhsjf.bak
> [oracle@jumper dbs]$
>
>


Remote:

> E:\Oracle\ora92\bin>sqlplus /nolog
>
> SQL*Plus: Release 9.2.0.4.0 - Production on 星期四 4月 15 09:50:14 2004
>
> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
>
> SQL> connect sys/oracle@hsjf as sysdba
> ERROR:
> ORA-01031: insufficient privileges
>
>
> SQL>
>
>


这实际上就是无法通过口令文件验证身份

4.如果丢失了passwdfile

如果使用passwdfile却意外丢失,此时将不能启动数据库

>
>
> SQL> startup force;
> ORACLE instance started.
>
> Total System Global Area 131142648 bytes
> Fixed Size 451576 bytes
> Variable Size 104857600 bytes
> Database Buffers 25165824 bytes
> Redo Buffers 667648 bytes
> ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'
> ORA-27037: unable to obtain file status
> Linux Error: 2: No such file or directory
> Additional information: 3 > >
>


此时可以通过orapwd重建口令文件来解决
此处我们恢复口令文件既可

> SQL> !
> [oracle@jumper oracle]$ mv $ORACLE_HOME/dbs/orapwhsjf.bak orapwhsjf
> [oracle@jumper oracle]$ exit
> exit
>
> SQL> alter database open;
>
> Database altered.
>
> SQL> > >
>


大致就是如此.

5. remote_login_passwordfile = shared

我们看一下Oracle9i文档中的说明:

SHARED

More than one database can use a password file. However, the only user recognized by the password file is SYS.

意思是说多个数据库可以共享一个口令文件,但是只可以识别一个用户:SYS

> SQL> select * from v$pwfile_users; > > USERNAME SYSDB SYSOP
> ------------------------------ ----- -----
> SYS TRUE TRUE > > SQL> grant sysdba to eygle;
> grant sysdba to eygle
> *
> ERROR at line 1:
> ORA-01994: GRANT failed: cannot add users to public password file
> > > SQL> show parameter password > > NAME TYPE VALUE
> ------------------------------------ ----------- ------------------------------
> remote_login_passwordfile string SHARED > >
>


我们看到,此时的口令文件中是不能添加用户的.

很多人的疑问在于:口令文件的缺省名称是orapw

  1<sid>,怎么能够共享? 
  2
  3实际上是这样的: Oracle数据库在启动时,首先查找的是orapw<sid>的口令文件,如果该文件不存在,则开始查找,orapw的口令文件   
  4如果口令文件命名为orapw,多个数据库就可以共享. 
  5
  6我们看一下测试: 
  7
  8&gt; 
  9&gt;     [oracle@jumper dbs]$ sqlplus "/ as sysdba"
 10&gt;     
 11&gt;     SQL*Plus: Release 9.2.0.3.0 - Production on Tue Jul 6 09:40:34 2004
 12&gt;     
 13&gt;     Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
 14&gt;     
 15&gt;     
 16&gt;     Connected to:
 17&gt;     Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
 18&gt;     With the Partitioning, OLAP and Oracle Data Mining options
 19&gt;     JServer Release 9.2.0.3.0 - Production
 20&gt;     
 21&gt;     SQL&gt; shutdown immediate
 22&gt;     Database closed.
 23&gt;     Database dismounted.
 24&gt;     ORACLE instance shut down.
 25&gt;     SQL&gt; !
 26&gt;     [oracle@jumper dbs]$ ls
 27&gt;     hsjf  initdw.ora  inithsjf.ora  init.ora  lkHSJF  orapwhsjf  spfilehsjf.ora
 28&gt;     [oracle@jumper dbs]$ mv orapwhsjf orapwhsjf.bak
 29&gt;     [oracle@jumper dbs]$ exit
 30&gt;     exit
 31&gt;     
 32&gt;     SQL&gt; startup
 33&gt;     ORACLE instance started.
 34&gt;     
 35&gt;     Total System Global Area  235999908 bytes
 36&gt;     Fixed Size                   451236 bytes
 37&gt;     Variable Size             201326592 bytes
 38&gt;     Database Buffers           33554432 bytes
 39&gt;     Redo Buffers                 667648 bytes
 40&gt;     ORA-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'--这是最后查找的文件
 41&gt;     ORA-27037: unable to obtain file status
 42&gt;     Linux Error: 2: No such file or directory
 43&gt;     Additional information: 3
 44&gt;     
 45&gt;     		  
 46&gt; 
 47&gt;   
 48&gt;   
 49  
 50---  
 51  
 52我们建立orapw口令文件,这时候可以打开数据库. 
 53
 54&gt; 
 55&gt;     SQL&gt; !
 56&gt;     [oracle@jumper dbs]$ ls
 57&gt;     hsjf  initdw.ora  inithsjf.ora  init.ora  lkHSJF  orapwhsjf.bak  spfilehsjf.ora
 58&gt;     [oracle@jumper dbs]$ cp orapwhsjf.bak orapw
 59&gt;     [oracle@jumper dbs]$ exit
 60&gt;     exit
 61&gt;     
 62&gt;     SQL&gt; alter database open;
 63&gt;     
 64&gt;     Database altered.
 65&gt;     
 66&gt;     SQL&gt; show parameter passw
 67&gt;     
 68&gt;     NAME                                 TYPE        VALUE
 69&gt;     ------------------------------------ ----------- ------------------------------
 70&gt;     remote_login_passwordfile            string      SHARED
 71&gt;     SQL&gt;      
 72  
 73---  
 74  
 75那么你可能会有这样的疑问,多个Exclusive的数据库是否可以共享一个口令文件(orapw)呢? 
 76
 77我们继续这个实验: 
 78
 79&gt; 
 80&gt;     SQL&gt; show parameter password
 81&gt; 
 82&gt; NAME TYPE VALUE   
 83&gt;  \------------------------------------ ----------- ------------------------------   
 84&gt;  remote_login_passwordfile string SHARED   
 85&gt; 
 86&gt; 
 87&gt; [oracle@jumper dbs]$ strings orapw   
 88&gt;  ]\\[Z   
 89&gt;  ORACLE Remote Password file   
 90&gt;  INTERNAL   
 91&gt;  AB27B53EDC5FEF41   
 92&gt;  8A8F025737A9097A   
 93  
 94---  
 95  
 96注意这里仅记录着INTERNAL/SYS的口令 
 97
 98REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE 时 
 99
100&gt; 
101&gt;     SQL&gt; alter system set remote_login_passwordfile=exclusive scope=spfile;
102&gt; 
103&gt; System altered. 
104&gt; 
105&gt; SQL&gt; startup force;   
106&gt;  ORACLE instance started. 
107&gt; 
108&gt; Total System Global Area 235999908 bytes   
109&gt;  Fixed Size 451236 bytes   
110&gt;  Variable Size 201326592 bytes   
111&gt;  Database Buffers 33554432 bytes   
112&gt;  Redo Buffers 667648 bytes   
113&gt;  Database mounted.   
114&gt;  Database opened.   
115&gt;  SQL&gt; !   
116&gt;    
117&gt;  [oracle@jumper bin]$ cd $ORACLE_HOME/dbs   
118&gt;  [oracle@jumper dbs]$ strings orapw   
119&gt;  ]\\[Z   
120&gt;  ORACLE Remote Password file   
121&gt;  HSJF   
122&gt;  INTERNAL   
123&gt;  AB27B53EDC5FEF41   
124&gt;  8A8F025737A9097A   
125&gt;  [oracle@jumper dbs]$ exit   
126&gt;  exit   
127  
128---  
129  
130注意这里,以EXCLUSIVE 方式启动以后,实例名称信息被写入口令文件. 
131
132此时如果有其他实例以Exclusive模式启动仍然可以使用这个口令文件,口令文件中的实例名称同时被改写. 
133
134也就是说,数据库只在启动过程中才读取口令文件,数据库运行过程中并不锁定该文件,类似于pfile/spfile文件.   
135
136
137&gt; 
138&gt;     SQL&gt; select * from v$pwfile_users;
139&gt; 
140&gt; USERNAME SYSDB SYSOP   
141&gt;  \------------------------------ ----- -----   
142&gt;  SYS TRUE TRUE 
143&gt; 
144&gt; SQL&gt; grant sysdba to eygle; 
145&gt; 
146&gt; Grant succeeded. 
147&gt; 
148&gt; SQL&gt; select * from v$pwfile_users; 
149&gt; 
150&gt; USERNAME SYSDB SYSOP   
151&gt;  \------------------------------ ----- -----   
152&gt;  SYS TRUE TRUE   
153&gt;  EYGLE TRUE FALSE 
154&gt; 
155&gt; SQL&gt; !   
156&gt;  [oracle@jumper bin]$ cd $ORACLE_HOME/dbs   
157&gt;  [oracle@jumper dbs]$ strings orapw   
158&gt;  ]\\[Z   
159&gt;  ORACLE Remote Password file   
160&gt;  HSJF   
161&gt;  INTERNAL   
162&gt;  AB27B53EDC5FEF41   
163&gt;  8A8F025737A9097A   
164&gt;  &gt;EYGLE   
165&gt;  B726E09FE21F8E83   
166  
167---  
168  
169  
170注意此时可以增加SYSDBA用户,并且这些信息可以被写入到口令文件. 
171
172一旦口令文件中增加了其他SYSDBA用户,此文件不再能够被其他Exclusive的实例共享.   
173
174
175实际上,口令文件对于其他用户来说就是启到了一个 sudo 的作用. 
176
1776.重建口令文件 
178
179如果口令文件丢失,可以使用orapwd可以重建口令文件,语法如下: 
180
181&gt; 
182&gt;     [oracle@jumper oracle]$ orapwd  
183&gt;     &gt; Usage: orapwd file=<fname> password=<password> entries=<users> 
184&gt; 
185&gt; where   
186&gt;  file - name of password file (mand),   
187&gt;  password - password for SYS (mand),   
188&gt;  entries - maximum number of distinct DBA and OPERs (opt),   
189&gt;  There are no spaces around the equal-to (=) character.   
190  
191---</users></password></fname></sid></sid>
Published At
Categories with 数据库类
Tagged with
comments powered by Disqus