Oracle中passwordfile的作用及說明考試大全

tolywang發表於2007-11-21
Oracle中passwordfile的作用及說明考試大全

在資料庫沒有啟動之前,資料庫內建使用者是無法透過資料庫來驗證身份的

口令檔案中存放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:Oracleora92bin>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/oracle@hsjf 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 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:Oracleora92bin>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/oracle@hsjf as
sysdba已連線。SQL> show userUSER 為"SYS"SQL>

這實際上就是透過口令檔案驗證登入的 [Page]

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:Oracleora92bin>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'
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,怎麼能夠共享?
實際上是這樣的: Oracle資料庫在啟動時,首先查詢的是orapw的口令檔案,如果該檔案不存在,則開始查詢,orapw的口令檔案
如果口令檔案命名為orapw,多個資料庫就可以共享.
我們看一下測試:

[oracle@jumper 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 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> !
[oracle@jumper dbs]$ ls
hsjf initdw.ora inithsjf.ora init.ora lkHSJF orapwhsjf spfilehsjf.ora
[oracle@jumper dbs]$ mv orapwhsjf orapwhsjf.bak
[oracle@jumper dbs]$ exit
exit
SQL> startup
ORACLE instance started.
Total System Global Area 235999908 bytes
Fixed Size 451236 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
ORA-01990: error opening password file '/opt'--這是最後查詢的檔案
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3[Page]

我們建立orapw口令檔案,這時候可以開啟資料庫.

SQL> !
[oracle@jumper dbs]$ ls
hsjf initdw.ora inithsjf.ora init.ora lkHSJF orapwhsjf.bak spfilehsjf.ora
[oracle@jumper dbs]$ cp orapwhsjf.bak orapw
[oracle@jumper dbs]$ exit
exit
SQL> alter database open;
Database altered.
SQL> show parameter passw
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string SHARED
SQL>

那麼你可能會有這樣的疑問,多個Exclusive的資料庫是否可以共享一個口令檔案(orapw)呢?
我們繼續這個實驗:

SQL> show parameter passwordNAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile string SHARED
[oracle@jumper dbs]$ strings orapw
][Z
ORACLE Remote Password file
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A

注意這裡僅記錄著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 bytes
Fixed Size 451236 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> !
[oracle@jumper bin]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ strings orapw
][Z
ORACLE Remote Password file
HSJF
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
[oracle@jumper dbs]$ exit
exit

注意這裡,以EXCLUSIVE 方式啟動以後,例項名稱資訊被寫入口令檔案.
此時如果有其他例項以Exclusive模式啟動仍然可以使用這個口令檔案,口令檔案中的例項名稱同時被改寫.
也就是說,資料庫只在啟動過程中才讀取口令檔案,資料庫執行過程中並不鎖定該檔案,類似於pfile/spfile檔案.[Page]

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 TRUE
EYGLE TRUE FALSE
SQL> !
[oracle@jumper bin]$ cd $ORACLE_HOME/dbs
[oracle@jumper dbs]$ strings orapw
][Z
ORACLE Remote Password file
HSJF
INTERNAL
AB27B53EDC5FEF41
8A8F025737A9097A
>EYGLE
B726E09FE21F8E83

注意此時可以增加SYSDBA使用者,並且這些資訊可以被寫入到口令檔案.
一旦口令檔案中增加了其他SYSDBA使用者,此檔案不再能夠被其他Exclusive的例項共享.
實際上,口令檔案對於其他使用者來說就是啟到了一個 sudo 的作用.

6.重建口令檔案

如果口令檔案丟失,可以使用orapwd可以重建口令檔案,語法如下:

[oracle@jumper oracle]$ orapwdUsage: orapwd file= password= entries= where
file - 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.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-85023/,如需轉載,請註明出處,否則將追究法律責任。

相關文章