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