首页 > 数据库 > Oracle > 正文

Oracle中password file的作用及说明

2020-03-09 22:55:51
字体:
来源:转载
供稿:网友

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

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

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

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

1.remote_login_passwordfile = none

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

local:

 

[[email protected] 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 - productionwith the partitioning, olap and oracle data mining optionsjserver 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 /nologsql*plus: release 9.2.0.4.0 - production on 星期四 4月 15 09:39:22 2004copyright (c) 1982, 2002, oracle corporation. all rights reserved.sql> connect sys/[email protected] as sysdbaerror: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 bytesfixed size 451576 bytesvariable size 104857600 bytesdatabase buffers 25165824 bytesredo buffers 667648 bytesdatabase mounted.database opened.sql> show parameter pass

name type value------------------------------------ ----------- ------------------------------remote_login_passwordfile string exclusivesql> alter user sys identified by oracle;

user altered.

 

remote:

 

 

e:/oracle/ora92/bin>sqlplus /nologsql*plus: release 9.2.0.4.0 - production on 星期四 4月 15 09:47:11 2004copyright (c) 1982, 2002, oracle corporation. all rights reserved.sql> connect sys/[email protected] as sysdba已连接。sql> show useruser 为"sys"sql> 

 

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

3.进一步测试

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

server:

 

sql> ![[email protected] oracle]$ cd $oracle_home/dbs[[email protected] dbs]$ ls orapwhsjforapwhsjf[[email protected] dbs]$ mv orapwhsjf orapwhsjf.bak[[email protected] 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/[email protected] as sysdbaerror:ora-01031: insufficient privileges

sql>

 



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

 

4.如果丢失了passwdfile

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

 



sql> startup force;oracle instance started.

total system global area 131142648 bytesfixed size 451576 bytesvariable size 104857600 bytesdatabase buffers 25165824 bytesredo buffers 667648 bytesora-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'ora-27037: unable to obtain file statuslinux error: 2: no such file or directoryadditional information: 3



 



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

 

sql> ![[email protected] oracle]$ mv $oracle_home/dbs/orapwhsjf.bak orapwhsjf[[email protected] oracle]$ exitexit

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<sid>,怎么能够共享?

实际上是这样的: oracle数据库在启动时,首先查找的是orapw<sid>的口令文件,如果该文件不存在,则开始查找,orapw的口令文件如果口令文件命名为orapw,多个数据库就可以共享.

我们看一下测试:

 

[[email protected] dbs]$ sqlplus "/ as sysdba"

sql*plus: release 9.2.0.3.0 - production on tue jul 6 09:40:34 2004

copyright (c) 1982, 2002, oracle corporation.  all rights reserved.

connected to:oracle9i enterprise edition release 9.2.0.3.0 - productionwith the partitioning, olap and oracle data mining optionsjserver release 9.2.0.3.0 - production

sql> shutdown immediatedatabase closed.database dismounted.oracle instance shut down.sql> ![[email protected] dbs]$ lshsjf  initdw.ora  inithsjf.ora  init.ora  lkhsjf  orapwhsjf  spfilehsjf.ora[[email protected] dbs]$ mv orapwhsjf orapwhsjf.bak[[email protected] dbs]$ exitexit

sql> startuporacle instance started.

total system global area  235999908 bytesfixed size                   451236 bytesvariable size             201326592 bytesdatabase buffers           33554432 bytesredo buffers                 667648 bytesora-01990: error opening password file '/opt/oracle/product/9.2.0/dbs/orapw'--这是最后查找的文件ora-27037: unable to obtain file statuslinux error: 2: no such file or directoryadditional information: 3

   

 

我们建立orapw口令文件,这时候可以打开数据库.

sql> ![[email protected] dbs]$ lshsjf  initdw.ora  inithsjf.ora  init.ora  lkhsjf  orapwhsjf.bak  spfilehsjf.ora[[email protected] dbs]$ cp orapwhsjf.bak orapw[[email protected] dbs]$ exitexit

sql> alter database open;

database altered.

sql> show parameter passw

name                                 type        value------------------------------------ ----------- ------------------------------remote_login_passwordfile            string      sharedsql>      

那么你可能会有这样的疑问,多个exclusive的数据库是否可以共享一个口令文件(orapw)呢?

我们继续这个实验:

sql> show parameter passwordname type value------------------------------------ ----------- ------------------------------remote_login_passwordfile string shared

[[email protected] dbs]$ strings orapw]/[zoracle remote password fileinternalab27b53edc5fef418a8f025737a9097a 

注意这里仅记录着internal/sys的口令

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 235999908 bytesfixed size 451236 bytesvariable size 201326592 bytesdatabase buffers 33554432 bytesredo buffers 667648 bytesdatabase mounted.database opened.sql> !

[[email protected] bin]$ cd $oracle_home/dbs[[email protected] dbs]$ strings orapw]/[zoracle remote password filehsjfinternalab27b53edc5fef418a8f025737a9097a[[email protected] dbs]$ exitexit 

注意这里,以exclusive 方式启动以后,实例名称信息被写入口令文件.

此时如果有其他实例以exclusive模式启动仍然可以使用这个口令文件,口令文件中的实例名称同时被改写.

也就是说,数据库只在启动过程中才读取口令文件,数据库运行过程中并不锁定该文件,类似于pfile/spfile文件.

sql> select * from v$pwfile_users;username sysdb sysop------------------------------ ----- -----sys true true

sql> grant sysdba to eygle;

grant succeeded.

sql> select * from v$pwfile_users;

username sysdb sysop------------------------------ ----- -----sys true trueeygle true false

sql> ![[email protected] bin]$ cd $oracle_home/dbs[[email protected] dbs]$ strings orapw]/[zoracle remote password filehsjfinternalab27b53edc5fef418a8f025737a9097a>eygleb726e09fe21f8e83 

注意此时可以增加sysdba用户,并且这些信息可以被写入到口令文件.

一旦口令文件中增加了其他sysdba用户,此文件不再能够被其他exclusive的实例共享.

实际上,口令文件对于其他用户来说就是启到了一个 sudo 的作用.

6.重建口令文件

如果口令文件丢失,可以使用orapwd可以重建口令文件,语法如下:

[[email protected] oracle]$ orapwdusage: orapwd file=<fname> password=<password> entries=<users> wherefile - name of password file (mand),password - password for sys (mand),entries - maximum number of distinct dba and opers (opt), there are no spaces around the equal-to (=) character.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表