Oracle管理与维护.安装创建启动关闭数据库的常见问题(一)

Oracle管理与维护.安装创建启动关闭数据库的常见问题(一)

20070605

草木瓜


一、内容概要

    本文主要介绍Oracle在Linux下安装创建启动数据库过程中常见问题的解决方法。这部分
内容在配置管理服务器系列文章中也已有比较详细的提及,这里做一次专题总结。


二、Oracle数据库在Linux环境下的安装

    《虚拟机RedHatLinux9安装Oralce92全过程》
    http://blog.csdn.net/liwei_cmg/archive/2006/05/28/759286.aspx
    《从服务器构建说起(四).Linux下安装配置Oracle》
    http://blog.csdn.net/liwei_cmg/archive/2007/04/18/1568923.aspx
   
三、创建数据库

    创建数据库通常使用两种方式:
   
    A.oracle自带的database configuration assistent
   
    图形化安装模式十分简单,不在赘述,在linux下使用database configuration assistent
    容易出错,并不推荐使用。不过dbca有个十分有用的功能,那就是生成建库脚本。
   
     
       问题一.点击创建数据库后,出现错误:home/oracle/ora9/oracle/bin/dbca: line 124: 31614 Segmentation fault      $JRE_DIR/bin/jre -DORACLE_HOME=$OH -DJDBC_PROTOCOL=thin -mx64m -classpath $CLASSPATH oracle.sysman.assistants.dbca.Dbca $ARGUMENTS
        图形化界面消失。
   
        修改dbca,将最后一行改为:
     # Run DBCA
     $JRE_DIR/bin/jre -native -DORACLE_HOME=$OH -DJDBC_PROTOCOL=thin -mx64m -classpath $CLASSPATH oracle.sysman.assistants.dbca.Dbca $ARGUMENTS
     fi
    即添加了一个native参数即可。

      
       问题二.创建数据库过程中出现ora-29807错误
     
      ORA-29807: specified operator does not exist
    This is a known issue (bug 2925665). You can click on the "Ignore" button to continue.
    Once DBCA has completed database creation, remember to run the 'prvtxml.plb' script
    from $ORACLE_HOME/rdbms/admin independently, as the user SYS. It is also advised
    to run the 'utlrp.sql' script to ensure that there are no invalid objects in the database at
    this time.

        这是oracle本身的bug,此时可选择“ignore”,数据库建立成功后,以sys用户执行rdbms/admin/utlrp.sql即可解决。
    
    
    问题三.建库最后弹出用户名密码提示框,输入密码后退出后,画面僵死无反应
    
    这个问题很可能来源于dbca的最后一行设置了native参数,解决方法和问题一恰好相反。这
    时即使kill掉dbca,数据库也是无法启动的。至于如何解决启动的问题,见数据库启动问题
    一节。
   
   
    B.使用脚本 create database 语句创建数据库

    在database configuration assistent最后一步存为script脚本,通过oracle用户运行
    即可。
   
    主要由以下这些文件组成,linux.sh是主shell:
  CreateDBCatalog.sql  CreateDB.sql  linux.sh
  CreateDBFiles.sql    init.ora      postDBCreation.sql

    成功后显示:

  SQL> show errors;
  No errors.
  SQL>
  SQL> Rem ===========================================================================
  SQL> Rem END utlrcmp.sql
  SQL> Rem ===========================================================================
  SQL> execute utl_recomp.recomp_serial();
  
  PL/SQL procedure successfully completed.
  
  SQL>
  SQL> Rem =====================================================================
  SQL> Rem Run component validation procedure
  SQL> Rem =====================================================================
  SQL>
  SQL> EXECUTE dbms_registry.validate_components;
  
  PL/SQL procedure successfully completed.
  
  SQL>
  SQL> Rem ===========================================================================
  SQL> Rem END utlrp.sql
  SQL> Rem ===========================================================================
  SQL> shutdown ;
  Database closed.
  Database dismounted.
  ORACLE instance shut down.
  SQL> connect SYS/change_on_install as SYSDBA
  Connected to an idle instance.
  SQL> set echo on
  SQL> spool /home/ora/ora9/oracle/assistants/dbca/logs/postDBCreation.log
  SQL> create spfile='/home/ora/ora9/oracle/dbs/spfilelinux.ora' FROM pfile='/home/ora/ora9/admin/linux/scripts/init.ora';
  
  File created.
  
  SQL> startup ;
  ORACLE instance started.
  
  Total System Global Area  122754448 bytes
  Fixed Size                   451984 bytes
  Variable Size              58720256 bytes
  Database Buffers           62914560 bytes
  Redo Buffers                 667648 bytes
  Database mounted.
  Database opened.
  SQL> exit;
  Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
  With the Partitioning, OLAP and Oracle Data Mining options
  JServer Release 9.2.0.4.0 - Production
  
  

四、启动数据库

    ORACLE数据库启动需要管理员权限的用户登陆。一般地使用如下命令操作:
    #sqlplus /nolog
    SQL> conn / as sysdba
  
  注:<dbname>表示是数据库名的参数,如 alter database linuxdb open。

    ORACLE数据库启动可以分为三个步骤:

  A.创建ORACLE实例(非安装阶段)
    -----------------------------------------------------------
   
    SQL> startup nomount
   
  这个步骤只创建了Oracle实例。首先读取init.ora初始化参数文件,启动后台相关进程和
初始化系统全局区SGA。nomount状态下常用于修复数据库,如重建参数文件,控制文件和数据库
等。
    init.ora参数文件定义了包括内存结构大小,控制文件,进程数,游标数,回滚段方式等
重要的初始化数据库参数。数据库实例名根据db_name设置,但不一定要与打开的数据库名称相
同。实例打开后,系统将显示一个SGA内存结构和大小的列表,如下所示:

  ORACLE instance started.
  
  Total System Global Area  202445884 bytes
  Fixed Size                   451644 bytes
  Variable Size              83886080 bytes
  Database Buffers          117440512 bytes
  Redo Buffers                 667648 bytes


  B.用实例安装数据库(安装阶段)
    -----------------------------------------------------------
   
    SQL> startup nomount
  SQL> alter database <dbname> mount 
  
  或者
  
  SQL> startup mount <dbname>
  
    打开实例并安装数据库。ORACLE读取控制文件中关于数据文件和重作日志文件的内容,确认
数据文件和联机日志文件的位置,但此时不对数据文件和日志文件进行校验检查。这种方式常在
数据库维护操作中使用。如数据库日志归档,数据库介质恢复,使数据文件联机或脱机,重新定
位数据文件、重做日志文件,打开归档方式等。

  通过下面命令可以更改到前一状态
  
  SQL > alter database <dbname> dismount


  C.打开数据库(打开阶段)
    -----------------------------------------------------------
   
    SQL> startup nomount
  SQL> alter database <dbname> mount 
  SQL> alter database <dbname> open
  
  或者
  
  SQL> startup open <dbname> 
  
  或者
  
  SQL> startup
  
  此时数据库打开,使数据文件和重作日志文件在线,通常还会请求一个或者是多个回滚段。
数据库系统处于正常工作状态,可以接受用户请求。

  通过下面命令可以更改到前一状态
  
  SQL > alter database <dbname> close
  
  
五、其他的一些启动数据库方式

   A. startup restrict  约束方式启动 
    这种方式能够启动数据库,但只允许具有一定特权的用户访问。非特权用户访问时,会出现
以下提示: 
    ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege


  B. startup force 强制启动方式 
    当不能关闭数据库时,可以用startup force来完成数据库的关闭再启动,不常用。 


  C. startup pfile=参数文件名 
    带初始化参数文件的启动方式。先读取参数文件,再按参数文件中的设置启动数据库 
    如:startup pfile='/home/ora/ora9/oracle/dbs/initlinux.ora';
   
    D. 并行服务时的选项,即可以启动多个实例同时访问一个数据库。  
    startup exclusive   独占方式打开数据库(只能运行一个实例,默认方式)   
    startup parallel    并行方式打开数据库  


六、关闭数据库


    数据库的关闭,有四种选项。

  A. shutdown normal

  这是数据库关闭shutdown命令的缺省选项。命令执行后,不允许任何新的数据库连接。在数据
库关闭之前,Oracle将等待目前连接的所有用户都从数据库中退出后才开始关闭数据库。采用这种
方式关闭数据库,在下一次启动时不需要进行任何的实例恢复。但需要注意一点的是,采用这种方
式,必须等待用户,时间不能确定。

  B. shutdown immediate

  这是最常用的一种关闭数据库的方式,当前正在被Oracle处理的SQL语句立即中断,系统中任
何没有提交的事务全部回滚。如果系统中存在一个很长的未提交的事务,采用这种方式关闭数据库
也需要一段时间(该事务回滚时间)。系统不等待连接到数据库的所有用户退出系统,强行回滚当
前所有的活动事务,然后断开所有的连接用户。
    实际应用中最为推荐的方式,但是对于繁忙的数据库,执行命令后也迟迟不能关闭,这时可以
手工kill数据库后台进程(oraSID)再行关闭。

  C. shutdown transactional

  该选项仅在Oracle8i后才可以使用。该命令常用来计划关闭数据库,它使当前连接到系统且正
在活动的事务执行完毕,运行该命令后,任何新的连接和事务都是不允许的。在所有活动的事务完
成后,数据库将和shutdown immediate同样的方式关闭数据库。

  D. shutdown abort

  这是关闭数据库的万不得已的最后一招,没有任何办法关闭数据库的情况下才不得不采用的方
式,大概有1%~4%机率导致数据库不能启动。执行这个命令之前最好确保后台的Oracle进程基本清
除,这样能很大提高安全系数。

  执行命令后,所有正在运行的SQL语句都将立即中止。所有未提交的事务将不回滚。Oracle也
不等待目前连接到数据库的用户退出系统。下一次启动数据库时需要实例恢复,启动时间可能比平
时需要更多。

  数据库不同关闭方式对比:

                                  D   B   C   A 
    允许新的连接                  ×  ×  ×  ×
    等待直到当前会话中止          ×  ×  ×  √
    等待直到当前事务中止          ×  ×  √  √
    强制CheckPoint,关闭所有文件  ×  √  √  √
  
   
七、数据库启动问题

    A.参数文件问题
   
    SQL> startup
  ORA-01078: failure in processing system parameters
  LRM-00109: could not open parameter file '/home/ora/ora9/oracle/dbs/initunixdb.ora'
  
  这个问题是由于找不到默认的参数文件,解决方法:
  查看当前export中的ORACLE_SID,确认与需要启的数据库sid名一致,然后进行如下操作。
  SQL> create pfile='/home/ora/ora9/oracle/dbs/initlinuxdb.ora' from spfile='/home/ora/ora9/oracle/dbs/spfilelinux.ora';
    SQL> startup pfile='/home/ora/ora9/oracle/dbs/initlinuxdb.ora';
  
  涉及spfile和pfile的相关知识,英文原文:
  
  In Oracle Databases through 8i, parameters controling memory, processor usage, control file locations and other key parameters are kept in a pfile (short for parameter file).
  
  The pfile is a static, plain text files which can be altered using a text editor, but it is only read at database startup. Any changes to the pfile will not be read until the database is restarted and any changes to a running database will not be written to the pfile.
  
  Due to these limitations, in 9i Oracle introduced the spfile (server parameter file). The spfile cannot be edited by the DBA; instead it is updated by using ALTER SYSTEM commands from within Oracle. This allows parameter changes to be persistent across database restarts, but can leave you in a pinch if you need to change a parameter to get a database started but you need the database running to change the parameter.
  
  A 9i (or later) database can have either a pfile or an spfile, or even both, but how can you tell which you have? If you have both, which one is being used? How do you go from one to the other? How do you get out of the chicken-and-the-egg quandary of a database that will not start up without you changing a parameter that’s in that file you can’t update unless the database is up?
  
  Note: This information is based on an Oracle 9i installation on Solaris. Your mileage may vary. I have also chosen to ignore issues of RAC installation. In my example I have used ORADB as my SID.
  
  Am I using a pfile or an spfile?
  
  The first thing to check is if you have a pfile or spfile. They can be specified at startup or found in the default location. The default path for the pfile is $ORACLE_HOME/dbs/init$ORACLE_SID.ora and the default for the spfile is $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora.
  
  If both a pfile and an spfile exist in their default location and the database is started without a pfile='/path/to/init.ora' then the spfile will be used.
  
  Assuming your database is running you can also check the spfile parameter. Either the command SHOW PARAMETER spfile or SELECT value FROM v$parameter WHERE name='spfile'; will return the path to the spfile if you are using one. If the value of spfile is blank you are not using an spfile.
  
  The path to the spfile will often be represented in the database by ?/dbs/[email protected]. This may seem cryptic, but Oracle translates ? to $ORACLE_HOME and @ to $ORACLE_SID so this string translates to the default location of the spfile for this database.
  
  How can I create an spfile from a pfile?
  
  As long as your pfile is in the default locations and you want your spfile in the default location, you can easily create an spfile with the command CREATE SPFILE FROM PFILE;.
  
  If you need to be more specific about the locations you can add paths to the create command like this:
  
  CREATE SPFILE='/u01/app/oracle/product/9.2/dbs/spfileORADB.ora'
  FROM PFILE=’/u01/app/oracle/product/9.2/dbs/initORADB.ora’;
  
  These commands should work even when the database is not running! This is important when you want to change a database to use an spfile before you start it.
  
  How can I create a pfile from an spfile?
  
  The commands for creating a pfile are almost identical to those for creating a spfile except you reverse the order of spfile and pfile:
  
  If your pfile is in the default location and you want your spfile created there as well run CREATE SPFILE FROM PFILE;.
  
  If you have, or want them in custom locations specify the paths like this:
  
  CREATE PFILE='/u01/app/oracle/product/9.2/dbs/initORADB.ora'
  FROM SPFILE=’/u01/app/oracle/product/9.2/dbs/spfileORADB.ora’;
  
  Again, this can be done without the database running. This is useful when the database fails to start due to a parameter set in the spfile. This is also a good step to integrate into your backup procedures.
  
  How can I see what’s in my spfile
  
  To view the settings in the spfile we have two options: First, we can use the command above to create a pfile from the spfile. This is simple, and fairly fast, but unnecessary if the database is running.
  
  The better way, if the database is running, is to select the parameter you want to view from the oracle view v$spparameter with a command like this:
  
  SELECT value FROM v$spparameter WHERE name='processes';
  
  If you try to view the spfile with a text editor it may seem like it is plain text, but beware! The spfile will not behave correctly (if it works at all) if it has been edited by a text editor.
  
  How can I update values in my spfile?
  
  The values in spfile are updated with the ALTER SYSTEM command, but to update the spfile we add an additional parameter of SCOPE.
  
  ALTER SYSTEM SET processes=50 SCOPE=spfile;
  
  This command would update the parameter processes in the spfile. Since this parameter can only be set at startup, we say SCOPE=spfile and the change will be reflected when the database is restarted. Other options for SCOPE are memory which only changes the parameter until the database is restarted, and both which changes the instance immediately and will remain in effect after the database is restarted.
  
  How can I update values in my spfile when my database won’t start?
  
  So your database won’t startup because of a problem in your spfile. You can’t edit it with a text editor and you can’t use ALTER SYSTEM because your database is not running. It sounds like a problem, but really isn’t. Here’s what you do:
  
  Connect up to your database as sysdba. You should get the message Connected to an idle instance
  
  Run the command CREATE pfile FROM spfile; specifying the location as above if necessary. You should now have a fresh version of the spfile.
  
  Edit the pfile to update the parameter you need to update.
  
  Run the command CREATE spfile FROM pfile; to move the changes you have just made back into the spfile.
  
  Startup the database normally. It should read the changed spfile and start up correctly. You can optionally delete the pfile if you are done.  


    B. startup过程中出错 ORA-01102: cannot mount database in EXCLUSIVE mode
   
    SQL> conn /as sysdba
  Connected to an idle instance.
  SQL> startup
  ORACLE instance started.
  Total System Global Area  202445884 bytes
  Fixed Size                   451644 bytes
  Variable Size              83886080 bytes
  Database Buffers          117440512 bytes
  Redo Buffers                 667648 bytes
  ORA-01102: cannot mount database in EXCLUSIVE mode
  
  原因是$ORACLE_HOME/dbs目录下的lkSID,即lkLINUX文件被占用。root用户查看:
  # fuser -u lkLINUX
  lkLINUX:   13468(oracle) 13480(oracle)
  释放文件
  # fuser -k lkLINUX
  
  关于ORA-01102的错误,这里有详细说明:
  http://www.hellodba.com/cases/case-unexception_down.htm


    C. startup过程中提示 ORA-01991 error opening password file ...
  SQL> startup
  ORACLE instance started.
  
  Total System Global Area  202445884 bytes
  Fixed Size                   451644 bytes
  Variable Size              83886080 bytes
  Database Buffers          117440512 bytes
  Redo Buffers                 667648 bytes
  ORA-01990: error opening password file '/home/ora/ora9/oracle/dbs/orapw'
  ORA-27037: unable to obtain file status
  Linux Error: 2: No such file or directory
  Additional information: 3

    原因是丢失密码验证文件,重建即可。
   
    [ora@liwei dbs]$ orapwd
  Usage: orapwd file=<fname> password=<password> entries=<users>
  
    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.
   
  [ora@liwei dbs]$ orapwd file=/home/ora/ora9/oracle/dbs/orapwlinux password=sys entries=10

  注:忘记sys,system密码时,可以用这种方式重建密码文件,不过还有更简单的方式,直接
  conn / as sysdba , alter user sys identified by sys 。

    D. startup 过程中提示 ORA-12701: CREATE DATABASE character set is not known
   
    确认ORA_NLS33环境变量的路径正确性。
   
   
八、数据库网络设置


    网络设置方面包括,listen和tns 都有相对应的图形化界面工具 netca netmgr。
    listen tns文件均位于/home/ora/ora9/oracle/network/admin 即$ORACLE_HOME/network/admin
    listener 服务器的实例监听 供网络内用户访问本机数据库,配置后,lsnrctl start即可。
    tnsnames 用于访问其他网络主机数据库。在linux/unix下要注意是Unix回车字符,最好使用
vi操作。实际应用中常出现由于回车符不正确不能被ORACLE识别。
   
   
九、总结

    本文所提及问题皆在实践过程中出现过,这里也仅是罗列问题,ORACLE体系十分复杂,这
里只是从应用角度出发。
     

你可能感兴趣的:(Oracle管理与维护.安装创建启动关闭数据库的常见问题(一))