日期:2014-05-16  浏览次数:20436 次

SYSDBA登陆权限问题

环境配置:Oracle10gR2,Windows XP

Oracle的用户信息一般来说是保存在数据字典里的,所以常规用户在Oracle数据库没有启动的时候是无法登陆的。但有两类用户例外,这就是具有sysdba或者sysoper权限的用户。Oracle sysdba或者sysoper用户的登陆有两种方式:一是通过OS认证,二是通过密码文件验证。



究竟使用哪一种验证方式以及能否成功登陆取决于三个方面的因素:

1. sqlnet.ora中SQLNET.AUTHENTICATION_SERVICES的设置

2. 参数文件中REMOTE_LOGIN_PASSWORDFILE的设置

3. 密码文件 PWD%sid%.ora



Oracle进行权限验证的大致顺序如下:

1. 根据SQLNET.AUTHENTICATION_SERVICES的值决定是进行os验证还是密码文件验证。

2. 如果是os验证,根据当前用户的用户组判断是否具有sysdba权限。如果os验证失败,则进行密码文件验证。

2. 如果是密码文件验证,REMOTE_LOGIN_PASSWORDFILE的值以及密码文件是否存在决定了验证是否成功。



1. OS 验 证



要启用os验证,就必须在qlnet.ora中设置SQLNET.AUTHENTICATION_SERVICES=(NTS),然后在Windows中建立ora_dba用户组,把相关用户加入到这个组中(e.g., administrator),这样administrator就可以在不用提供用户名和密码(或者提供任意的用户名和密码)的情况下以sysdba身份本地登陆。因为操作系统已经代替Oracle进行了验证。



测试一:ora_dba用户本地登陆


C:\>sqlplus / as sysdba   
Connected to:   
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production   
With the OLAP and Data Mining options   
SQL>   
  
C:\>sqlplus wrong_user/wrong_password as sysdba   
Connected to:   
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production   
With the OLAP and Data Mining options   
SQL>  

C:\>sqlplus / as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the OLAP and Data Mining options
SQL>

C:\>sqlplus wrong_user/wrong_password as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the OLAP and Data Mining options
SQL>



测试二:非ora_dba用户本地登陆

C:\>sqlplus / as sysdba   
ERROR:   
ORA-01031: insufficient privileges   
Enter user-name:   
  
C:\>sqlplus wrong_user/wrong_password sysdba   
ERROR:   
ORA-01017: invalid username/password; logon denied   
Enter user-name:   
  
C:\>sqlplus sys/change_on_install as sysdba   
Connected to:   
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production   
With the OLAP and Data Mining options   
SQL>  

C:\>sqlplus / as sysdba
ERROR:
ORA-01031: insufficient privileges
Enter user-name:

C:\>sqlplus wrong_user/wrong_password sysdba
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:

C:\>sqlplus sys/change_on_install as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the OLAP and Data Mining options
SQL>  


2. 密码文件验证



密码文件包含了被授予sysdba和sysoper权限的用户的用户名和密码。这是一个加密文件,一般来说存放在%oracle_home%/database目录下,文件名为PWD%sid%.ora。



如果要使用密码文件验证,则把sqlnet.ora改为SQLNET.AUTHENTICATION_SERVICES=none,或者从sqlnet.ora中删除SQLNET.AUTHENTICATION_SERVICES。同上匿名登陆sqlplus会失败,给出用户名和密码就可以成功登陆。

 
C:\>sqlplus / as sysdba   
ERROR:   
ORA-01031: insufficient privileges  
Enter user-name:   
  
C:\>sqlplus sys/change_on_install as sysdba   
Connected to an idle instance.   
idle>  

C:\>sqlplus / as sysdba
ERROR:
ORA-01031: insufficient privileges
Enter user-name:

C:\>sqlplus sys/change_on_install as sysdba
Connected to an idle instance.
idle> 

测试一:删除密码文件。使用用户名和密码登陆,失败!

C:\>sqlplus sys/change_on_install as sysdba   
ERROR:   
ORA-01031: insufficient privileges  
Enter user-name:  

C:\>sqlplus sys/change_on_install as sysdba
ERROR:
ORA-01031: insufficient privileges
Enter user-name: 

测试二:恢复密码文件,设置REMOTE_LOGIN_PASSWORDFILE=none。使用用户名和密码登陆,失败!

 
SQL> alter system set remote_login_passwordfile=none scope=spfile;   
System altered.   
  
C:\>sqlplus sys/change_on_install as sysdba   
ERROR:   
ORA-01017: invalid username/password; logon denied   
Enter user-name: