http://www.cnblogs.com/beanbee/archive/2012/09/22/2697689.html
使用命令行手工建立Oracle11gR2数据库
通过命令行建立一个数据库可以帮助更好的了解数据库的建库流程,今天试了试手工建立Oracle11gR2数据库,感觉和10g的手工建库流程还是有一定的区别的,10g数据库的手工方式建立可以参考大侯(secooler)的“http://space.itpub.net/519536/viewspace-667563 ”
下面是我的建库流程:
一、测试环境
OS:SUSE 11 SP1
DB:Oracle database 11g R2(11.2.0.4.0)
实例名:zfox
二、实施步骤
1、配置环境变量(参考)
$ vi .bash_profile
.bash_profile
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/11gR2/db
export GRID_HOME=/opt/oracrs/product/11gR2/grid
#export ORACLE_SID=NDSCDB
export ORACLE_SID=zfox
export ORACLE_TERM=xterm
#LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/lib32:/lib:/usr/lib:$ORACLE_HOME/rdbms/lib
export LD_LIBRARY_PATH
SHLIB_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
export SHLIB_PATH
# Set shell search paths:
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH:/usr/local/bin
# CLASSPATH must include the following JRE locations:
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
$ source ~/.bash_profile
2、创建dump目录
和10g相比,11gR2只需建立adump一个目录就可以了
$ mkdir -p $ORACLE_BASE/admin/zfox/adump
3、数据文件及控制文件的存放目录
ASM存储或裸设备则不需创建
注:oracle存储使用本地存储创建如下
$ mkdir -p /u01/app/oracle/oradata/prod
4、建立密码文件
$ cd $ORACLE_HOME/dbs
$ orapwd file=orapwzfox password=oracle entries=30
5、创建参数文件
类似如下:
$ cat initzfox.ora
zfox.__db_cache_size=45365592064
zfox.__java_pool_size=536870912
zfox.__large_pool_size=134217728
zfox.__oracle_base='/opt/oracle'#ORACLE_BASE set from environment
zfox.__pga_aggregate_target=16911433728
zfox.__sga_target=50465865728
zfox.__shared_io_pool_size=0
zfox.__shared_pool_size=4160749568
zfox.__streams_pool_size=0
*.audit_file_dest='/opt/oracle/admin/zfox/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_file_record_keep_time=20
*.control_files='+DG_DATA/zfox/controlfile/control01'
*.cursor_sharing='FORCE'
*.db_block_size=8192
*.db_create_file_dest='+DG_DATA'
*.db_domain=''
*.db_file_multiblock_read_count=64
*.db_name='zfox'
*.db_writer_processes=8
*.diagnostic_dest='/opt/oracle'
*.dispatchers=''
*.dml_locks=6756
*.filesystemio_options='ASYNCH'
*.job_queue_processes=20
*.open_cursors=1000
*.pga_aggregate_target=16814964736
*.processes=1000
*.recyclebin='OFF'
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.sessions=1536
*.sga_target=50446991360
*.shared_servers=0
*.transactions=1689
*.undo_retention=5400
*.undo_tablespace='UNDOTBS1'
6、使用之前创建的参数文件启动数据库到nomount状态下
$ export ORACLE_SID=zfox
$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup nomount;
7、在10gR2本需手工修改的undo_management,job_queue_processes等参数,在11gR2已符合要求,无需再修改
SQL> show parameter undo_management --AUTO
SQL> show parameter job_queue_processes --1000
SQL> show parameter _dump_ --/opt/oracle/diag/rdbms/zfox/zfox/trace
8、创建数据库
$ vi dbcreate_zofx.sql
CREATE DATABASE zfox
USER SYS IDENTIFIED BY oracle
USER SYSTEM IDENTIFIED BY oracle
LOGFILE GROUP 1 ('+DG_DATA') SIZE 100M BLOCKSIZE 512,
GROUP 2 ('+DG_DATA') SIZE 100M BLOCKSIZE 512,
GROUP 3 ('+DG_DATA') SIZE 100M BLOCKSIZE 512
MAXLOGFILES 30
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '+DG_DATA' SIZE 325M REUSE
SYSAUX DATAFILE '+DG_DATA' SIZE 325M REUSE
DEFAULT TABLESPACE users
DATAFILE '+DG_DATA'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE temp
TEMPFILE'+DG_DATA'
SIZE 20M REUSE
UNDO TABLESPACE undotbs1
DATAFILE '+DG_DATA'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
---执行建库脚本,需要在nomount下执行
SQL> @/home/oracle/dbcreate_zofx.sql
---查询数据库状态并确认创建成功。
SQL> select instance_name,status from v$instance;
col tablespace_name for a10
col tablespace_file for a60
select a.name tablespace_name,b.name tablespace_file from v$tablespace a,v$datafile b where a.ts#=b.ts#;
9、执行建立数据字典脚本
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
@?/sqlplus/admin/pupbld.sql #需使用system用户执行
10、重置spfile文件到ASM存储中。
$ cd $ORACLE_HOME/dbs
$ cat initzfox.ora
SPFILE='+DG_DATA/ZFOX/spfileZFOX.ora'
$ mv spfilezfox.ora spfilezfox.ora.bak
SQL> create SPFILE='+DG_DATA/ZFOX/spfileZFOX.ora' from pfile='/home/oracle/initzfox.ora'
附带一个DBCA静默建库的方法,可以快速建库:
$ dbca -silent -createDatabase -templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc -gdbname dg -sid dg -characterSet ZHS16GBK
也可以手工编辑response目录下的dbca.rsp来定制数据库