Oracle11gR2手工建库(附DBCA静默建库)

时间:2022-06-09 08:39:36
参考官方文档:E25494-03
环境:CentOS6.5  Oracle11.2.0.4

1. 指定Oracle SID

[oracle@centos6 ~]$ echo $ORACLE_SID
orcl

2. 设置环境变量

[oracle@centos6 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1
[oracle@centos6 ~]$ echo $ORACLE_BASE
/u01/app/oracle
由于这些参数已经在安装oracle软件的时候写入了环境变量,这里就不再修改

3. 选择认证方式,创建密码文件

[oracle@centos6 ~]$ cd $ORACLE_HOME/dbs
[oracle@centos6 dbs]$ orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl entries=30

Enter password for SYS:

4. 创建参数文件

[oracle@centos6 dbs]$ cp init.ora initorcl.ora
[oracle@centos6 dbs]$ ls
init.ora initorcl.ora orapworcl
[oracle@centos6 dbs]$ vim initorcl.ora
# Change '<ORACLE_BASE>' to point to the oracle base (the one you specify at
# install time)

db_name='ORCL'
memory_target=900m
processes = 150
audit_file_dest='/u01/app/orcle/admin/orcl/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/app/oracle'
dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = ('/u01/app/oracle/oradata/orcl/control01.ctl', '/u01/app/oracle/oradata/orcl/control02.ctl')
compatible ='11.2.0'
"initorcl.ora" 66L, 2856C written   
注:需要根据参数文件中的参数创建相应的目录,创建后重新赋一次权限

[root@centos6 ~]# mkdir -p /u01/app/orcle/admin/orcl/adump
[root@centos6 ~]# mkdir -p /u01/app/oracle/flash_recovery_area
[root@centos6 oradata]$ mkdir -p /u01/app/oracle/oradata/orcl
[root@centos6 ~]# chown -R oracle:oinstall /u01/app
[root@centos6 ~]# chmod -R 775 /u01/app

5. 连接到数据库,启动到nomount状态

[oracle@centos6 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sat Nov 19 02:09:58 2016

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 939495424 bytes
Fixed Size 2258840 bytes
Variable Size 595593320 bytes
Database Buffers 335544320 bytes
Redo Buffers

6. 执行建库脚本

SQL> CREATE DATABASE orcl
2 USER SYS IDENTIFIED BY oracle
3 USER SYSTEM IDENTIFIED BY oracle
4 LOGFILE GROUP 1 ('/u01/app/oracle/oradata/orcl/redo01a.log','/u01/app/oracle/oradata/orcl/redo01b.log') SIZE 100M BLOCKSIZE 512,
5 GROUP 2 ('/u01/app/oracle/oradata/orcl/redo02a.log','/u01/app/oracle/oradata/orcl/redo02b.log') SIZE 100M BLOCKSIZE 512,
6 GROUP 3 ('/u01/app/oracle/oradata/orcl/redo03a.log','/u01/app/oracle/oradata/orcl/redo03b.log') SIZE 100M BLOCKSIZE 512
7 MAXLOGFILES 5
8 MAXLOGMEMBERS 5
9 MAXLOGHISTORY 1
10 MAXDATAFILES 100
11 CHARACTER SET ZHS16GBK
12 NATIONAL CHARACTER SET AL16UTF16
13 EXTENT MANAGEMENT LOCAL
14 DATAFILE '/u01/app/oracle/oradata/orcl/system01.dbf' SIZE 325M REUSE
15 SYSAUX DATAFILE '/u01/app/oracle/oradata/orcl/sysaux01.dbf' SIZE 325M REUSE
16 DEFAULT TABLESPACE users
17 DATAFILE '/u01/app/oracle/oradata/orcl/users01.dbf'
18 SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
19 DEFAULT TEMPORARY TABLESPACE temp
20 TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf'
21 SIZE 20M REUSE
22 UNDO TABLESPACE UNDOTBS1
23 DATAFILE '/u01/app/oracle/oradata/orcl/undotbs01.dbf'
24 SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

Database created.

7. 执行创建数据字典脚本

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
@?/sqlplus/admin/pupbld.sql #需使用system用户执行

附带一个DBCA静默建库的方法,可以快速建库:

[oracle@centos6_dg database]$ dbca -silent -createDatabase -templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc -gdbname dg -sid dg -characterSet ZHS16GBK
Enter SYS user password:

Enter SYSTEM user password:

Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/dg/dg.log" for further details.
也可以手工编辑response目录下的dbca.rsp来定制数据库