ORA-01994: GRANT failed: password file missing or disabled

2023-05-25,,

1、错误现象

SQL> grant sysdba to test;
grant sysdba to test
*
ERROR at line 1:
ORA-01994: GRANT failed: password file missing or disabled

SQL> ho oerr ora 01994
01994, 00000, "GRANT failed: password file missing or disabled"
// *Cause:  The operation failed either because the INIT.ORA parameter
//          REMOTE_LOGIN_PASSWORDFILE was set to NONE or else because the
//          password file was missing.
// *Action: Create the password file using the orapwd tool and set the
//          INIT.ORA parameter REMOTE_LOGIN_PASSWORDFILE to EXCLUSIVE.

2.根据提示分析解决

SQL> show parameter remote_login

NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
remote_login_passwordfile            string
EXCLUSIVE

SQL> ho ls $ORACLE_HOME/dbs/orapw*
/u01/app/oracle/product/11.1.0.6/dbs/orapworcl

果然没有当前数据库的密码文件。

3.使用orapwd重建当前数据库密码文件

首先查看orapwd的用法:

[oracle]$ orapwd
Usage: orapwd file=<fname> entries=<users> force=<y/n> ignorecase=<y/n> nosysdba=<y/n>

where
    file - name of password file (required),
    password - password for SYS will be prompted if not specified at command line,
    entries - maximum number of distinct DBA (optional),
    force - whether to overwrite existing file (optional),
    ignorecase - passwords are case-insensitive (optional),
    nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).
    
  There must be no spaces around the equal-to (=) character.

执行操作:

[oracle dbs]$ orapwd file=/u01/app/oracle/product/11.1.0.6/dbs/orapwsales password=oracle entries=20   <---使用orapwd重建当前数据库密码文件

SQL> ho ls $ORACLE_HOME/dbs/orapw*
/u01/app/oracle/product/11.1.0.6/dbs/orapworcl  /u01/app/oracle/product/11.1.0.6/dbs/orapwsales  <--有了sales这个数据库的密码文件

SQL> grant sysdba to test; <--授权成功
Grant succeeded.
SQL> commit;  <--提交操作
Commit complete.

4.orapwd命令的详细解析及说明

[oracle]$ orapwd
Usage: orapwd file=<fname> entries=<users> force=<y/n> ignorecase=<y/n> nosysdba=<y/n>

where
    file - name of password file (required),
    password - password for SYS will be prompted if not specified at command line,
    entries - maximum number of distinct DBA (optional),
    force - whether to overwrite existing file (optional),
    ignorecase - passwords are case-insensitive (optional),
    nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).
    
  There must be no spaces around the equal-to (=) character.

例如:D:\oracle\ora92 \database>orapwd file=orcl.ora password=orclsys entries=2 其中参数entries的含义是表示口令文件中可以存放的最大用户数,对应于允许以SYSDBA/SYSOPER权限登录数据库的最大用户数,如果用户数 超过这个值只能重建口令文件,增大entries。

file后面可以指定口令文件的全路径和文件名,否则创建在当前目录下。

windows下oracle默认的位置是ora92/database目录,默认的文件名是 pwdSID.ora,对于别的文件名是不认的。linux下oracle默认的位置是$ORACLE_HOME/dbs目录,默认的文件名是 orapwSID,对于别的文件名是不认的。

(1)、为什么需要口令文件?

在数据库没有启动之前,数据库内建用户是无法通过数据库来验证身份的。口令文件中存放sysdba/sysoper
用户的用户名及口令,允许用户通过口令文件验证,在数据库未启动之前登陆,从而启动数据库。如果没有口令文件,在数据库未启动之前就只能通过操作系统认
证。
使用Rman,很多时候需要在nomount,mount等状态对数据库进行处理。所以通常要求sysdba权限如果属于本地DBA组,可以通过操作系统
认证登陆。如果是远程sysdba登陆,需要通过passwordfile认证。

(2)、口令文件损坏或者丢失怎么办?

口令文件就是sysdba/sysoper用户的唯一口令文件,丢了就进不来,不管数据库启动没有。连接报错...

SQL> connect sys/oracle@fzlgfm as sysdba 
ERROR: 
ORA-01031: insufficient privileges

只能用操作系统级权限验证登陆,即oracle/oracle登陆,然后orapwd重建口令文件: 
orapwd file=orcl.ora password=orclsys entries=2

Orapwd命令第二个参数是指定sys的密码,参数等于什么,sys密码以后就是什么。为什么要指定sys密码?
因为口令文件里面必须要有用户密码,否则怎么验证啊?但此时数据库如果没启动的话就根本取不到sys密码,所以只能强行指定了,启动后数据库里面sys的
密码会被改成此时指定的。另外重建口令文件的工作只能由系统验证用户完成,或者具有dba权限的用户也可以,其他用户执行orapwd命令都会失败。

(3)、如何把sysdba/sysoper用户加到口令文件中去?

再执行一遍grant sysdba/sysoper to 用户,oracle会自动在口令文件中增加一个条目,并且把密码copy过来。
察看口令文件内容的方法:
select * from v$pwfile_users;

SQL> grant sysdba to scott; 
Grant succeeded

SQL> select * from v$pwfile_users;

USERNAME SYSDBA SYSOPER 
--------------- ------- ------- 
SYS TRUE TRUE 
SCOTT TRUE FALSE

(4)、没有口令文件是否可以启动数据库?

可以。9i及以下mount过程中会报错,然后手动open就可以了。因为只要用本地验证用户照样可以做sysdba的事情,没有理由让数据库启动不了。10g已经不会报错了。

(5)、没有口令文件为什么是mount阶段报错而不是nomount阶段报错?

因为只有到了alter mount阶段才验证各种文件,nomount只读spfile/pfile创建进程。

(6)、修改sysdba/sysoper用户密码时,能否同步到口令文件?

可以同步。Alter user xxx identified by yyy 
所有密码忘记都没关系,但至少要记住sys用户密码。

(7)、spfile/pfile中remote_login_passwordfile是干嘛用的?

三种设定模式:可以通过show parameter pass命令查看当前模式

remote_login_passwordfile = EXCLUSIVE,则一个实例专用;

remote_login_passwordfile = SHARE则可以多个实例共享(用于OPS/RAC环境);

remote_login_passwordfile = NONE则不启用口令文件,此时任何sysdba/sysoper都无法连接进来。

remote_login_passwordfile = shared 我们看一下Oracle9i文档中的说明:
More than one database can use a password file. However, the only user recognized by the password file is SYS. 

思是说多个数据库可以共享一个口令文件,但是只可以识别一个用户:SYS。在用SPFILE的情况
下,remote_login_passwordfile参数怎么改呢?SPFILE是不可以强行编辑的,否则数据库不认的。用alter system
set remote_login_passwordfile=none scope=spfile。

改成NONE以后怎么改回来呢?

用os级认证登陆,然后alter system set remote_login_passwordfile=none scope=spfile,或者直接create spfile from pfile;

remote_login_passwordfile='none'意味着禁用口令文件,有也不能用。等于可以
disable所有sysdba/sysoper,此时只能用oracle/oracle用户来启动和关闭数据库,也就是只有os认证,没有口令文件认
证,这就是此参数的意义-口令文件验证的开关。

(8)、sqlnet.ora中SQLNET.AUTHENTICATION_SERVICES=(NTS/NONE)有什么用?

NTS=NT Security 即采用OS优先认证登陆,NONE为不可以,必须采用usr/pwd as
sysdba/sysoper
登陆。这里是操作系统级验证的开关。如果SQLNET.AUTHENTICATION_SERVICES=(NONE)并且
remote_login_passwordfile='none',即两个开关都关闭,那么神仙也进不了数据库,hoho我指的是
sysdba/sysoper用户,普通用户可以照常使用的。当然,有物理权限的人也除外,即你可以物理地打开这台计算机操作。

总结一下,ORACLE有两种方式可以认证sysdba/sysoper用户:操作系统级认证-dba权限组(linux
/unix)和ORA_DBA组(win);口令文件认证。
两种方式有各自的开关:sqlnet.ora中AUTHENTICATION_SERVICES参数;spfile/pfile中
remote_login_passwordfile参数。并且这两个开关互不矛盾,可以同时打开同时关闭或者只开一个。

参考文档:

http://blog.itpub.net/28716724/viewspace-756259/

http://www.cnblogs.com/51linux/archive/2013/06/08/3125788.html

ORA-01994: GRANT failed: password file missing or disabled的相关教程结束。

《ORA-01994: GRANT failed: password file missing or disabled.doc》

下载本文的Word格式文档,以方便收藏与打印。