日期:2014-05-16  浏览次数:20528 次

手工创建数据库,包括oracle rac


最简单的方法就是使用dbca来生产建库的脚本,然后手工执行这些脚本。具体过程如下

1,手工创建相关目录和环境变量

#!/bin/sh

OLD_UMASK=`umask`
umask 0027
mkdir -p /oracle/app/oracle/admin/hrdb/adump
mkdir -p /oracle/app/oracle/admin/hrdb/dpdump
mkdir -p /oracle/app/oracle/admin/hrdb/hdump
mkdir -p /oracle/app/oracle/admin/hrdb/pfile
mkdir -p /oracle/app/oracle/cfgtoollogs/dbca/hrdb
umask ${OLD_UMASK}
ORACLE_SID=hrdb1; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
是否使用数据库自动启动,这里设置为false
echo You should Add this entry in the /etc/oratab: hrdb:/oracle/app/oracle/product/11.2.0/db_1:N

2,创建参数文件、密码文件

密码文件
/oracle/app/oracle/product/11.2.0/db_1/bin/orapwd file=/oracle/app/oracle/product/11.2.0/db_1/dbs/orapwhrdb1 force=y
参数文件$ORACLE_HOME/dbs/inithrdb1.ora
*.audit_file_dest='/oracle/app/oracle/admin/hrdb/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.0.0'
*.cpu_count=8
*.create_stored_outlines=''
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='hrdb'
*.db_recovery_file_dest='+FRA'
*.db_recovery_file_dest_size=107374182400
*.diagnostic_dest='/oracle/app/oracle'
hrdb1.instance_number=1
*.log_archive_format='%t_%s_%r.dbf'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=1000
*.pga_aggregate_target=1610612736
*.processes=500
*.remote_listener='dtydb-scan2:1521'
*.sga_target=4399824896  

启动到nomount状态
sqlplus "/as sysdba"

startup nomount pfile="/oracle/app/oracle/product/11.2.0/db_1/dbs/inithrdb1.ora";

3,开始建库

CREATE DATABASE "hrdb"
MAXINSTANCES 32
MAXLOGHISTORY 1
MAXLOGFILES 192
MAXLOGMEMBERS 3
MAXDATAFILES 1024
DATAFILE SIZE 700M AUTOEXTEND ON NEXT  10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE SIZE 600M AUTOEXTEND ON NEXT  10240K MAXSIZE UNLIMITED
SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE SIZE 20M AUTOEXTEND ON NEXT  640K MAXSIZE UNLIMITED
SMALLFILE UNDO TABLESPACE "UNDOTBS1" DATAFILE SIZE 1024M AUTOEXTEND ON NEXT  5120K MAXSIZE UNLIMITED
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1  SIZE 512M,
GROUP 2  SIZE 512M,
GROUP 7  SIZE 512M
USER SYS IDENTIFIED BY oracle USER SYSTEM IDENTIFIED BY oracle;

4,参数文件中添加控制文件选项

hrdb1>column ctl_files NEW_VALUE ctl_files;
hrdb1>select concat('control_files=''', concat(replace(value, ', ', ''','''), '''')) ctl_files from v$parameter where name ='control_files';

CTL_FILES
--------------------------------------------------------------------------------------------
control_files='+DATA/hrdb/controlfile/current.388.791301537','+FRA/hrdb/controlfile/current.361.791301537'


host echo &ctl_files >> /oracle/app/oracle/product/11.2.0/db_1/dbs/inithrdb1.ora;

5,创建数据字典

connect / as sysdba;
spool /tmp/CreateDBCatalog.log append

@/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catalog.sql;
@/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catblock.sql;
@/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catproc.sql;
@/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catoctk.sql;
@/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/owminst.plb;
spool off

connect "SYSTEM"/"oracle"
spool /tmp/system.log append
@/oracle/app/oracle/product/11.2.0/db_1/sqlplus/admin/pupbld.sql;
@/oracle/app/oracle/product/11.2.0/db_1/sqlplus/admin/help/hlpbld.sql helpus.sql;
spool off

6,创建spfile,存放于asm磁盘

create spfile from pfile='/oracle/app/oracle/product/11.2.0/db_1/dbs/inithrdb1.ora';

cp /oracle/app/oracle/product/11.2.0/db_1/dbs/inithrdb1.ora /oracle/app/oracle/product/1