最简单的方法就是使用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";
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;
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;
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
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/11.2.0/db_1/dbs/inithrdb1.ora.bak echo "SPFILE='+DATA/hrdb/spfilehrdb.ora'" > /oracle/app/oracle/product/11.2.0/db_1/dbs/inithrdb1.ora
spool /tmp/postDBCreation.log append @/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catbundle.sql psu apply; select 'utl_recomp_begin: ' || to_char(sysdate, 'HH:MI:SS') from dual; execute utl_recomp.recomp_serial(); select 'utl_recomp_end: ' || to_char(sysdate, 'HH:MI:SS') from dual;
shutdown immediate; connect "SYS"/"&&sysPassword" as SYSDBA startup mount pfile="/oracle/app/oracle/admin/hrdb/scripts/init.ora"; startup mount; alter database archivelog; alter database open;
9、添加log file和undo
--添加log thread 3
ALTER DATABASE ADD LOGFILE THREAD 3
GROUP 5 SIZE 512M,
GROUP 6 SIZE 512M,
GROUP 9 SIZE 512M;
ALTER DATABASE ENABLE PUBLIC THREAD 3;
--添加log thread 3
ALTER DATABASE ADD LOGFILE THREAD 2
GROUP 3 SIZE 512M,
GROUP 4 SIZE 512M,
GROUP 8 SIZE 512M;
ALTER DATABASE ENABLE PUBLIC THREAD 2;
undo tablespace
CREATE SMALLFILE UNDO TABLESPACE "UNDOTBS2" DATAFILE SIZE 1024M AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;
CREATE SMALLFILE UNDO TABLESPACE "UNDOTBS3" DATAFILE SIZE 1024M AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;
10,CreateClustDBViews
spool /oracle/app/oracle/admin/epmdb/scripts/CreateClustDBViews.log append @/oracle/app/oracle/product/11.2.0/db_1/rdbms/admin/catclust.sql; spool off
alter system set cluster_database=true scope=spfile; alter system set remote_listener="dtydb-scan2:1521" scope=spfile; alter system set instance_number=2 scope=spfile sid='hrdb2'; alter system set instance_number=3 scope=spfile sid='hrdb3'; alter system set thread=2 scope=spfile sid='hrdb2'; alter system set thread=3 scope=spfile sid='hrdb3'; alter system set undo_tablespace=UNDOTBS2 scope=spfile sid='hrdb2'; alter system set undo_tablespace=UNDOTBS3 scope=spfile sid='hrdb3'; create pfile = '/tmp/init.ora' from spfile; create spfile='+DATA/hrdb/spfilehrdb.ora' FROM pfile ='/tmp/init.ora'; 也可通过修改pfile文件完成 epmdb3.instance_number=3 epmdb2.instance_number=2 epmdb1.instance_number=1 epmdb3.thread=3 epmdb2.thread=2 epmdb1.thread=1 epmdb3.undo_tablespace=UNDOTBS3 epmdb1.undo_tablespace=UNDOTBS1 epmdb2.undo_tablespace=UNDOTBS212,删除默认的spfile,让数据库从pfile启动,实际从asm上的spfile上启动
shutdown immediate; mv spfilehrdb1.ora spfilehrdb1.ora.bak db2上 vi inithrdb2.ora SPFILE='+DATA/hrdb/spfilehrdb.ora' db3上 vi inithrdb3.ora SPFILE='+DATA/hrdb/spfilehrdb.ora'
/oracle/11.2.0/grid/bin/setasmgidwrap o=/oracle/app/oracle/product/11.2.0/db_1/bin/oracle /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl add database -d hrdb -o /oracle/app/oracle/product/11.2.0/db_1 -p +DATA/hrdb/spfilehrdb.ora -n hrdb -a DATA,FRA /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl add instance -d hrdb -i hrdb1 -n dtydb3 /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl add instance -d hrdb -i hrdb2 -n dtydb4 /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl add instance -d hrdb -i hrdb3 -n dtydb5 /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl enable database -d hrdb; /oracle/app/oracle/product/11.2.0/db_1/bin/srvctl start database -d hrdb;