手动创建数据库是DBA们经常遇到的情形,因为有些情况下无法提供GUI环境。实际上手动建库,只要设置好了相关的参数或值,也是非常方便的。本文基于Oracle 11g首先描述了手动建库的大致步骤并给出示例演示。最后提供了一个shell脚本直接执行来实现手动建库。在执行前该脚本可根据你的路径进行适当的修改。
一、手动建库大致步骤
设置环境变量.bash_profile
创建参数文件(位置:$ORACLE_HOME/dbs)
创建目录结构
执行建库脚本
二、手动创建数据库
-
1、设置环境变量.bash_profile
-
--确保至少包含下列环境变量,对于已经安装好Oracle Database software的情形下,实际上可以跳过此步骤
-
$ vi .bash_profile
-
export ORACLE_SID=catadb
-
export ORACLE_BASE=/u01/app/oracle
-
export ORACLE_HOME=$ORACLE_BASE/db_1
-
export PATH=/usr/sbin:$PATH
-
export PATH=$ORACLE_HOME/bin:$PATH
-
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
-
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
-
2、创建参数文件(位置:$ORACLE_HOME/dbs)
-
[oracle@linux1 dbs]$ export ORACLE_SID=catadb
-
[oracle@linux1 ~]$ cd $ORACLE_HOME/dbs
-
[oracle@linux1 dbs]$ grep -v \# init.ora >init$ORACLE_SID.ora
-
[oracle@linux1 dbs]$ more initcatadb.ora
-
db_name='catadb'
-
memory_target=512M
-
processes = 150
-
audit_file_dest='/u03/uat/catadb/adump'
-
audit_trail ='db'
-
db_block_size=8192
-
db_domain=''
-
db_recovery_file_dest='/u03/uat/catadb/fr_area'
-
db_recovery_file_dest_size=2G
-
diagnostic_dest='/u03/uat/catadb'
-
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
-
open_cursors=300
-
remote_login_passwordfile='EXCLUSIVE'
-
undo_tablespace='UNDOTBS1'
-
control_files = ('/u03/uat/catadb/oradata/catadb01.ctl','/u03/uat/catadb/oradata/catadb02.ctl')
-
compatible ='11.2.0'
-
3、创建目录结构
-
[oracle@linux1 ~]$ mkdir -p /u03/uat/catadb
-
[oracle@linux1 dbs]$ cd /u03/uat/catadb
-
[oracle@linux1 catadb]$ mkdir adump diag fr_area oradata
-
4、执行建库脚本
-
[oracle@linux1 catadb]$ more create_catadb.sql
-
createdatabase catadb
-
maxlogfiles 5
-
maxlogmembers 5
-
maxdatafiles 100
-
maxinstances 1
-
logfile
-
group 1 ('/u03/uat/catadb/oradata/redo1.log') size 10m,
-
group 2 ('/u03/uat/catadb/oradata/redo2.log') size 10m,
-
group 3 ('/u03/uat/catadb/oradata/redo3.log') size 10m
-
datafile
-
'/u03/uat/catadb/oradata/system.dbf'size 200m reuse
-
sysaux datafile '/u03/uat/catadb/oradata/sysaux.dbf'size 100m
-
default tablespace user
-
datafile '/u03/uat/catadb/oradata/userdata.dbf'size 100m
-
undo tablespace undotbs1
-
datafile '/u03/uat/catadb/oradata/undo1.dbf'size 100m
-
defaulttemporary tablespace temp1
-
tempfile '/u03/uat/catadb/oradata/temp01.dbf'
-
size 100m reuse
-
characterset al32utf8
-
;
-
idle> @/u03/uat/catadb/create_catadb.sql
-
Database created.
-
--添加数据字典
-
idle> edit /u03/uat/catadb/post_create_catadb.sql
-
@$ORACLE_HOME/rdbms/admin/catalog.sql
-
@$ORACLE_HOME/rdbms/admin/catproc.sql
-
conn system/manager
-
@$ORACLE_HOME/sqlplus/admin/pupbld.sql
-
idle> @/u03/uat/catadb/post_create_catadb.sql
-
system@CATADB> selectname,open_mode from v$database;
-
NAME OPEN_MODE
-
--------- --------------------
-
CATADB READ WRITE
1、设置环境变量.bash_profile
--确保至少包含下列环境变量,对于已经安装好Oracle Database software的情形下,实际上可以跳过此步骤
$ vi .bash_profile
export ORACLE_SID=catadb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/db_1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
2、创建参数文件(位置:$ORACLE_HOME/dbs)
[oracle@linux1 dbs]$ export ORACLE_SID=catadb
[oracle@linux1 ~]$ cd $ORACLE_HOME/dbs
[oracle@linux1 dbs]$ grep -v \# init.ora >init$ORACLE_SID.ora
[oracle@linux1 dbs]$ more initcatadb.ora
db_name='catadb'
memory_target=512M
processes = 150
audit_file_dest='/u03/uat/catadb/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u03/uat/catadb/fr_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u03/uat/catadb'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
control_files = ('/u03/uat/catadb/oradata/catadb01.ctl','/u03/uat/catadb/oradata/catadb02.ctl')
compatible ='11.2.0'
3、创建目录结构
[oracle@linux1 ~]$ mkdir -p /u03/uat/catadb
[oracle@linux1 dbs]$ cd /u03/uat/catadb
[oracle@linux1 catadb]$ mkdir adump diag fr_area oradata
4、执行建库脚本
[oracle@linux1 catadb]$ more create_catadb.sql
create database catadb
maxlogfiles 5
maxlogmembers 5
maxdatafiles 100
maxinstances 1
logfile
group 1 ('/u03/uat/catadb/oradata/redo1.log') size 10m,
group 2 ('/u03/uat/catadb/oradata/redo2.log') size 10m,
group 3 ('/u03/uat/catadb/oradata/redo3.log') size 10m
datafile
'/u03/uat/catadb/oradata/system.dbf' size 200m reuse
sysaux datafile '/u03/uat/catadb/oradata/sysaux.dbf' size 100m
default tablespace user
datafile '/u03/uat/catadb/oradata/userdata.dbf' size 100m
undo tablespace undotbs1
datafile '/u03/uat/catadb/oradata/undo1.dbf' size 100m
default temporary tablespace temp1
tempfile '/u03/uat/catadb/oradata/temp01.dbf'
size 100m reuse
character set al32utf8
;
idle> @/u03/uat/catadb/create_catadb.sql
Database created.
--添加数据字典
idle> edit /u03/uat/catadb/post_create_catadb.sql
@$ORACLE_HOME/rdbms/admin/catalog.sql
@$ORACLE_HOME/rdbms/admin/catproc.sql
conn system/manager
@$ORACLE_HOME/sqlplus/admin/pupbld.sql
idle> @/u03/uat/catadb/post_create_catadb.sql
system@CATADB> select name,open_mode from v$database;
NAME OPEN_MODE
--------- --------------------
CATADB READ WRITE
三、手动建库脚本
--下面将上述动作进行了一个整理,全部封装到shell脚本来执行,输入密码,坐着喝咖啡吧!
本文转自东方之子736651CTO博客,原文链接:http://blog.51cto.com/ecloud/1339574 ,如需转载请自行联系原作者