当前位置:文档之家 > Oracle 11g R2 手动建库(create database manually)

Oracle 11g R2 手动建库(create database manually)

Oracle 11g R2 手动建库(create database manually)
手动创建数据库是DBA们经常遇到的情形,因为有些情况下无法提供GUI环境。实际上手动建库,只要设置好了相关的参数或值,也是非常方便的。本文基于Oracle 11g首先描述了手动建库的大致步骤并给出示例演示。最后提供了一个shell脚本直接执行来实现手动建库。在执行前该脚本可根据你的路径进行适当的修改。



一、手动建库大致步骤
设置环境变量.bash_profile
创建参数文件(位置:$ORACLE_HOME/dbs)
创建目录结构
执行建库脚本



二、手动创建数据库

[sql] view plaincopyprint?
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/o

radata/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

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/rdb

ms/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脚本来执行,输入密码,坐着喝咖啡吧!





在nomount 状态下创建数据库。所以需要创建实例启动用的参数文件。在程序默认的参数文件里修改即可:重命名规则 initSID.ora
initora11g.ora
db_name='ora11g' --修改
#memory_target=500m --注释掉
sga_target=200m --添加
pga_aggregate_target=60m --添加
processes = 150
audit_file_dest='/u01/app/admin/ora11g/adump' --建立目录
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/flash_recovery_area' --建立目录
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app' ---修改
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'

创建相应的目录
mkdir -p /u01/app/admin/ora11g/adump
mkdir -p /u01/app/admin/ora11g/dpdump
mkdir -p /u01/app/flash_recovery_area

本篇文章来源于 Linux公社网站(http://www.doczj.com/doc/1458535e9b6648d7c1c746c7.html) 原文链接:http://www.doczj.com/doc/1458535e9b6648d7c1c746c7.html/Linux/2012-07/64651.htm


Oracle 11g 手工建库(2013-02-27 13:36:58)转载▼标签: oracle11g手动建库手工建库it 分类: Oracle操作用例
1、导出ORACLE_SID

export ORACLE_SID=n1



2、建立文件夹

mkdir /u01/app/oracle/product/admin/adump -p

mkdir /u01/app/oracle/product/admin/bdump -p

mkdir /u01/app/oracle/product/admin/cdump -p

mkdir /u01/app/oracle/product/admin/udump -p

mkdir /u01/app/oracle/product/admin/pfile -p

mkdir /u01/app/oracle/product/admin/create -p



mkdir /u01/app/oracle/oradata/n1



3、建立参数文件

在其中填写

db_name=n1

control_files=(/u01/app/oracle/oradata/control01.ctl)



4、建立服务

oradism -new -sid n1



5、建立口令文件

orapwd file=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/pwdn1.ora password=oracle



6、启动实例到NOMOUT

startup nomount pfile='xxxx';



7、建立库文件

CREATE DATABASE N1
DATAFILE '/u01/app/oracle/oradata/n1/system01.dbf' SIZE 300M AUTOEXTEND ON NEXT 10M EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/u01/app/oracle/oradata/n1/sysaux01.dbf' SIZE 150M
UNDO TABLESPACE UNDOTBS1 DATAFILE '/u01/app/oracle/oradata/n1/undotbs01.dbf' SIZE 100M
DEFAULT TEMPORARY TABLESPACE TEMPTABLS1 TEMPFILE '/u01/app/oracle/oradata/n1/temp01.dbf' SIZE 100M
LOGFILE
GROUP 1 ('/u01/app/oracle/oradata/n1/redo01.log') SIZE 100M,
GROUP 2 ('/u01/app/oracle/oradata/n1/redo02.log') SIZE 100M,
GROUP 3 ('/u01/

app/oracle/oradata/n1/redo03.log') SIZE 100M;



8、建立数据字典

start /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/catalog

start /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/admin/catproc



9、执行pupbld.sql脚本

conn system/manager

start /u01/app/oracle/product/11.2.0/dbhome_1/sqlplus/admin/pupbld



建立完毕。