分类: Oracle
2008-09-23 11:08:57
一、不使用OMF创建数据库
1.创建数据库实例,实例名为abc(只是Windows平台需要,Unix平台不需要)
C:\WINDOWS>oradim -new -sid abc
Instance created.
2.为了sys用户可以连入数据库执行操作,先创建数据库的密码文件,密码文件的名称必须为PWDsid.ora
C:\WINDOWS>orapwd password=oracle file=F:\oracle\product\10.2.0\database\PWDabc.ora
3.创建下列目录,以存放数据文件和dump信息
#数据文件目录
F:\oracle\product\oradata\abc
#background dump目录
F:\oracle\product\admin\abc\bdump
#core dump目录
F:\oracle\product\admin\abc\cdump
#user dump目录
F:\oracle\product\admin\abc\udump
4.在listener.ora中添加下列信息,把此数据库注册在监听器中(可选)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = abc)
(ORACLE_HOME = f:\oracle\product\10.2.0)
(service=abc)
)
)
5.为了可以访问数据库,在tnsnames.ora添加下列信息
abc =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521))
(CONNECT_DATA =
(SERVER = dedicated)
(SERVICE_NAME = abc)
)
)
6.建立pfile文件F:\oracle\product\10.2.0\database\initabc.ora,文件的内容如下:
background_dump_dest=''f:\oracle\product/admin/abc/bdump''
compatible=''10.2.0.1.0''
control_files=''F:\oracle\product\oradata\abc\control01.ctl'',''F:\oracle\product\oradata\abc\control02.ctl''
core_dump_dest=''f:\oracle\product/admin/abc/cdump''
db_block_size=8192
db_name=''abc''
db_recovery_file_dest=''f:\oracle\product/flash_recovery_area''
db_recovery_file_dest_size=2147483648
pga_aggregate_target=41943040
processes=150
remote_login_passwordfile=''EXCLUSIVE''
sga_max_size=167772160
sga_target=125829120
undo_management=''AUTO''
undo_tablespace=''UND01''
user_dump_dest=''f:\oracle\product/admin/abc/udump''
7.连入数据库,并创建spfile文件
C:\WINDOWS>set ORACLE_SID=abc
C:\WINDOWS>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Apr 20 21:17:42 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an SQL instance.
SQL>create spfile from pfile;
File created.
8.启动数据库到nomount
SQL>startup nomount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1247924 bytes
Variable Size 104858956 bytes
Database Buffers 54525952 bytes
Redo Buffers 7139328 bytes
SQL>
9.执行creata database脚本
SQL>@F:\oracle\product\admin\abc\create\createdb.sql
Database created.
#createdb.sql脚本的具体内容如下:
create database abc
maxlogfiles 5
maxlogmembers 5
maxloghistory 1
maxdatafiles 100
maxinstances 1
user sys identified by oracle
user system identified by oracle
logfile group 1 (''F:\oracle\product\oradata\abc\redo01.log'') size 10m reuse,
group 2 (''F:\oracle\product\oradata\abc\redo02.log'') size 10m reuse,
group 3 (''F:\oracle\product\oradata\abc\redo03.log'') size 10m reuse
datafile ''F:\oracle\product\oradata\abc\system01.dbf'' size 325m reuse
extent management local
sysaux datafile ''F:\oracle\product\oradata\abc\sysaux01.dbf'' size 325m reuse
default temporary tablespace temp
tempfile ''F:\oracle\product\oradata\abc\temp01.dbf'' size 20m reuse
undo tablespace undotbs1
datafile ''F:\oracle\product\oradata\abc\undo01.dbf'' size 200m reuse
character set utf8
national character set al16utf16;
10.执行catalog.sql,创建数据库的数据字典视图
SQL>spool f:\catalog.log
SQL>@F:\oracle\product\10.2.0\RDBMS\ADMIN\catalog.sql
SQL>spool off
11.执行catproc.sql,创建执行PL/SQL程序所需的所有包
SQL>spool f:\catproc.log
SQL>@F:\oracle\product\10.2.0\RDBMS\ADMIN\catproc.sql
SQL>spool off
到此数据库abc创建完毕,可以正常使用了
注:
1.pfile文件中undo_tablespace中的名字必需与create database中的相同,否则会出现ORA-01092:ORACLE instance terminated.Disconnection forced的错误。
2.数据字典视图不是都由catalog.sql创建,部分由catproc.sql创建,如:dba_data_files
二、使用OMF创建数据库
从Oracle9i起,Oracle提出了OMF的概念,主要是简化了日常的管理操作,下面的实验演示了使用OMF时创建数据库的过程:
1.先删除刚刚建立的abc数据库
1.1启动数据库到mount
SQL>startup mount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1247924 bytes
Variable Size 134219084 bytes
Database Buffers 25165824 bytes
Redo Buffers 7139328 bytes
Database mounted.
1.2将数据库设置为restricted session模式
SQL>alter system enable restricted session;
System altered.
1.3使用drop database命令删除数据库,这个操作将删除所有的数据文件(不包括参数和密码文件)
SQL>drop database;
Database dropped.
2.修改pfile文件F:\oracle\product\10.2.0\database\initabc.ora,添加下列内容:
db_create_file_dest=''F:\oracle\product\oradata\''
db_create_online_log_dest_1=''F:\oracle\product\oradata\''
3.连入数据库,并启动数据库到nomount
SQL>startup nomount
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1247924 bytes
Variable Size 104858956 bytes
Database Buffers 54525952 bytes
Redo Buffers 7139328 bytes
4.根据刚刚修改的pfile文件创建spfile文件
SQL>create spfile from pfile;
File created.
5.执行creata database脚本
SQL>@F:\oracle\product\admin\abc\create\createdb.sql
Database created.
#createdb.sql脚本的具体内容如下(可以看出内容很简洁,所有的数据文件的具体信息都不用指定):
create database abc
user sys identified by oracle
user system identified by oracle
default temporary tablespace temp
undo tablespace undotbs1
character set utf8
national character set al16utf16;
在这边也需要运行
创建数据字典和视图
$ORACLE_HOME\rdbms\admin\catalog.sql
$ORACLE_HOME\rdbms\admin\catproc.sql
6.查看数据库的各个文件的位置和名称
6.1在线日志文件
SQL>select group#,member from v$logfile;
GROUP# MEMBER
---------- ----------------------------------------------------------------------
1 F:\ORACLE\PRODUCT\ORADATA\ABC\ONLINELOG\O1_MF_1_40PN2T5C_.LOG
2 F:\ORACLE\PRODUCT\ORADATA\ABC\ONLINELOG\O1_MF_2_40PN312X_.LOG
6.2数据文件
SQL>select tablespace_name,file_name from dba_data_files;
TABLESPACE FILE_NAME
---------- -------------------------------------------------------------------------------
SYSTEM F:\ORACLE\PRODUCT\ORADATA\ABC\DATAFILE\O1_MF_SYSTEM_40PN388S_.DBF
UNDOTBS1 F:\ORACLE\PRODUCT\ORADATA\ABC\DATAFILE\O1_MF_UNDOTBS1_40PN3OLK_.DBF
SYSAUX F:\ORACLE\PRODUCT\ORADATA\ABC\DATAFILE\O1_MF_SYSAUX_40PN3Q00_.DBF
6.3临时文件
SQL>select tablespace_name,file_name from dba_temp_files;
TABLESPACE FILE_NAME
---------- ---------------------------------------------------------------------
TEMP F:\ORACLE\PRODUCT\ORADATA\ABC\DATAFILE\O1_MF_TEMP_40PN3YJ3_.TMP
到此数据库abc创建完毕,可以正常使用了
三、附录:
create database的全部语法:
CREATE DATABASE database
USER SYS IDENTIFIED BY password
USER SYSTEM IDENTIFIED BY password
CONTROLFILE REUSE
MAXDATAFILES integer
MAXINSTANCES integer
MAXLOGFILES integer
MAXLOGMEMBERS integer
MAXLOGHISTORY integer
CHARACTER SET charset
NATIONAL CHARACTER SET charset
SET DEFAULT BIGFILE(SMALLFILE) TABLESPACE
LOGFILE GROUP integer file_specification
ARCHIVELOG(NOARCHIVELOG)
FORCE LOGGING
DATAFILE file_specification
SYSAUX DATAFILE file_specification
DEFAULT TABLESPACE tablespace DATAFILE datafile_tempfile_spec extent_management_clause
BIGFILE(SMALLFILE) DEFAULT TEMPORARY TABLESPACE tablespace TEMPFILE file_specification extent_management_clause
BIGFILE(SMALLFILE) UNDO TABLESPACE tablespace DATAFILE file_specification
SET TIME_ZONE = ''+/–hh : mi''(time_zone_region)