您的位置:首页 > 数据库 > Oracle

转载: oracle: 浅谈orapwd命令,及解决远程登录ORA-01031: insufficient privileges问题

2014-06-19 11:09 441 查看

转载地址http://blog.csdn.net/lzx_bupt/article/details/6780856


1、先看下命令说明:orapwd


  1. Usage: orapwd file=<fname> entries=<users> force=<y/n> ignorecase=<y/n> nosysdba=<y/n>  
  2.   
  3.   where  
  4.     file - name of password file (required),  
  5.     password - password for SYS will be prompted if not specified at command line,  
  6.     entries - maximum number of distinct DBA (optional),  
  7.     force - whether to overwrite existing file (optional),  
  8.     ignorecase - passwords are case-insensitive (optional),  
  9.     nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).  
  10.       
  11.   There must be no spaces around the equal-to (=) character.  


2、再看下使用范例:


  1. orapwd file=orapwmercury password=lzx123 entries=10  

范例说明:

  • file:变量orapwmercury为'orapw$ORACLE_SID'格式,如sid为test则命令文件为orapwtest,这点必须按格式来,并且该文件要放置在$ORACLE_HOME/dbs/目录下。
  • password:变量lzx123为设定给sys用户的密码
  • entries:10表明可以有10个sysdba权限用户,不可超过10个,目前已经定义了sys一个。

注:改动生效需要重启数据库。

3、应用说明:

orapwd命令是用来创建口令文件的,所以需要明白什么时候需要这个口令文件,执行下列命令查看


  1. [oracle@centos ~]$ sqlplus / as sysdba;  
  2.   
  3. SQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 17 11:21:52 2011  
  4.   
  5. Copyright (c) 1982, 2009, Oracle.  All rights reserved.  
  6.   
  7.   
  8. Connected to:  
  9. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production  
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  11.   
  12. SQL> show parameter remote_login_passwordfile;  
  13.   
  14. NAME                                 TYPE        VALUE  
  15. ------------------------------------ ----------- ------------------------------  
  16. remote_login_passwordfile            string      EXCLUSIVE  
  17. SQL>   

保证数据库open情况下,执行命令show parameter remote_login_passwordfile;查看值是不是EXCLUSIVE。这里的值是pfile中定义的,可以查看你的initSID.ora文件。对该字段的描述是:

***********************************************FROM ORACLE11G DOCS******************************************

REMOTE_LOGIN_PASSWORDFILE = { shared | exclusive | none }

REMOTE_LOGIN_PASSWORDFILE
specifies whether Oracle checks for a password file.

Values:

  • shared

    One or more databases can use the password file. The password file can contain

    SYS
    as well as non-
    SYS
    users.

  • exclusive

    The password file can be used by only one database. The password file can contain

    SYS
    as well as non-
    SYS
    users.

  • none

    Oracle ignores any password file. Therefore, privileged users must be authenticated by the operating system.

Notes:

  • When

    REMOTE_LOGIN_PASSWORDFILE
    is set to either
    exclusive
    or
    shared
    , but the password file does not exist, then the behavior is the same as setting
    REMOTE_LOGIN_PASSWORDFILE
    to
    none
    .

  • If you change

    REMOTE_LOGIN_PASSWORDFILE
    to
    exclusive
    or
    shared
    from
    none
    , then ensure that the password file is in sync with the dictionary passwords. SeeOracle Database Administrator's Guide for more information.

*******************************************************************************************************************

从描述中可以知道如果值是none的话,表明口令文件模式不起作用,必须用操作系统级的sysdba权限用户登录,如系统用户oracle。而没有指定值得话等同于none。因此如果要使用口令文件必须是exclusive或是shared模式,并且用orapwd命令创建,值得一提的是该口令文件指保存具有sysdba等超级权限的用户。

注:假如你不能用sys加上口令登录,那就用系统用户oracle,使用sqlplus / as sysdba;登录到数据库(如不能登录,这里有个sqlnet.ora文件请查阅https://www.geek-share.com/detail/2527146081.html)。

4、常见问题

(1)尝试使用sysdba权限用户远程登录的时候提示,尤其是pl/sql使用 "sys/密码 as sysdba"登录时

ORA-01031: insufficient privileges

对该问题首要考虑就是1:口令文件的缺失,造成没有找到口令、2:

REMOTE_LOGIN_PASSWORDFILE
值没有指定或是指定了none。

(2)select * from v$pwfile_users; 结果为 no rows select如


  1. SQL> show user;  
  2. USER is "SYS"  
  3. SQL> select * from v$pwfile_users;  
  4.   
  5. no rows selected  

也说明口令文件不存在或是不起作用,需要按上述调整好,重启数据库,登录,然后检验:

  1. SQL> startup open;   
  2. ORACLE instance started.  
  3.   
  4. Total System Global Area  801701888 bytes  
  5. Fixed Size                  2217632 bytes  
  6. Variable Size             469764448 bytes  
  7. Database Buffers          322961408 bytes  
  8. Redo Buffers                6758400 bytes  
  9. Database mounted.  
  10. Database opened.  
  11. SQL> show parameter remote_login_passwordfile;  
  12.   
  13. NAME                                 TYPE        VALUE  
  14. ------------------------------------ ----------- ------------------------------  
  15. remote_login_passwordfile            string      EXCLUSIVE  
  16. SQL> select * from v$pwfile_users;  
  17.   
  18. USERNAME                       SYSDB SYSOP SYSAS  
  19. ------------------------------ ----- ----- -----  
  20. SYS                            TRUE  TRUE  FALSE  
  21.   
  22. SQL> grant sysdba to cat;  
  23.   
  24. Grant succeeded.  
  25.   
  26. SQL> select * from v$pwfile_users;  
  27.   
  28. USERNAME                       SYSDB SYSOP SYSAS  
  29. ------------------------------ ----- ----- -----  
  30. SYS                            TRUE  TRUE  FALSE  
  31. CAT                            TRUE  FALSE FALSE  

可说明,口令文件工作了!


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