手工创建Oracle数据库

一、初始化
1、创建初始化文件
[Oracle@sigleNode dbs]$ more initdw.ora|grep -v '#'|grep -v '^$'>initprod.ora
编辑初始化文件,进行参数设置,在原来参数设置基础之上增加以下设置
db_name=prod
db_cache_size = 100M
shared_pool_size = 60M
parallel_threads_per_cpu = 4
background_dump_dest = $ORACLE_BASE/admin/prod/bdump
user_dump_dest = $ORACLE_BASE/admin/prod/udump
core_dump_dest = $ORACLE_BASE/admin/prod/cdump
control_files = $ORACLE_BASE/oradata/prod/control01.ctl
undo_management = auto
undo_tablespace = rtbs
2、创建转储目录和文件路径
[oracle@sigleNode dbs]$ mkdir -p $ORACLE_BASE/admin/prod/bdump
[oracle@sigleNode dbs]$ mkdir -p $ORACLE_BASE/admin/prod/udump
[oracle@sigleNode dbs]$ mkdir -p $ORACLE_BASE/admin/prod/cdump
[oracle@sigleNode oradata]$ mkdir -p $ORACLE_BASE/oradata/prod
3、创建口令文件
[oracle@sigleNode dbs]$ orapwd file=orapwprod entries=5 force=y password=prod
可以看到在dbs下面增加实例orapwprod口令文件
[oracle@sigleNode dbs]$ ls -lt|grep orapwprod
-rw-r----- 1 oracle oinstall    2048 Feb 14 23:49 orapwprod
二、手工建库
1、创建建库语句
[oracle@sigleNode dbs]$ vi cr_db.sql

create database prod
  user sys identified by prod
  user system identified by prod
datafile '$ORACLE_BASE/oradata/prod/system01.dbf' size 400m
sysaux datafile '$ORACLE_BASE/oradata/prod/sysaux01.dbf' size 100m
default temporary tablespace temp tempfile '$ORACLE_BASE/oradata/prod/temp01.dbf' size 100m
undo tablespace rtbs datafile '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m
logfile
    group 1 '$ORACLE_BASE/oradata/prod/redo01.log' size 50m,
    group 2 '$ORACLE_BASE/oradata/prod/redo02.log' size 50m
character set zhs16gbk;

注意建库语句创建system和sysaux表空间特殊语法,不要带tablespace关键字,否则会创建失败
undo tablespace表空间的名字必须与undo_tablesapce参数设置保持一致,否则在告警日志中会报类似下面的错误
ORA-30012 signalled during: CREATE UNDO TABLESPACE UNDO01 DATAFILE  '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m
...
Sun Feb 15 00:27:01 2015
Errors in file /u01/app/oracle/admin/prod/udump/prod_ora_18355.trc:
ORA-00604: error occurred at recursive SQL level 1
ORA-30012: undo tablespace 'rtbs' does not exist or of wrong type
Sun Feb 15 00:27:01 2015
Errors in file /u01/app/oracle/admin/prod/udump/prod_ora_18355.trc:
ORA-01501: CREATE DATABASE failed
ORA-01519: error while processing file '?/rdbms/admin/sql.bsq' near line 5792
ORA-00604: error occurred at recursive SQL level 1
ORA-30012: undo tablespace 'rtbs' does not exist or of wrong type
Error 1519 happened during db open, shutting down database
找不到rtbs这个undo表空间导致创建失败
2、创建数据库
  首先启动实例到nomount状态
[oracle@sigleNode dbs]$ export ORACLE_SID=prod
[oracle@sigleNode dbs]$ sqlplus / as sysdba
SQL> startup nomount;
ORA-32004: obsolete and/or deprecated parameter(s) specified
ORACLE instance started.

Total System Global Area  205520896 bytes
Fixed Size                  1218508 bytes
Variable Size              92276788 bytes
Database Buffers          104857600 bytes
Redo Buffers                7168000 bytes
实例成功启动到nomount状态,但是报了废弃参数问题
通过告警日志发现具体如下
Deprecated system parameters with specified values:
  parallel_automatic_tuning
End of deprecated system parameter listing
指明参数parallel_automatic_tuning已经废弃,编辑初始化文件
[oracle@sigleNode dbs]$ vi initprod.ora
注释掉下面一行
#parallel_automatic_tuning = true
重启启动实例到nomount状态
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  201326592 bytes
Fixed Size                  1218484 bytes
Variable Size              88082508 bytes
Database Buffers          104857600 bytes
Redo Buffers                7168000 bytes
执行建库脚本cr_db.sql
SQL> @$ORACLE_HOME/dbs/cr_db.sql;

Database created.
通过告警日志看到建库的详细过程如下:
create database prod
  user sys identified by ****user system identified by *datafile '$ORACLE_BASE/oradata/prod/system01.dbf' size 400m
sysaux datafile '$ORACLE_BASE/oradata/prod/sysaux01.dbf' size 100m
default temporary tablespace temp tempfile '$ORACLE_BASE/oradata/prod/temp01.dbf' size 100m
undo tablespace rtbs datafile '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m
logfile
    group 1 '$ORACLE_BASE/oradata/prod/redo01.log' size 50m,
    group 2 '$ORACLE_BASE/oradata/prod/redo02.log' size 50m
character set zhs16gbk
Sun Feb 15 00:28:30 2015
Database mounted in Exclusive Mode
Sun Feb 15 00:28:33 2015
Successful mount of redo thread 1, with mount id 283499181
Assigning activation ID 283499181 (0x10e5daad)
Thread 1 opened at log sequence 1
  Current log# 1 seq# 1 mem# 0: /u01/app/oracle/oradata/prod/redo01.log
Successful open of redo thread 1
Sun Feb 15 00:28:33 2015
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Sun Feb 15 00:28:33 2015
SMON: enabling cache recovery
Sun Feb 15 00:28:33 2015
create tablespace SYSTEM datafile  '$ORACLE_BASE/oradata/prod/system01.dbf' size 400m

  default storage (initial 10K next 10K) EXTENT MANAGEMENT DICTIONARY online
Sun Feb 15 00:28:41 2015
Completed: create tablespace SYSTEM datafile  '$ORACLE_BASE/oradata/prod/system01.dbf' size 400m
  default storage (initial 10K next 10K) EXTENT MANAGEMENT DICTIONARY online
Sun Feb 15 00:28:41 2015
create rollback segment SYSTEM tablespace SYSTEM
  storage (initial 50K next 50K)
Completed: create rollback segment SYSTEM tablespace SYSTEM
  storage (initial 50K next 50K)
Sun Feb 15 00:28:50 2015
CREATE UNDO TABLESPACE RTBS DATAFILE  '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m

Sun Feb 15 00:28:52 2015
Successfully onlined Undo Tablespace 1.
Completed: CREATE UNDO TABLESPACE RTBS DATAFILE  '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m
Sun Feb 15 00:28:52 2015
create tablespace SYSAUX datafile  '$ORACLE_BASE/oradata/prod/sysaux01.dbf' size 100m

  EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO online
Completed: create tablespace SYSAUX datafile  '$ORACLE_BASE/oradata/prod/sysaux01.dbf' size 100m
  EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO online
Sun Feb 15 00:28:55 2015
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE  '$ORACLE_BASE/oradata/prod/temp01.dbf' size 100m

Completed: CREATE TEMPORARY TABLESPACE TEMP TEMPFILE  '$ORACLE_BASE/oradata/prod/temp01.dbf' size 100m
Sun Feb 15 00:28:56 2015
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP
Completed: ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP
Sun Feb 15 00:28:56 2015
ALTER DATABASE DEFAULT TABLESPACE SYSTEM
Completed: ALTER DATABASE DEFAULT TABLESPACE SYSTEM
Sun Feb 15 00:29:01 2015
SMON: enabling tx recovery
Sun Feb 15 00:29:03 2015
Threshold validation cannot be done before catproc is loaded.
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=13, OS id=18386
Sun Feb 15 00:29:04 2015
Completed: create database prod
  user sys identified by ****user system identified by *datafile '$ORACLE_BASE/oradata/prod/system01.dbf' size 400m
sysaux datafile '$ORACLE_BASE/oradata/prod/sysaux01.dbf' size 100m
default temporary tablespace temp tempfile '$ORACLE_BASE/oradata/prod/temp01.dbf' size 100m
undo tablespace rtbs datafile '$ORACLE_BASE/oradata/prod/undo01.dbf' size 100m
logfile
    group 1 '$ORACLE_BASE/oradata/prod/redo01.log' size 50m,
    group 2 '$ORACLE_BASE/oradata/prod/redo02.log' size 50m
character set zhs16gbk

3、建立数据字典
[oracle@sigleNode dbs]$ vi cr_dict.sql

@$ORACLE_HOME/rdbms/admin/catalog.sql
@$ORACLE_HOME/rdbms/admin/catproc.sql
conn system/prod
@$ORACLE_HOME/sqlplus/admin/pupbld.sql

  直接执行脚本
SQL>@ORACLE_HOME/dbs/cr_dict.sql;
即可

4、创建用户表空间
SQL> create tablespace users datafile '$ORACLE_BASE/oradata/prod/user01.dbf' size 500m;

Tablespace created.

SQL> alter database default tablespace users;

Database altered.

创建数据库prod完成

相关推荐