使用命令行手工建立Oracle11gR2数据库

时间:2022-09-19 23:18:54

通过命令行建立一个数据库可以帮助更好的了解数据库的建库流程,今天试了试手工建立Oracle11gR2数据库,感觉和10g的手工建库流程还是有一定的区别的,10g数据库的手工方式建立可以参考大侯(secooler)的“http://space.itpub.net/519536/viewspace-667563 ”

 

下面是我的建库流程:

测试环境:

OSOEL5.6 x64

DBOracle database 11g R211.2.0.1.0

建立数据库名:prod

 

1. 配置环境变量(参考)

1)设置环境变量

[oracle@ocm ~]$ vi .bash_profile
# .bash_profile # Get the aliases and functions
if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/11.2.0.1/db_1; export ORACLE_HOME LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;export LD_LIBRARY_PATH CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;export CLASSPATH PATH=$ORACLE_HOME/bin:/usr/sbin:/sbin:$PATH; export PATH

2)生效环境变量

[oracle@ocm ~]$ source ~/.bash_profile

 

2.建立相关的目录

1dump目录和10g相比,这里只需要建立adump一个目录就可以了

[oracle@ocm ~]$ mkdir -p /u01/app/oracle/admin/prod/adump

 

2)数据文件及控制文件的存放目录

[oracle@ocm ~]$ mkdir -p /u01/app/oracle/oradata/prod

 

3.建立密码文件

[oracle@ocm ~]$ cd $ORACLE_HOME/dbs
[oracle@ocm dbs]$ orapwd
file=orapwprod password=oracle entries=30

 

4.创建参数文件

1)从init.ora文件中获得示例参数,参考了大侯的cat方法:

[oracle@ocm ~]$ cd $ORACLE_HOME/dbs

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

 

2)修改参数文件中的信息

 

主要修改下列参数

1db_name

2memory_target内存区大小

3:替换<ORACLE_BASE>标签为当前的$ORACLE_BASE中的内容

4:快速恢复区路径设置(我在这里不设置所以注释掉了)

5:修改diagnostic_dest

6:修改dispatchers中的SERVICEPRODXDB

7:添加控制文件的文件名

db_name='prod'
memory_target=600M
processes = 150
audit_file_dest='/u01/app/oracle/admin/prod/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
#db_recovery_file_dest='<ORACLE_BASE>/flash_recovery_area'
#db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=PRODXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
control_files = (/u01/app/oracle/oradata/prod/control01.ctl,/u01/app/oracle/oradata/prod/control02.ctl)
compatible ='11.2.0' 

 

5.使用之前创建的参数文件启动数据库到nomount状态下

[oracle@ocm ~]$ export ORACLE_SID=prod

[oracle@ocm ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Jul 24 18:26:51 2012

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

Connected to an idle instance.

SYS@prod>create spfile from pfile;

File created.

SYS@prod>startup nomount;
ORACLE instance started. Total System Global Area
626327552 bytes Fixed Size 2215944 bytes Variable Size 373297144 bytes Database Buffers 247463936 bytes Redo Buffers 3350528 bytes

 

6.10gR2中本来是需要手动修改undo_managementjob_queue_processes等参数,但是show parameter后发现这些参数在11gR2版本中的值都已经符合要求,也就不需要修改了。

SYS@prod>show parameter undo_management

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
undo_management                      string      AUTO

SYS@prod>show parameter job_queue_processes

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes                  integer     1000

SYS@prod>show parameter _dump_

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------

background_dump_dest                 string      /u01/app/oracle/diag/rdbms/pro
                                                 d/prod/trace

core_dump_dest                       string      /u01/app/oracle/diag/rdbms/pro
                                                 d/prod/cdump

max_dump_file_size                   string      unlimited

user_dump_dest                       string      /u01/app/oracle/diag/rdbms/pro
                                                 d/prod/trace

 

7.创建数据库

 

1)在官方文档中找到建库语句,位置:Administrator's Guide 11g Release 2 (11.2) => 2 Creating and Configuring an Oracle Database => Creating a Database with the CREATE DATABASE Statement => “CREATE DATABASE mynewdb”

 

2)修改示例的建库语句,需要注意UNDO TABLESPACE的名字和默认的不相同。

[oracle@ocm ~]$ vi dbcreate.sql

CREATE DATABASEprod
   USER SYS IDENTIFIED BYoracle
   USER SYSTEM IDENTIFIED BYoracle
   LOGFILE GROUP 1 ('/u01/app/oracle/oradata/prod/redo01a.log','/u01/app/oracle/oradata/prod/redo01b.log') SIZE 100M BLOCKSIZE 512,
           GROUP 2 ('/u01/app/oracle/oradata/prod/redo02a.log','/u01/app/oracle/oradata/prod/redo02b.log') SIZE 100M BLOCKSIZE 512,
           GROUP 3 ('/u01/app/oracle/oradata/prod/redo03a.log','/u01/app/oracle/oradata/prod/redo03b.log') SIZE 100M BLOCKSIZE 512
   MAXLOGFILES30
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 1
   MAXDATAFILES 100
   CHARACTER SET US7ASCII
   NATIONAL CHARACTER SET AL16UTF16
   EXTENT MANAGEMENT LOCAL
   DATAFILE'/u01/app/oracle/oradata/prod/system01.dbf'SIZE 325M REUSE
   SYSAUX DATAFILE'/u01/app/oracle/oradata/prod/sysaux01.dbf'SIZE 325M REUSE
   DEFAULT TABLESPACE users
      DATAFILE'/u01/app/oracle/oradata/prod/users01.dbf'
      SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE tempts1
      TEMPFILE'/u01/app/oracle/oradata/prod/temp01.dbf'
      SIZE 20M REUSE
   UNDO TABLESPACEundotbs1
      DATAFILE'/u01/app/oracle/oradata/prod/undotbs01.dbf'
      SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

 

3)执行建库脚本,需要在nomount下执行

SYS@prod>@/home/oracle/dbcreate.sql

Database created.

 

4)修改数据文件自动扩展

SYS@prod>alter database datafile 1 autoextend on;

Database altered.


SYS@prod> alter database datafile 2 autoextend on;

Database altered.


SYS@prod> alter database datafile 3 autoextend on;

Database altered.


SYS@prod> alter database datafile 4 autoextend on;

Database altered.


SYS@prod> alter database tempfile 1 autoextend on;

Database altered.

 

5)查询数据库状态并确认创建成功。

SYS@prod>conn / as sysdba

Connected.

SYS@prod>select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
prod             OPEN


SYS@db11g>col tablespace_name for a10
SYS@db11g>col tablespace_file for a60
SYS@prod>select a.name tablespace_name,b.name tablespace_file from v$tablespace a,v$datafile b where a.ts#=b.ts#;

TABLESPACE TABLESPACE_FILE

---------- ------------------------------------------------------------
SYSTEM     /u01/app/oracle/oradata/prod/system01.dbf
SYSAUX     /u01/app/oracle/oradata/prod/sysaux01.dbf
UNDOTBS1   /u01/app/oracle/oradata/prod/undotbs01.dbf
USERS      /u01/app/oracle/oradata/prod/users01.dbf

 

6)执行建立数据字典脚本

SYS@db11g>conn / as sysdba

Connected

SYS@prod> @?/rdbms/admin/catalog.sql

……

SYS@prod> @?/rdbms/admin/catproc.sql

……

 

到这里,手工建立11gR2数据库就基本完成了,可以再跑一些额外的脚本如catoctk.sql来完善数据库的功能,总体来说手工建立11gR2数据库的过程和建立10gR2数据库基本思路相同,主要是参数文件和建库语句有一定区别,可以说11gR2数据库的手工建立过程比10gR2要少一些修改动作,这或许是因为随着数据库版本的升级,其设计越来越完善的缘故吧。