关于sysdba,sysoper,dba这些名词在工作中可能接触的比较多,如果接触的环境是服务器端的,sysdba可能是经常用到的。如果是数据库的维护工作,dba就是必备的权限。
在Oracle的官方文档中给出了sysdba和sysoper的区别。我在这个基础上又加入了一些东西做点补充。
标黄的部分是sysdba和sysoper的不同之处。这两个特殊的系统权限和dba权限还是有着明显的差别。
System PrivilegeOperations AuthorizedSYSDBA
Perform STARTUP and SHUTDOWN operations
ALTER DATABASE: open, mount, back up, or change character set
CREATE DATABASE
DROP DATABASE
CREATE SPFILE
ALTER DATABASE ARCHIVELOG
ALTER DATABASE RECOVER
Includes the RESTRICTED SESSION privilege
Effectively, this system privilege allows a user to connect as user SYS.
SYSOPER
Perform STARTUP and SHUTDOWN operations
CREATE SPFILE
ALTER DATABASE OPEN/MOUNT/BACKUP
ALTER DATABASE ARCHIVELOG
ALTER DATABASE RECOVER (Complete recovery only. Any form of incomplete recovery, such as UNTIL TIME|CHANGE|CANCEL|CONTROLFILE requires connecting as SYSDBA.)
Includes the RESTRICTED SESSION privilege
#1 sys,system用户都是数据库创建时内置的用户。sys绑定的是sysdba系统权限,system绑定的是dba角色。
sys的默认密码是CHANGE_ON_INSTALL,而system的默认密码是MANAGER
#2 如果直接拿sys来登录,不使用sysdba,会有下面的错误。
[ora11g@rac1 ~]$ sqlplus sys/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 22 04:39:21 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
#3 sysdba对应的用户时SYS,而sysoper对应的用户PUBLIC
SQL> conn / as sysoper
Connected.
SQL> show user
USER is "PUBLIC"
SQL> conn / as sysdba
Connected.
SQL> show user
USER is "SYS"
#4 如果在服务端登录,随便用一个用户。因为设置了操作系统级的验证,所以都可以使用sysdba.
SQL> conn test/test as sysdba
Connected.
如果使用了tns连接的情况下。就会校验test的权限。发现不具备sysdba的系统权限。
SQL> conn test/tets@test01 as sysdba
ERROR:
ORA-01031: insufficient privileges
#5 关于sys,不得不提到密码文件。如果没有密码文件。会报如下的错误。
[ora11g@rac1 dbs]$ sqlplus sys/oracle@test01 as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 22 05:40:03 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-01031: insufficient privileges
创建了密码文件之后,就没有问题
[ora11g@rac1 dbs]$ orapwd password=oracle file=orapwTEST01 entries=2
[ora11g@rac1 dbs]$ sqlplus sys/oracle@test01 as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 22 05:40:37 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> exit
#6 关于sysdba和dba的区别,可以通过如下的例子来简单示范一下。
用户n1是dba用户。我们使用sysdba和dba权限的时候来看一下不同之处。
[ora11g@rac1 dbs]$ sqlplus n1/n1 as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Sat Nov 22 05:56:40 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*)from cat;
COUNT(*)
----------
4809
SQL> conn n1/n1
Connected.
SQL> select count(*)from cat;
COUNT(*)
----------
406
#7 sysdba具有的权限要远大于dba。我们平常使用的dba角色主要包括创建表,视图,索引等等的明细权限,但是sysdba可以做数据库级的任何操作。