Oracle Foundation(7-9)

来源:互联网 发布:java runtime class 编辑:程序博客网 时间:2024/05/17 03:47

概念:

1: SYS  和 SYSTEM 的区别:

      SYS  最高权限,是数据库中数据字典的所有者, 默认密码为: change_on_install

               >>当数据库安装的时候,自动创建

               >>自动授权DBA ROLE

               >>默认的密码为 change_on_install

               >>拥有数据库数据字典的 base table 和 views

               >>当通过SYSDBA连接时(conn  /as sysdba) 默认的用户就是SYS

  SYS是拥有数据库的最高权限,一般情况下应该从不被修改,数据库用户也不要通过SYS账户链接oracle 数据库,简而言之,就是一般情况下不要动

   (Tables in the SYS schema are manipulated only by the database. They should never be modified by any user or database administrator, and no    one should create any tables in the schema of user SYS. Database users should not connect to the Oracle database using the SYS account.)

   (important   SYS owns the oracle data dictionary. Every object in the database (tables, views, packages, procedures, etc. ) all have a single owner. For the database dictionary, and a whole lot of special tables (performance views and the like) are all owned by the SYS user.)

      ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------      

       SYSTEM  

                    >>当数据库安装的时候自动创建

                    >>自动被授予DBA ROLE

                    >>有一个默认的密码: manager

                    >>能够用于创建表和视图显示管理员的信息

                    >>oracle 数据库创建内部表和视图的很好的选择和工具

永远不要使用SYSTEM schema 去存储一些非管理员用户的信息,常用于数据的备份和恢复,

used to create additional tables and views that display administrative information ,used to create internal tables and views used by various Oracle database options and tools ,Never use the SYSTEM schema to store tables of interest to non-administrative users

SYS 比 SYSTEM拥有更高一级的权限。

REF  还有一点区别: SYS 可以创建数据库  SYSTEM不可以创建数据库

2:sqlplus 连接数据库

  在windows情况下: 

                 命令提示符下   command :    sqlplus   nolog

                                             command:      connect   / as sysdba

                                              command:       startup

关于以上命令为什么没有输入密码:

                          是因为我的操作系统是权限是管理员,这样oracle 认为能够获取操作系统的管理员的权限的用户就不需要验证了,直接能够登陆,

如果是通过其他客户端登陆,需要密码验证。(其他方式指客户端和服务器不在同一个物理机上)

   如果普通用户需要密码的时候登陆方式:  mydb/mydb@orcl

 判断启动是否成功  可以通过查询表:  select  *  from   v$sga_dynamic_components

 如果有数据 就启动成功。

 

3:启动参数管理       

                oracle启动参数 9i以前是在 pfileSID.ora文件中 有两种类型:
                         1:显式参数类型        在pfileSID.ora中列出的参数就是显示参数
                          2:隐式参数类型       在 pfileSID.ora中没有列出的参数为隐式参数,
没有列出的参数的使用oralce的默认参数作为启动参数。
  多个启动文件可以同时存在,但是只能指定其中一个参数为启动参数。
这些参数也可以以查询表的形式获取: 在表  v$parameter中。
sqlplus中可以设定 每一列暂用字符的个数:  
例如有一列为  name  ,一列为value,
通过 col name  format  a20
         col  value  format   a30    来设定。

查询相应的参数的命令:  show parameter  sga 
含有相应参数的参数名。

4: oracle  SID

关于SID  oracle大牛 有一段很NB的回答:
        What is a SID, how to change it, how to find out what it is


5:关于启动参数文件 pfile和spfile

        ASK  TOM
                     
                    当一个oracle instance启动时,这个instance的特性是通过定义的初始化参数文件设定的。
                    这些初始化参数文件是存储在pfile或者spfile中,spfiles在oracle 9i及其以后的版本中出现,
           SPILES vs  PFILE  advantage:
                        >> An SPFILE can be backed-up with RMAN (RMAN cannot backup PFILEs)  ?
                  >>减少了人为的错误,spfile是在数据库服务器上,在接受修改前要进行检测。
                  >>减少了配置不统一的问题(因为pfile是存储在客户端,当用户访问时会用自己的pfile),这样只需要服务器上有一个spfile即可。
                  >>容易找到
   
             SPILE  VS  PFILE   difference
            pfile是静态的,客户端的 text文件,必须被更新通过文本编辑器,example: notepad vi,这个文件常常作用于服务器上,如果你想从远程机器上开启oracle需要一个本地拷贝,DBA常常引用这个文件作为INIT.ORA文件。
            SPFILE(server parameter file),换句话来说:你仅仅通过alert  system set 命令,这意味着你不需要一个本地拷贝去启动一个oracle database,

           如何得知 oralce使用的是 PFILE 还是SPFILE:
                执行下列语句可以得出:
            
SQL> SELECT DECODE(value, NULL, 'PFILE', 'SPFILE') "Init File Type"  2         FROM sys.v_$parameter WHERE name = 'spfile';Init F------SPFILE
可以看出我的是 SPFILE文件。

oracle 中 PFILE 和 SPIFLE 的位置:
  • Try to use the spfile${ORACLE_SID}.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)
  • Try to use the spfile.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)
  • Try to use the init${ORACLE_SID}.ora file in $ORACLE_HOME/dbs (Unix) or ORACLE_HOME/database (Windows)
启动的时候能够指定参数文件位置:
 STARTUP PFILE='/oradata/spfileORCL.ora'
spfile是 是二进制文件,不能用普通的软件打开,乱码多,
在linux环境下:可以通过 strings filename more进行显示

    修改spfile文件里面的信息:登录到sqlplus:
ALTER system set parameter=value <comment='text'> <deferred>
<scope = memory|spfile|both> <sid='sid|*'>
scope  memory 是修改内存中,spfile文件中的参数, both两个都修改
deferred 是否立即修改, 如果defered是这次不修改,下次登录的时候修改。 

单机的系统 一个实例instance 对应一个数据库
在构建大型的数据库中, 多个instance对应一个数据库.
我系统中 spfile的路径为: D:\app\topwqp\product\11.1.0\db_1\database

     如果想要修改oracle的默认的参数的命令为:
    
    ALTER SYSTEM RESET undo_suppress_errors  scope=both sid='*' ;

关于alter system set parameter 语句中的意义:

The SCOPE parameter can be set to SPFILE, MEMORY or BOTH:

- MEMORY: Set for the current instance only. This is the default behaviour if a PFILE was used at STARTUP.

- SPFILE: update the SPFILE, the parameter will take effect with next database startup

- BOTH: affect the current instance and persist to the SPFILE. This is the default behaviour if an SPFILE was used at STARTUP.
The COMMENT parameter (optional) specifies a user remark.

The SID parameter (optional; only used with RAC) indicates the instance for which the parameter applies (Default is *: all Instances).

Use the following syntax to set parameters that take multiple (a list of) values:

ref

6:启动到关闭数据库的状态

谁有权限启动数据库:

       1: 如果你是操作系统的管理员,当然可以启动和关闭数据库
      2: 当授权 SYSDBA 或者 SYSOPER 时可以启动和关闭数据库

数据库启动的几个状态:



nomount:  开启了 一个没有mounting instance ,不允许访问数据库,通常仅仅用于数据库的创建或者通过控制文件重建。
mount: 开启一个mount 的instance,但是是关闭的,这个状态允许DBA执行归档,或者数据恢复备份等,但是不允许普通用户访问。。
open: 这个模式没有什么限制,允许所有的用户访问,或者只允许数据库管理员访问。
force:强制instance启动当在启动或者关闭中出现问题时,
open recover:看英文。


shutdown   到 oracle的联机文档中的  database  concept中寻找,
no mount 状态: starup nomount
表示 oracle的后台进程已经启动起来了,共享内存已经分配:
这个时候没有任务一个数据库和它建立连接,
mounted  状态是把 instance 和 database建立起来,
就是把内存和数据库建立起来连接,
怎样挂载instance 和 database呢 通过 Control---file;
这个时候数据库建立起来了,用户还不能进行访问。
从 nomount 到 mount 状态 的语句为:
alter database mount;
这个时候数据库是关闭状态,普通用户不能关联数据库,只有
数据库管理员可以做一些其他的操作。
mount 数据库的文件和联机文件都会打开。
 
打开数据时:
首先根据 control file 找到 online datafile 和 redo log files
然后进行连接这两个文件,如果这两个文件损坏,数据库就无法打开,
这个时候需要到mount状态 恢复相应的文件,然后再打开。


  • NOMOUNT—Start the instance without mounting a database. This does not allow access to the database and usually would be done only for database creation or the re-creation of control files.

  • MOUNT—Start the instance and mount the database, but leave it closed. This state allows for certain DBA activities, but does not allow general access to the database.

  • OPEN—Start the instance, and mount and open the database. This can be done in unrestricted mode, allowing access to all users, or in restricted mode, allowing access for database administrators only.

  • FORCE—Force the instance to start after a startup or shutdown problem.

  • OPEN RECOVER—Start the instance and have complete media recovery begin immediately.


原创粉丝点击