Chinaunix首页 | 论坛 | 博客
  • 博客访问: 785097
  • 博文数量: 56
  • 博客积分: 451
  • 博客等级: 下士
  • 技术积分: 1431
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-20 11:14
文章分类

全部博文(56)

文章存档

2013年(35)

2012年(21)

分类: Oracle

2013-07-08 11:18:16

最近参加oracle认证培训,老师讲了手动建库的方法,平时的操作不太系统,今天就顺便系统总结一下:
1.创建必要的目录
2.初始化参数文件
3.执行建库语句
4.执行必要脚本

1.首先创建必要的目录

点击(此处)折叠或打开

  1. [oracle@DB ~]$ cd $ORACLE_BASE/oradata
  2. [oracle@DB oradata]$ mkdir BOB
  3. [oracle@DB BOB]$ mkdir disk1 disk2 disk3 disk4 disk5 bdump cdump udump
  4. [oracle@DB BOB]$ ll
    total 32
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 09:53 bdump
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 09:44 cdump
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 15:34 disk1
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 15:34 disk2
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 15:56 disk3
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 15:35 disk4
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 15:35 disk5
    drwxr-xr-x 2 oracle oinstall 4096 Jul  7 09:44 udump
2.创建初始化参数文件
oracle参数文件有pfile和spfile两种,spfile是二进制文件,pfile是文本文件,
查看数据库是用pfile启动还是spfile启动的方式为

点击(此处)折叠或打开

  1. SQL> show parameter spfile;

  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. spfile string /u01/app/oracle/product/11.2.0/dbhome_1/dbs/spfileorcl.ora
如果VALUE处是空的,就说明是按照pfile来启动的,发现首次安装oracle 11g软件并建库后
是生成了spfile,没有生成pfile,可以手动spfile生成pfile.

点击(此处)折叠或打开

  1. SQL> create pfile from spfile; 
当生成了pfile后,若想切换用pfile来启动数据库,有两种方式:

点击(此处)折叠或打开

  1. 手动指定初始化参数文件
  2. SQL> startup pfile=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora --这是第一种方法
  3. 修改spfile的名字,然后再启动数据库。
扯远了,下面开始创建初始化参数文件
oracle的初始化参数文件一般存放在$ORACLE_HOME/dbs下面:

点击(此处)折叠或打开

  1. [oracle@DB BOB]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/dbs/
  2. [oracle@DB dbs]$ vi initBOB.ora ---文件内容如下
  3. sga_target=400m
    db_name=BOB
    control_files='/u01/app/oracle/oradata/BOB/disk1/control01.ctl',
    '/u01/app/oracle/oradata/BOB/disk2/control01.ctl','/u01/app/oracle/oradata/BOB/disk3/control01.ctl',
    undo_management=auto
    undo_tablespace=undotbs
    user_dump_dest=/u01/app/oracle/oradata/BOB/udump
    background_dump_dest=/u01/app/oracle/oradata/BOB/bdump
    core_dump_dest=/u01/app/oracle/oradata/BOB/cdump
3.执行建库语句
现在就可以把BOB这个库启动到nomount阶段

点击(此处)折叠或打开

  1. [oracle@DB dbs]$ export ORACLE_SID=BOB
  2. [oracle@DB dbs]$ sqlplus / as sysdba


    SQL*Plus: Release 11.2.0.1.0 Production on Sun Jul 7 23:25:46 2013


    Copyright (c) 1982, 2009, Oracle.  All rights reserved.




    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
  3. SQL> startup nomount
    ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
    ORACLE instance started.


    Total System Global Area  417546240 bytes
    Fixed Size                  2213936 bytes
    Variable Size             134219728 bytes
    Database Buffers          272629760 bytes
    Redo Buffers                8482816 bytes
    SQL> select instance_name,status from v$instance;


    INSTANCE_NAME    STATUS
    ---------------- ------------
    BOB              STARTED

启动到nomount阶段之后,接下来就可以执行建库语句了
oracle 官方给出的建库语句如下:

点击(此处)折叠或打开

  1. CREATE DATABASE mynewdb
  2.    USER SYS IDENTIFIED BY sys_password
  3.    USER SYSTEM IDENTIFIED BY system_password
  4.    LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/my/redo01b.log') SIZE 100M BLOCKSIZE 512,
  5.            GROUP 2 ('/u01/logs/my/redo02a.log','/u02/logs/my/redo02b.log') SIZE 100M BLOCKSIZE 512,
  6.            GROUP 3 ('/u01/logs/my/redo03a.log','/u02/logs/my/redo03b.log') SIZE 100M BLOCKSIZE 512
  7.    MAXLOGFILES 5
  8.    MAXLOGMEMBERS 5
  9.    MAXLOGHISTORY 1
  10.    MAXDATAFILES 100
  11.    CHARACTER SET US7ASCII
  12.    NATIONAL CHARACTER SET AL16UTF16
  13.    EXTENT MANAGEMENT LOCAL
  14.    DATAFILE '/u01/app/oracle/oradata/mynewdb/system01.dbf' SIZE 325M REUSE
  15.    SYSAUX DATAFILE '/u01/app/oracle/oradata/mynewdb/sysaux01.dbf' SIZE 325M REUSE
  16.    DEFAULT TABLESPACE users
  17.       DATAFILE '/u01/app/oracle/oradata/mynewdb/users01.dbf'
  18.       SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
  19.    DEFAULT TEMPORARY TABLESPACE tempts1
  20.       TEMPFILE '/u01/app/oracle/oradata/mynewdb/temp01.dbf'
  21.       SIZE 20M REUSE
  22.    UNDO TABLESPACE undotbs
  23.       DATAFILE '/u01/app/oracle/oradata/mynewdb/undotbs01.dbf'
  24.       SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
根据自己的环境修改如下:

点击(此处)折叠或打开

  1. SQL> CREATE DATABASE BOB
  2.        LOGFILE GROUP 1 ('/u01/app/oracle/oradata/BOB/disk1/redo01.log',
  3.                         '/u01/app/oracle/oradata/BOB/disk2/redo01.log') SIZE 100M,
  4.                GROUP 2 ('/u01/app/oracle/oradata/BOB/disk1/redo02.log',
  5.                         '/u01/app/oracle/oradata/BOB/disk2/redo02.log') SIZE 100M,
  6.                GROUP 3 ('/u01/app/oracle/oradata/BOB/disk1/redo03.log',
  7.                         '/u01/app/oracle/oradata/BOB/disk2/redo03.log') SIZE 100M
  8.        CHARACTER SET zhs16gbk
  9.        NATIONAL CHARACTER SET AL16UTF16
  10.       DATAFILE '/u01/app/oracle/oradata/BOB/disk3/system01.dbf' SIZE 325M REUSE
  11.       EXTENT MANAGEMENT LOCAL
  12.       SYSAUX DATAFILE '/u01/app/oracle/oradata/BOB/disk4/sysaux01.dbf' SIZE 325M REUSE
  13.       DEFAULT TEMPORARY TABLESPACE tempts
  14.          TEMPFILE '/u01/app/oracle/oradata/BOB/disk5/temp01.dbf'
  15.          SIZE 20M REUSE
  16.       UNDO TABLESPACE undotbs
  17.          DATAFILE '/u01/app/oracle/oradata/BOB/disk4/undotbs01.dbf'
  18.          SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
  19. Database created.
上述语句的注意事项:

Tips:

  • Ensure that all directories used in the CREATE DATABASE statement exist. The CREATE DATABASE statement does not create directories.

  • If you are not using Oracle Managed Files, then every tablespace clause must include a DATAFILE or TEMPFILE clause.

  • If database creation fails, then you can look at the alert log to determine the reason for the failure and to determine corrective actions. See "Viewing the Alert Log". If you receive an error message that contains a process number, then examine the trace file for that process. Look for the trace file that contains the process number in the trace file name. See "Finding Trace Files" for more information.

  • To resubmit the CREATE DATABASE statement after a failure, you must first shut down the instance and delete any files created by the previous CREATE DATABASE statement.

在此过程中出现什么错误,都可以监控log日志来查看,查看日志文件所在目录用如下命令:

点击(此处)折叠或打开

  1. SQL> show parameter dump;

  2. NAME TYPE VALUE
  3. ------------------------------------ ----------- ------------------------------
  4. background_core_dump string partial
  5. background_dump_dest string /u01/app/oracle/diag/rdbms/bob/BOB/trace
  6. core_dump_dest string /u01/app/oracle/oradata/BOB/cdump
  7. max_dump_file_size string unlimited
  8. shadow_core_dump string partial
  9. user_dump_dest string /u01/app/oracle/diag/rdbms/bob/BOB/trace
可以看到日志文件存放在/u01/app/oracle/diag/rdbms/bob/BOB/trace 目录下
进入找到alert_BOB.log文件即可跟踪日志信息。

4.执行脚本来创建数据字典视图及同义词以及PL/SQL包等

点击(此处)折叠或打开

  1. SQL> @?/rdbms/admin/catalog  ---创建数据字典表的视图,动态性能视图,以及一些视图的公共同义词
  2. SQL> @?/rdbms/admin/catproc  ---创建DBMS过程
  3. SQL> conn system/manager     
  4. Connected.
  5. SQL> @?/sqlplus/admin/pupbld ---让sqpplus 可以使用其他用户登录

oracle官方的说明如下:

Run the scripts necessary to build data dictionary views, synonyms, and PL/SQL packages, and to support proper functioning of SQL*Plus:
跑如下脚本来创建数据字典视图,同义词以及PL/SQL包,从而来支持SQL*Plus的正常工作:

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
@?/sqlplus/admin/pupbld.sql
EXIT

The at-sign (@) is shorthand for the command that runs a SQL*Plus script. The question mark (?) is a SQL*Plus variable indicating the Oracle home directory. The following table contains descriptions of the scripts:
@符号表示的是运行SQL*Plus脚本的简写命令,?是一个SQL*Plus变量表示ORACLE HOME目录.下面是具体的脚本描述信息


如果没有报错,就可以查看一下目前数据库的状态等信息了:

点击(此处)折叠或打开

  1. SQL> conn /as sysdba
  2. Connected.
  3. SQL> select instance_name,status from v$instance;

  4. INSTANCE_NAME STATUS
  5. ---------------- ------------
  6. BOB OPEN

  7. 1 row selected.

  8. SQL> select tablespace_name,contents,status from dba_tablespaces;

  9. TABLESPACE_NAME CONTENTS STATUS
  10. ------------------------------ --------- ---------
  11. SYSTEM PERMANENT ONLINE
  12. UNDOTBS UNDO ONLINE
  13. SYSAUX PERMANENT ONLINE
  14. TEMPTS TEMPORARY ONLINE

  15. 4 rows selected.

到此,手动建库成功执行。

阅读(6147) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

libingquan0082014-08-18 10:24:53

总结的非常棒!