当前位置: 首页 > Oracle, oracle 10g > 正文

OCM考试第一题–手动建库及常见错误

OCM考试第一道题就是手动建库,之前曾写过关于手动建库的文章,这次当作复习,再记录一下实验过程和常见的错误。
实验环境:OEL5.4 ORACLE 10.2.0.5.0
实验过程
1.创建ORACLE用户

[root @rac2]# groupadd -g 1000 oinstall
[root @rac2]# groupadd -g 1200 dba
[root @rac2]# useradd -u 1100 -g oinstall -G dba oracle
[root @rac2]# passwd oracle

2.创建所需的目录结构

[root @rac2]# mkdir -p /u01/app/oracle/admin/dbdream/adump
[root @rac2]# mkdir -p /u01/app/oracle/admin/dbdream/bdump
[root @rac2]# mkdir -p /u01/app/oracle/admin/dbdream/cdump
[root @rac2]# mkdir -p /u01/app/oracle/admin/dbdream/udump
[root @rac2]# mkdir -p /u01/app/oracle/oradata/dbdream/
[root @rac2]# chmod -R 755 /u01
[root @rac2]# chown -R oracle:oinstall /u01

3.切换ORACLE用户,编辑.bash_profile文件,添加环境变量

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=dbdream
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/jdk/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

4.安装ORACLE软件,OCM考试时,服务器上已经安装ORACLE好软件,此步骤略。
5.建立密码文件

[oracle @rac2]$ cd $ORACLE_HOME/bin
[oracle @rac2 bin]$ orapwd file=orapwdbdream password=oracle1 entries=30

6.创建参数文件

[oracle@rac2 dbs]$ cat init.ora | grep -v ^# | grep  -v ^$ > initdbdream.ora

编辑参数文件,主要修改dbname、control_files参数,注释掉db_block_buffers和shared_pool_size = 3500000参数,增加SGA_MAX_SIZE和SGA_TARGET参数,如下:

db_name=dbdream
db_files = 80                                                   # SMALL
db_file_multiblock_read_count = 8                               # SMALL
#db_block_buffers = 100                                         # SMALL
#shared_pool_size = 3500000                                     # SMALL
log_checkpoint_interval = 10000
processes = 50                                                  # SMALL
parallel_max_servers = 5                                        # SMALL
log_buffer = 32768                                              # SMALL
max_dump_file_size = 10240      # limit trace file size to 5 Meg each
global_names = TRUE
control_files = (/u01/app/oracle/oradata/dbdream/control01.ctl, /u01/app/oracle
/oradata/dbdream/control02.ctl)
sga_max_size=300M
sga_target=300M

此步骤注意事项:如果ORACLE_BASE环境变量设置正确,尽量不要手动设置adump、bdump、cdump、udump路径,如果ORACLE_BASE环境变量设置正确,ORACLE会自动找到这些dump路径,否则,手动设置后,很可能数据库启动不到nomount状态,报参数错误,后台进程XX启动失败。
7.建立SPFILE,将数据库启动到NOMOUNT状态

sqlplus / as sysdba
create spfile from pfile;
startup nomount

8.手动建库,在官方文档中,找到manually create an oracle database部分的建库命令,修改DB_NAME,PASSWORD,和文件路径,在DEFAULT TABLESPACE TBS_1后加入DATAFILE信息,官方文档中的建库命令是在开启OMF自动管理数据文件的环境下,如果没有开启OMF,就需要添加DATAFILE信息,否则会遇到以下错误并建库失败。

ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced

而告警日志中会报SQL递归错误和文件名无效,并看不出具体错误原因。

Wed Sep 26 19:42:29 CST 2012
Errors in file /u01/app/oracle/admin/dbdream/udump/dbdream_ora_13282.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-02236: invalid file name
Wed Sep 26 19:42:29 CST 2012
Errors in file /u01/app/oracle/admin/dbdream/udump/dbdream_ora_13282.trc:
ORA-01501: CREATE DATABASE failed
ORA-01519: error while processing file '?/rdbms/admin/sql.bsq' near line 6269
ORA-00604: error occurred at recursive SQL level 1
ORA-02236: invalid file name
Error 1519 happened during db open, shutting down database
USER: terminating instance due to error 1519
Instance terminated by USER, pid = 13282
ORA-1092 signalled during: CREATE DATABASE dbdream

但是只要打开trace文件,就可以清楚的看到是由于没有指定tbs_1表空间的数据文件导致创建tbs_1表空间失败。

*** 2012-09-26 19:42:29.290
ORA-00604: error occurred at recursive SQL level 1
ORA-02236: invalid file name
Offending statement at line 6269
CREATE  TABLESPACE TBS_1 DATAFILE  SEGMENT SPACE MANAGEMENT MANUAL
ORA-01501: CREATE DATABASE failed
ORA-01519: error while processing file '?/rdbms/admin/sql.bsq' near line 6269
ORA-00604: error occurred at recursive SQL level 1
ORA-02236: invalid file name

如果参数文件中设置OMF相关参数,开启OMF功能,这个建库SQL是可以正确建库的。

SQL> show parameter db_create
NAME                            TYPE    VALUE
----------------------------   ------   ------------------------
db_create_file_dest            string   /u01/app/oracle/oradata/
db_create_online_log_dest_1    string   /u01/app/oracle/oradata/

在没有指定tbs_1表空间数据文件的情况下,OMF会自动管理,生成的数据文件名称也相当另类。

SQL> select t.name tname,d.name fname from v$tablespace t,v$datafile d where
t.ts#=d.ts#;
TNAME    FNAME
-------  ------------------------------------------------------------------
SYSTEM   /u01/app/oracle/oradata/dbdream/system01.dbf
UNDOTBS  /u01/app/oracle/oradata/dbdream/undotbs01.dbf
SYSAUX   /u01/app/oracle/oradata/dbdream/sysaux01.dbf
TBS_1    /u01/app/oracle/oradata/dbdream/datafile/o1_mf_tbs_1_865v87ft_.dbf

如果没有特别要求,本人还是喜欢不用OMF来管理数据文件,下面是手动建库的SQL语句。

CREATE DATABASE dbdream
   USER SYS IDENTIFIED BY oracle1
   USER SYSTEM IDENTIFIED BY oracle1
   LOGFILE GROUP 1 ('/u01/app/oracle/oradata/dbdream/redo01.log') SIZE 100M,
           GROUP 2 ('/u01/app/oracle/oradata/dbdream/redo02.log') SIZE 100M,
           GROUP 3 ('/u01/app/oracle/oradata/dbdream/redo03.log') SIZE 100M
   MAXLOGFILES 5
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 1
   MAXDATAFILES 100
   MAXINSTANCES 1
   CHARACTER SET US7ASCII
   NATIONAL CHARACTER SET AL16UTF16
   DATAFILE '/u01/app/oracle/oradata/dbdream/system01.dbf' SIZE 325M REUSE
   EXTENT MANAGEMENT LOCAL
   SYSAUX DATAFILE '/u01/app/oracle/oradata/dbdream/sysaux01.dbf' SIZE 325M REUSE
   DEFAULT TABLESPACE tbs_1 datafile '/u01/app/oracle/oradata/dbdream/tbs_1.dbf' size 50M
   DEFAULT TEMPORARY TABLESPACE tempts1
      TEMPFILE '/u01/app/oracle/oradata/dbdream/temp01.dbf'
      SIZE 20M REUSE
   UNDO TABLESPACE undotbs
      DATAFILE '/u01/app/oracle/oradata/dbdream/undotbs01.dbf'
      SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

如果有要求必须建立一个OMF管理数据文件的表空间,那么在参数文件中设置db_create_file_dest和db_create_online_log_dest_1参数,并在建库时不指定tbs_1表空间的数据文件即可。
9.跑脚本建立数据字典,正常情况下,手动建立数据库后需要跑catalog.sql和catproc.sql两个脚本,但是现在的OCM考试在做第一道题时,如果跑了这两个脚本,很可能被视为作弊,ORACLE会自欺欺人的解释说因为你已经知道下一套题是什么了。

SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql

10.配置监听,此过程在OCM第一道题时也不需要配置,在$ORACLE_HOME/network/admin目录下建立listener.ora文件,并添加以下内容。

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = rac2)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

启动监听后,远程登录数据库测试。

C:Usersstream>sqlplus sys/oracle1@192.168.249.200/dbdream as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期三 9月 26 11:19:13 2012
Copyright (c) 1982, 2010, Oracle.  All rights reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

本实验由windows版11.2.0.1客户端远程登录linux版10.2.0.5数据库成功。

本文固定链接: https://www.dbdream.com.cn/2012/09/ocm%e8%80%83%e8%af%95%e7%ac%ac%e4%b8%80%e9%a2%98-%e6%89%8b%e5%8a%a8%e5%bb%ba%e5%ba%93%e5%8f%8a%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af/ | 信春哥,系统稳,闭眼上线不回滚!

该日志由 dbdream 于2012年09月26日发表在 Oracle, oracle 10g 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: OCM考试第一题–手动建库及常见错误 | 信春哥,系统稳,闭眼上线不回滚!
关键字: , , , ,

OCM考试第一题–手动建库及常见错误:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter